Added :id param on snippet delete route

This commit is contained in:
Florian Sylvain
2023-02-02 10:15:56 +01:00
parent 10c7c07b97
commit 02dbc0e6f6
2 changed files with 4 additions and 12 deletions
+2 -5
View File
@@ -255,15 +255,12 @@ describe('PUT /v1/snippet/:id', () => {
})
})
describe('DELETE /v1/snippet', () => {
describe('DELETE /v1/snippet/:id', () => {
it('returns status code 200 and success message', async () => {
const res = await request(app)
.delete('/v1/snippet')
.delete(`/v1/snippet/${snippet_id}`)
.set('Content-Type', 'application/json')
.set('Cookie', jwtCookie as string)
.send(JSON.stringify({
id: snippet_id
}))
expect(res.status).toEqual(200)
expect(res.body).toHaveProperty('message')
+2 -7
View File
@@ -12,10 +12,6 @@ const snippetPostParser = z.object({
language: z.string().max(32)
}).required()
const snippetDeleteParser = z.object({
id: z.number(),
}).required()
const snippetUpdateParser = z.object({
code: z.string().optional(),
title: z.string().max(50).optional(),
@@ -91,10 +87,9 @@ const snippetDelete: RequestHandler = async (req, res) => {
let deleted: Prisma.BatchPayload
try {
const snippetToDel = snippetDeleteParser.parse(req.body)
deleted = await prisma.category.deleteMany({
where: {
id: snippetToDel.id,
id: paramsIdParser.parse(req.params).id,
user_id: req.body.userId
}
})
@@ -109,6 +104,6 @@ const snippetDelete: RequestHandler = async (req, res) => {
snippetRouter.get('/', userIdMiddleware, snippetGet)
snippetRouter.post('/', userIdMiddleware, snippetPost)
snippetRouter.put('/:id', userIdMiddleware, snippetUpdate)
snippetRouter.delete('/', userIdMiddleware, snippetDelete)
snippetRouter.delete('/:id', userIdMiddleware, snippetDelete)
export default snippetRouter