-
Notifications
You must be signed in to change notification settings - Fork 2
/
toggle-rai-response-withdraw.ts
52 lines (48 loc) · 1.38 KB
/
toggle-rai-response-withdraw.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 { Action, events } from "shared-types";
import { response } from "../../../libs/handler-lib";
import { TOPIC_NAME } from "../consts";
import { toggleRaiResponseWithdrawAction } from "../services/package-action-write-service";
export async function toggleRaiResponseWithdraw({
toggle = false,
...body
}: Record<string, unknown> & { toggle?: boolean }) {
const now = new Date().getTime();
const result = events["toggle-withdraw-rai"].baseSchema.safeParse({
...body,
raiWithdrawEnabled: toggle,
});
if (result.success === false) {
console.error(
"Toggle Rai Response Withdraw Enable event validation error. The following record failed to parse: ",
JSON.stringify(body),
"Because of the following Reason(s):",
result.error.message,
);
return response({
statusCode: 400,
body: {
message: "Toggle Rai Response Withdraw Enable event validation error",
},
});
}
try {
await toggleRaiResponseWithdrawAction({
...result.data,
action: toggle ? Action.ENABLE_RAI_WITHDRAW : Action.DISABLE_RAI_WITHDRAW,
id: result.data.id,
topicName: TOPIC_NAME,
timestamp: now,
});
return response({
statusCode: 200,
body: {
message: "record successfully submitted",
},
});
} catch (err) {
console.log(err);
return response({
statusCode: 500,
});
}
}