Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
car-crushers-portal/functions/api/reports/recall.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
31 lines (26 sloc)
786 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function onRequestPost(context: RequestContext) { | |
const { id } = context.data.body; | |
if (!id) | |
return new Response('{"error":"No ID provided"}', { | |
headers: { | |
"content-type": "application/json", | |
}, | |
status: 400, | |
}); | |
const reportUserId = await context.env.DATA.get(`reportprocessing_${id}`); | |
if ( | |
!reportUserId || | |
(context.data.current_user?.id !== reportUserId && | |
context.request.headers.get("CF-Connecting-IP") !== reportUserId) | |
) | |
return new Response('{"error":"No processing report with that ID found"}', { | |
headers: { | |
"content-type": "application/json", | |
}, | |
status: 404, | |
}); | |
await context.env.DATA.delete(`report_${id}`); | |
return new Response(null, { | |
status: 204, | |
}); | |
} |