fix: normalize overseer webhook statuses
This commit is contained in:
@@ -133,11 +133,22 @@ router.post(
|
|||||||
router.post(
|
router.post(
|
||||||
"/webhook",
|
"/webhook",
|
||||||
asyncHandler(async (req, res) => {
|
asyncHandler(async (req, res) => {
|
||||||
const { request_id, status } = req.body;
|
const rawId =
|
||||||
if (!request_id || !status)
|
req.body.request_id ??
|
||||||
|
req.body.requestId ??
|
||||||
|
req.body.id ??
|
||||||
|
req.body.overseer_request_id;
|
||||||
|
const statusRaw = String(req.body.status || "").toUpperCase();
|
||||||
|
const status =
|
||||||
|
statusRaw === "APPROVED" || statusRaw === "COMPLETED"
|
||||||
|
? "APPROVED"
|
||||||
|
: statusRaw === "DECLINED" || statusRaw === "FAILED"
|
||||||
|
? "DECLINED"
|
||||||
|
: statusRaw;
|
||||||
|
if (!rawId || !status)
|
||||||
return res.status(400).json({ error: "Missing fields" });
|
return res.status(400).json({ error: "Missing fields" });
|
||||||
const request = await prisma.contentRequest.findFirst({
|
const request = await prisma.contentRequest.findFirst({
|
||||||
where: { overseerRequestId: request_id },
|
where: { overseerRequestId: Number(rawId) },
|
||||||
include: { user: true },
|
include: { user: true },
|
||||||
});
|
});
|
||||||
if (!request) return res.status(404).json({ error: "Request not found" });
|
if (!request) return res.status(404).json({ error: "Request not found" });
|
||||||
|
|||||||
Reference in New Issue
Block a user