(params: {
threadIds: string[];
userId: string;
muted: boolean;
read: boolean;
reminder: boolean;
reminderType?: ReminderTypes;
communityId: string;
})
| 29 | } |
| 30 | |
| 31 | export async function create(params: { |
| 32 | threadIds: string[]; |
| 33 | userId: string; |
| 34 | muted: boolean; |
| 35 | read: boolean; |
| 36 | reminder: boolean; |
| 37 | reminderType?: ReminderTypes; |
| 38 | communityId: string; |
| 39 | }) { |
| 40 | const body = createSchema.safeParse(params); |
| 41 | if (!body.success) { |
| 42 | return { status: 400, data: { error: body.error } }; |
| 43 | } |
| 44 | |
| 45 | const { |
| 46 | threadIds, |
| 47 | userId, |
| 48 | muted, |
| 49 | read, |
| 50 | reminder, |
| 51 | reminderType, |
| 52 | communityId, |
| 53 | } = params; |
| 54 | |
| 55 | const creation = muted || read || reminder; |
| 56 | |
| 57 | if (creation && threadIds.length > 0) { |
| 58 | await prisma.$transaction([ |
| 59 | prisma.userThreadStatus.deleteMany({ |
| 60 | where: { |
| 61 | userId, |
| 62 | threadId: { in: threadIds }, |
| 63 | }, |
| 64 | }), |
| 65 | prisma.userThreadStatus.createMany({ |
| 66 | data: threadIds.map((threadId) => { |
| 67 | if (reminderType) { |
| 68 | const remindAt = getRemindAt(reminderType); |
| 69 | createRemindMeJob(`${threadId}_${userId}`, remindAt, { |
| 70 | threadId, |
| 71 | userId, |
| 72 | }); |
| 73 | return { |
| 74 | userId, |
| 75 | threadId, |
| 76 | muted, |
| 77 | read, |
| 78 | reminder, |
| 79 | remindAt, |
| 80 | }; |
| 81 | } |
| 82 | return { |
| 83 | userId, |
| 84 | threadId, |
| 85 | muted, |
| 86 | read, |
| 87 | reminder, |
| 88 | }; |
no test coverage detected