mirror of
https://github.com/Floriansylvain/SnippetsManager.git
synced 2026-08-19 11:43:15 +02:00
Added :id param on snippet delete route
This commit is contained in:
@@ -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 () => {
|
it('returns status code 200 and success message', async () => {
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.delete('/v1/snippet')
|
.delete(`/v1/snippet/${snippet_id}`)
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.set('Cookie', jwtCookie as string)
|
.set('Cookie', jwtCookie as string)
|
||||||
.send(JSON.stringify({
|
|
||||||
id: snippet_id
|
|
||||||
}))
|
|
||||||
|
|
||||||
expect(res.status).toEqual(200)
|
expect(res.status).toEqual(200)
|
||||||
expect(res.body).toHaveProperty('message')
|
expect(res.body).toHaveProperty('message')
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ const snippetPostParser = z.object({
|
|||||||
language: z.string().max(32)
|
language: z.string().max(32)
|
||||||
}).required()
|
}).required()
|
||||||
|
|
||||||
const snippetDeleteParser = z.object({
|
|
||||||
id: z.number(),
|
|
||||||
}).required()
|
|
||||||
|
|
||||||
const snippetUpdateParser = z.object({
|
const snippetUpdateParser = z.object({
|
||||||
code: z.string().optional(),
|
code: z.string().optional(),
|
||||||
title: z.string().max(50).optional(),
|
title: z.string().max(50).optional(),
|
||||||
@@ -91,10 +87,9 @@ const snippetDelete: RequestHandler = async (req, res) => {
|
|||||||
let deleted: Prisma.BatchPayload
|
let deleted: Prisma.BatchPayload
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const snippetToDel = snippetDeleteParser.parse(req.body)
|
|
||||||
deleted = await prisma.category.deleteMany({
|
deleted = await prisma.category.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
id: snippetToDel.id,
|
id: paramsIdParser.parse(req.params).id,
|
||||||
user_id: req.body.userId
|
user_id: req.body.userId
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -109,6 +104,6 @@ const snippetDelete: RequestHandler = async (req, res) => {
|
|||||||
snippetRouter.get('/', userIdMiddleware, snippetGet)
|
snippetRouter.get('/', userIdMiddleware, snippetGet)
|
||||||
snippetRouter.post('/', userIdMiddleware, snippetPost)
|
snippetRouter.post('/', userIdMiddleware, snippetPost)
|
||||||
snippetRouter.put('/:id', userIdMiddleware, snippetUpdate)
|
snippetRouter.put('/:id', userIdMiddleware, snippetUpdate)
|
||||||
snippetRouter.delete('/', userIdMiddleware, snippetDelete)
|
snippetRouter.delete('/:id', userIdMiddleware, snippetDelete)
|
||||||
|
|
||||||
export default snippetRouter
|
export default snippetRouter
|
||||||
|
|||||||
Reference in New Issue
Block a user