From f4e9f384dce2a3e456f3e156e60964518fbc5671 Mon Sep 17 00:00:00 2001 From: SalleeMatthew <132789789+SalleeMatthew@users.noreply.github.com> Date: Sun, 14 Jul 2024 04:24:52 -0500 Subject: [PATCH] Update member.controller.ts Added more error-checking to the function for updating the storage unit name. --- api/src/controllers/member.controller.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/api/src/controllers/member.controller.ts b/api/src/controllers/member.controller.ts index b4a12df0..322f5d08 100644 --- a/api/src/controllers/member.controller.ts +++ b/api/src/controllers/member.controller.ts @@ -392,6 +392,9 @@ class MemberController { if(!session) return; try { const storage = await this.memberService.getStorageById(parseInt(request.body.id)); + if(!storage){ + throw new Error('Storage area not found!'); + } if(storage && storage.member_id !== session.id){ throw new Error('You do not own this storage area'); } @@ -401,12 +404,14 @@ class MemberController { if(storageName.match(bannedwords)){ throw new Error('You can not use this language on CTR!'); } - this.placeService.updatePlaces( - parseInt(request.body.id.toString()), - request.body.column.toString(), - storageName, - ); - response.status(200).json({status: 'success'}); + if(storage && storage.member_id === session.id){ + this.placeService.updatePlaces( + parseInt(request.body.id.toString()), + 'name', + storageName, + ); + response.status(200).json({status: 'success'}); + } } catch (error) { console.log(error); response.status(400).json({ error });