-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathpostBoostAction.ts
More file actions
42 lines (37 loc) · 1.31 KB
/
postBoostAction.ts
File metadata and controls
42 lines (37 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Post, User } from '../../entity';
import { NotificationType } from '../../notifications/common';
import { generateTypedNotificationWorker } from './worker';
import { type NotificationBoostContext } from '../../notifications';
import { queryReadReplica } from '../../common/queryReadReplica';
import { updateFlagsStatement } from '../../common';
const worker = generateTypedNotificationWorker<'skadi.v1.campaign-updated'>({
subscription: 'api.campaign-updated-notification',
handler: async (params, con) => {
const { userId, postId, campaignId, action } = params;
const user = await queryReadReplica(con, ({ queryRunner }) => {
return queryRunner.manager
.getRepository(User)
.findOneByOrFail({ id: userId });
});
const ctx: NotificationBoostContext = {
user,
campaignId,
userIds: [userId],
};
switch (action) {
case 'first_milestone':
return [{ type: NotificationType.PostBoostFirstMilestone, ctx }];
case 'completed':
await con
.getRepository(Post)
.update(
{ id: postId },
{ flags: updateFlagsStatement<Post>({ campaignId: null }) },
);
return [{ type: NotificationType.PostBoostCompleted, ctx }];
default:
return;
}
},
});
export default worker;