File tree Expand file tree Collapse file tree 3 files changed +17
-9
lines changed
Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 11import type { NextFunction , Request , Response } from 'express'
22
33import express from 'express'
4- import cors from 'cors'
54import logger from 'morgan'
65import swaggerUi from 'swagger-ui-express'
76
@@ -34,7 +33,7 @@ app.listen(Number(process.env.PORT) || 5432, () => {
3433const appRouter = express . Router ( )
3534
3635app . use ( logger ( 'dev' ) )
37- app . use ( cors ( { origin : process . env . ALLOWED_ORIGINS } ) )
36+ // app.use(cors({ origin: process.env.ALLOWED_ORIGINS }))
3837app . use ( express . json ( ) )
3938app . disable ( 'x-powered-by' )
4039
Original file line number Diff line number Diff line change @@ -32,9 +32,7 @@ boardRouter.get(
3232 const board = await prisma . board . findFirst ( {
3333 where : { id : params . boardId , userId : user . id } ,
3434 include : {
35- columns : {
36- include : { cards : { orderBy : { order : 'asc' } } }
37- }
35+ columns : { include : { cards : { orderBy : { order : 'asc' } } } }
3836 }
3937 } )
4038
Original file line number Diff line number Diff line change @@ -79,16 +79,27 @@ cardRouter.patch(
7979 '/:columnId/order' ,
8080 validateRequestParams ( ColumnParamsSchema ) ,
8181 validateRequestBody ( UpdateCardOrderSchema ) ,
82- async ( { params, body } , res ) => {
82+ async ( { params, body } , res , next ) => {
83+ const column = await prisma . column . findFirst ( {
84+ where : { id : params . columnId }
85+ } )
86+
87+ if ( ! column ) {
88+ return next ( createHttpError ( 404 , 'Column not found' ) )
89+ }
90+
8391 const transaction = body . ids . map ( ( id , order ) =>
8492 prisma . card . update ( {
8593 where : { id } ,
8694 data : { order, columnId : params . columnId }
8795 } )
8896 )
8997
90- const updatedCards = await prisma . $transaction ( transaction )
91-
92- res . json ( updatedCards )
98+ try {
99+ const updatedCards = await prisma . $transaction ( transaction )
100+ res . json ( updatedCards )
101+ } catch {
102+ return next ( createHttpError ( 400 , 'Invalid order' ) )
103+ }
93104 }
94105)
You can’t perform that action at this time.
0 commit comments