-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathreactivate-program.ts
More file actions
47 lines (41 loc) · 1.12 KB
/
reactivate-program.ts
File metadata and controls
47 lines (41 loc) · 1.12 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
43
44
45
46
47
import { qstash } from "@/lib/cron";
import { DEFAULT_PARTNER_GROUP } from "@/lib/zod/schemas/groups";
import { prisma } from "@dub/prisma";
import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";
export async function reactivateProgram(programId: string) {
if (!programId) {
throw new Error("[reactivateProgram] programId is required");
}
await prisma.$transaction([
prisma.program.update({
where: {
id: programId,
},
data: {
deactivatedAt: null,
},
}),
// republish the default group
prisma.partnerGroup.update({
where: {
programId_slug: {
programId,
slug: DEFAULT_PARTNER_GROUP.slug,
},
},
data: {
applicationFormPublishedAt: new Date(),
landerPublishedAt: new Date(),
},
}),
]);
const response = await qstash.publishJSON({
url: `${APP_DOMAIN_WITH_NGROK}/api/cron/programs/reactivate`,
body: {
programId,
},
deduplicationId: `reactivate-program-${programId}`,
});
console.log("[reactivateProgram] Reactivation job enqueued.", { response });
return response;
}