File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -69,8 +69,12 @@ const removeDiscFromBag = async (id: string, disc_id: string) => {
6969 return bag ;
7070} ;
7171
72- const updateBagName = async ( id : string , name : string ) => {
72+ const updateBagName = async ( id : string , name : string , user_id ?: string ) => {
7373 const bag = await assertBagExists ( id ) ;
74+ if ( user_id ) {
75+ const existingBag = await BagModel . findOne ( { user_id, name } ) ;
76+ if ( existingBag ) throw new CustomError ( `You already have a bag named '${ name } '` , 400 ) ;
77+ }
7478 bag . name = name ;
7579 await BagModel . updateOne ( { id } , bag ) ;
7680 return bag ;
Original file line number Diff line number Diff line change @@ -225,7 +225,11 @@ export const initBagRoutes = (app: OpenAPIHono) => {
225225 body : {
226226 content : {
227227 "application/json" : {
228- schema : z . object ( { id : z . string ( ) , name : z . string ( ) } )
228+ schema : z . object ( {
229+ id : z . string ( ) ,
230+ name : z . string ( ) ,
231+ user_id : z . optional ( z . string ( ) )
232+ } )
229233 }
230234 } ,
231235 required : true
@@ -257,8 +261,8 @@ export const initBagRoutes = (app: OpenAPIHono) => {
257261 async c => {
258262 const { authorization } = c . req . valid ( "header" ) ;
259263 assertIsRequestAuthorized ( authorization ) ;
260- const { id, name } = c . req . valid ( "json" ) ;
261- const bag = await Bag . updateBagName ( id , name ) ;
264+ const { id, name, user_id } = c . req . valid ( "json" ) ;
265+ const bag = await Bag . updateBagName ( id , name , user_id ) ;
262266 return c . json ( bag , 200 ) ;
263267 }
264268 ) ;
You can’t perform that action at this time.
0 commit comments