-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
339a0a6
commit 5b50989
Showing
4 changed files
with
77 additions
and
22 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import RequestModel from '@/models/Request'; | ||
import { GET } from "@/app/api/auth/me/route" | ||
import { createHash } from "crypto"; | ||
|
||
export async function DELETE(req, res) { | ||
const body = await req.json() | ||
let { jobRequestId } = body | ||
const response = await GET(req) | ||
const user = await response.json() | ||
|
||
const uniqCode = createHash("sha256").update(user._id + process.env.PAPER).digest("hex"); | ||
const userJobRequest = await RequestModel.findById(jobRequestId) | ||
|
||
if (!userJobRequest) { | ||
return Response.json({ status: 404 }, { message: 'Document not found' }) | ||
} | ||
|
||
if (!userJobRequest.uniqCode === uniqCode) { | ||
return Response.json( | ||
{ message: `You are not authorized to delete this jobRequest ` }, | ||
{ status: 403 } | ||
) | ||
} | ||
|
||
try { | ||
await RequestModel.findOneAndDelete({ _id: jobRequestId }); | ||
return Response.json({ message: 'Document deleted successfully' }, { status: 200 }) | ||
} catch (error) { | ||
return Response.json({ message: 'Server error', error }, { status: 500 }) | ||
} | ||
} |
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
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