mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add created_at and updated_at to newsletter emails and sort by created_at desc
This commit is contained in:
parent
1893e36375
commit
6597cc37b6
5 changed files with 48 additions and 11 deletions
|
|
@ -1,10 +1,12 @@
|
|||
import {
|
||||
Entity,
|
||||
BaseEntity,
|
||||
Column,
|
||||
ManyToOne,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm'
|
||||
import { User } from './user'
|
||||
|
||||
|
|
@ -22,4 +24,10 @@ export class NewsletterEmail extends BaseEntity {
|
|||
|
||||
@Column('varchar', { nullable: true })
|
||||
confirmationCode?: string
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Date
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt!: Date
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,10 @@ export const createNewsletterEmail = async (
|
|||
export const getNewsletterEmails = async (
|
||||
userId: string
|
||||
): Promise<NewsletterEmail[]> => {
|
||||
return getRepository(NewsletterEmail).find({ where: { user: userId } })
|
||||
return getRepository(NewsletterEmail).find({
|
||||
where: { user: userId },
|
||||
order: { createdAt: 'DESC' },
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteNewsletterEmail = async (id: string): Promise<boolean> => {
|
||||
|
|
|
|||
|
|
@ -61,16 +61,18 @@ describe('Newsletters API', () => {
|
|||
}
|
||||
`
|
||||
|
||||
it('responds with newsletter emails', async () => {
|
||||
it('responds with newsletter emails sort by created_at desc', async () => {
|
||||
const response = await graphqlRequest(query, authToken).expect(200)
|
||||
expect(response.body.data.newsletterEmails.newsletterEmails).to.eqls(
|
||||
newsletterEmails.map((value) => {
|
||||
return {
|
||||
id: value.id,
|
||||
address: value.address,
|
||||
confirmationCode: value.confirmationCode,
|
||||
}
|
||||
})
|
||||
newsletterEmails
|
||||
.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())
|
||||
.map((value) => {
|
||||
return {
|
||||
id: value.id,
|
||||
address: value.address,
|
||||
confirmationCode: value.confirmationCode,
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
|
|
|
|||
13
packages/db/migrations/0075.do.add_created_at_to_newsletter_emails.sql
Executable file
13
packages/db/migrations/0075.do.add_created_at_to_newsletter_emails.sql
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
-- Type: DO
|
||||
-- Name: add_created_at_to_newsletter_emails
|
||||
-- Description: Add created_at and updated_at fields to newsletter_emails table
|
||||
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE omnivore.newsletter_emails
|
||||
ADD COLUMN created_at timestamptz NOT NULL default current_timestamp,
|
||||
ADD COLUMN updated_at timestamptz NOT NULL default current_timestamp;
|
||||
|
||||
CREATE TRIGGER newsletter_emails_modtime BEFORE UPDATE ON omnivore.newsletter_emails FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column();
|
||||
|
||||
COMMIT;
|
||||
11
packages/db/migrations/0075.undo.add_created_at_to_newsletter_emails.sql
Executable file
11
packages/db/migrations/0075.undo.add_created_at_to_newsletter_emails.sql
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
-- Type: UNDO
|
||||
-- Name: add_created_at_to_newsletter_emails
|
||||
-- Description: Add created_at and updated_at fields to newsletter_emails table
|
||||
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE omnivore.newsletter_emails
|
||||
DROP COLUMN created_at,
|
||||
DROP COLUMN updated_at;
|
||||
|
||||
COMMIT;
|
||||
Loading…
Reference in a new issue