-
Notifications
You must be signed in to change notification settings - Fork 3
feat(domain): auto delete notifications #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
import database from '^/integrations/database'; | ||
|
||
import type { RecordQuery } from '^/integrations/database'; | ||
import { RECORD_TYPE } from '../definitions'; | ||
import type { DataModel } from '../types'; | ||
|
||
export default async function getByPostId(postId: string): Promise<DataModel[]> | ||
{ | ||
const query: RecordQuery = | ||
{ | ||
deleted: { EQUALS: false }, | ||
postId: { EQUALS: postId } | ||
}; | ||
|
||
return database.searchRecords(RECORD_TYPE, query) as Promise<DataModel[]>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
export { default } from './getByPostId'; |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,10 @@ | ||||||||||
|
||||||||||
import getNotifications from '../getByPostId'; | ||||||||||
import deleteData from '../remove'; | ||||||||||
|
||||||||||
export default async function removedPost(postId: string): Promise<Promise<void>[]> | ||||||||||
{ | ||||||||||
const notifications = await getNotifications(postId); | ||||||||||
|
||||||||||
return notifications.map(item => deleteData(item.id)); | ||||||||||
|
return notifications.map(item => deleteData(item.id)); | |
const promises = notifications.map(item => deleteData(item.id)); | |
await Promise.allSettled(promises); |
Return type: Promise<void>
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file contains the actual feature, and therefore should be named |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
import database from '^/integrations/database'; | ||
|
||
import { RECORD_TYPE } from '../definitions'; | ||
|
||
export default async function deleteData(id: string): Promise<void> | ||
{ | ||
return database.updateRecord(RECORD_TYPE, id, { deleted: true }); | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,2 @@ | ||||||
|
||||||
export { default } from './deleteData'; | ||||||
|
export { default } from './deleteData'; | |
export { default } from './remove'; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file tests the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
import { beforeEach, describe, expect, it } from 'vitest'; | ||
|
||
import getByPostId from '^/domain/notification/getByPostId'; | ||
import removedPost from '^/domain/notification/notify/removedPost'; | ||
import { DATABASES, VALUES } from './fixtures'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be an empty line before this import. Those above are coming from the |
||
|
||
beforeEach(async () => | ||
{ | ||
await Promise.all([ | ||
DATABASES.withCreatorsPostsAndNotifications() | ||
]); | ||
}); | ||
|
||
describe('domain/notification/remove', () => | ||
{ | ||
it('should remove all notifications of a removed post', async () => | ||
{ | ||
await removedPost(VALUES.IDS.POST_RATED); | ||
|
||
const result = await getByPostId(VALUES.IDS.POST_RATED); | ||
|
||
expect(result).toHaveLength(0); | ||
}); | ||
|
||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import should be grouped with the other
^/integration/...
import.