-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatePoints.ts
52 lines (45 loc) · 1.26 KB
/
createPoints.ts
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
48
49
50
51
52
import { type NextApiRequest, type NextApiResponse } from "next";
import { type SinglePointsRequest, type Error } from "@/types";
import { pointsQueue } from "@/workers/points.worker";
interface Request extends NextApiRequest {
body: SinglePointsRequest;
}
interface Response extends NextApiResponse {
status(code: number): Response;
send(data: { message: string } | Error): void;
}
export default async function handler(req: Request, res: Response) {
try {
const { recipient, amount, context, multiplier, subContext, trigger } =
req.body;
// first create allocation
await pointsQueue.add("pointsQueue", {
recipient,
amount,
context,
multiplier,
subContext,
trigger,
docType: "allocation",
});
// then create context aggregation
await pointsQueue.add("pointsQueue", {
recipient,
context,
amount,
docType: "context",
});
// then create total aggregation
await pointsQueue.add("pointsQueue", {
recipient,
amount,
docType: "total",
});
return res
.status(200)
.send({ message: "Points successfully added to queues" });
} catch (error) {
console.error(error);
res.status(500).send({ error: "Internal Server Error" });
}
}