From 6d429c6e9d10c410f3b8c9322db47f533f9e8fbc Mon Sep 17 00:00:00 2001 From: senuravihanjayadeva Date: Fri, 24 Dec 2021 19:13:37 +0530 Subject: [PATCH 1/4] Change the Contact route --- src/api/routes/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/api/routes/index.ts b/src/api/routes/index.ts index bc57c71..87dccef 100644 --- a/src/api/routes/index.ts +++ b/src/api/routes/index.ts @@ -17,9 +17,11 @@ export default function (app: Express) { app.put("/user/recover/", middleware.authenticate, controller.recoverUser); app.delete("/user/remove/", middleware.authenticate, controller.removeUserPermenently); - // Contact Us endpoints - app.get("/contact/", middleware.authenticate, controller.getAllContacts); - app.delete("/contact/:contactId", middleware.authenticate, controller.removeContact); + // Contact Us endpoints - Private + app.get("/admin/contact/", middleware.authenticate, controller.getAllContacts); + app.delete("/admin/contact/:contactId", middleware.authenticate, controller.removeContact); + + // Contact Us endpoints - Public app.post("/contact/", controller.createContact); // Event endpoints - Private From aeff9301f6e1a700ab9950d8b95e781b3d31e68c Mon Sep 17 00:00:00 2001 From: senuravihanjayadeva Date: Fri, 24 Dec 2021 19:21:45 +0530 Subject: [PATCH 2/4] Resolved the bug in Contact Service --- src/api/services/Contact.service.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/api/services/Contact.service.ts b/src/api/services/Contact.service.ts index 44d8edd..a25cb61 100644 --- a/src/api/services/Contact.service.ts +++ b/src/api/services/Contact.service.ts @@ -23,14 +23,12 @@ export const insertContact = async (contactData: DocumentDefinition) = export const archiveContact = async (contactId: string) => { return await ContactModel.findById(contactId) .then(async (contactData) => { - if (contactData) { - if (!contactData.deletedAt) { - throw new Error('Contact Information Not Found'); - } else { - contactData.deletedAt = new Date(); - return await contactData.save(); - } - } + if (contactData && contactData.deletedAt === null) { + contactData.deletedAt = new Date(); + return await contactData.save(); + } else { + return "Contact not found"; + } }) .catch((error) => { throw new Error(error.message); From fae481f8d4bcbba9b05186d4d395ab44e2be314d Mon Sep 17 00:00:00 2001 From: senuravihanjayadeva Date: Fri, 24 Dec 2021 21:35:38 +0530 Subject: [PATCH 3/4] Fixed the bug in webinar --- src/api/controllers/Webinar.controller.ts | 4 ++-- src/api/services/Webinar.service.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/api/controllers/Webinar.controller.ts b/src/api/controllers/Webinar.controller.ts index 7114613..8a5dfa9 100644 --- a/src/api/controllers/Webinar.controller.ts +++ b/src/api/controllers/Webinar.controller.ts @@ -144,9 +144,9 @@ export const updateWebinar = async ( const webinarId = request.params.webinarId; const updatedBy = request.user && request.user._id ? request.user._id : null; - + if (webinarId) { - await WebinarService.updateWebinar(request.params.webinarId, request.body,updatedBy) + await WebinarService.updateWebinar(webinarId, request.body,updatedBy) .then((data) => { request.handleResponse.successRespond(response)(data); next(); diff --git a/src/api/services/Webinar.service.ts b/src/api/services/Webinar.service.ts index 606759c..3de0959 100644 --- a/src/api/services/Webinar.service.ts +++ b/src/api/services/Webinar.service.ts @@ -91,10 +91,11 @@ export const updateWebinar = async ( webinarData: DocumentDefinition, updatedBy: Schema.Types.ObjectId ) => { + return await WebinarModel.findById(webinarId) .then(async (webinarDetails) => { if (webinarDetails) { - if (webinarDetails.deletedAt) { + if (!webinarDetails.deletedAt) { if (webinarData.title) { webinarDetails.title = webinarData.title; } From 6859e77c359a201e65c8dcf1e72383c590ff31d5 Mon Sep 17 00:00:00 2001 From: senuravihanjayadeva Date: Sat, 25 Dec 2021 08:39:09 +0530 Subject: [PATCH 4/4] Fixed the bugs in Executive Board --- src/api/controllers/Event.controller.ts | 1 + .../controllers/ExecutiveBoard.controller.ts | 50 +++++++++++-------- src/api/controllers/TopSpeaker.controller.ts | 2 +- src/api/routes/index.ts | 6 +-- src/api/services/BoardMember.service.ts | 2 +- src/api/services/ExecutiveBoard.service.ts | 2 +- src/api/services/TopSpeaker.service.ts | 2 +- 7 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/api/controllers/Event.controller.ts b/src/api/controllers/Event.controller.ts index 7e98aea..4364f29 100644 --- a/src/api/controllers/Event.controller.ts +++ b/src/api/controllers/Event.controller.ts @@ -119,6 +119,7 @@ export const updateEvent = async (request: Request, response: Response, next: Ne } const eventId = request.params.eventId; const updatedBy = request.user && request.user._id ? request.user._id : null; + if (eventId) { await EventService.updateEvent(eventId, request.body, updatedBy) .then((data) => { diff --git a/src/api/controllers/ExecutiveBoard.controller.ts b/src/api/controllers/ExecutiveBoard.controller.ts index 9cb9db4..fbebcd6 100644 --- a/src/api/controllers/ExecutiveBoard.controller.ts +++ b/src/api/controllers/ExecutiveBoard.controller.ts @@ -15,7 +15,7 @@ export const insertExecutiveBoard = async ( next: NextFunction ) => { request.body.createdBy = - request.user && request.user._id ? request.user._id : null; + request.user && request.user._id ? request.user._id : null; await ExecutiveBoardService.insertExecutiveBoard(request.body) .then((data) => { request.handleResponse.successRespond(response)(data); @@ -88,27 +88,37 @@ export const addBoardMember = async ( response: Response, next: NextFunction ) => { - const bucketDirectoryName = "boardmember-flyers"; + if (request.file) { + const bucketDirectoryName = "boardmember-flyers"; - const boardMemberFlyerPath = await ImageService.uploadImage( - request.file, - bucketDirectoryName - ); - request.body.imageUrl = boardMemberFlyerPath; + const boardMemberFlyerPath = await ImageService.uploadImage( + request.file, + bucketDirectoryName + ); + request.body.imageUrl = boardMemberFlyerPath; + } + request.body.createdBy = request.user && request.user._id ? request.user._id : null; + const executiveBoardId = request.params.executiveBoardId; const updatedBy = request.user && request.user._id ? request.user._id : null; - await ExecutiveBoardService.addBoardMember( - request.params.executiveBoardId, - request.body, - updatedBy - ) - .then((data) => { - request.handleResponse.successRespond(response)(data); - next(); - }) - .catch((error: any) => { - request.handleResponse.errorRespond(response)(error.message); - next(); - }); + if (executiveBoardId) { + await ExecutiveBoardService.addBoardMember( + request.params.executiveBoardId, + request.body, + updatedBy + ) + .then((data) => { + request.handleResponse.successRespond(response)(data); + next(); + }) + .catch((error: any) => { + request.handleResponse.errorRespond(response)(error.message); + next(); + }); + } else { + request.handleResponse.errorRespond(response)( + "Executive Board Id not found" + ); + } }; /** * @param request diff --git a/src/api/controllers/TopSpeaker.controller.ts b/src/api/controllers/TopSpeaker.controller.ts index 0ec762f..67e6687 100644 --- a/src/api/controllers/TopSpeaker.controller.ts +++ b/src/api/controllers/TopSpeaker.controller.ts @@ -49,7 +49,7 @@ export const getTopSpeaker = async ( next: NextFunction ) => { const topSpeakerId = request.params.topSpeakerId; - + if (topSpeakerId) { await TopSpeakerService.getTopSpeaker(request.params.topSpeakerId).then( (data) => { diff --git a/src/api/routes/index.ts b/src/api/routes/index.ts index 87dccef..026a373 100644 --- a/src/api/routes/index.ts +++ b/src/api/routes/index.ts @@ -56,8 +56,8 @@ export default function (app: Express) { app.post("/admin/topspeaker/", middleware.authenticate,upload.single('topSpeakerFlyer'), controller.insertTopSpeaker); app.put("/admin/topspeaker/:topSpeakerId", middleware.authenticate,upload.single('topSpeakerFlyer'), controller.updateTopSpeaker); app.put("/admin/topspeaker/delete/:topSpeakerId", middleware.authenticate, controller.deleteTopSpeaker); - app.get("/admin/topspeaker/", middleware.authenticate,controller.webinarsForAdmin); - app.get("/admin/topspeaker/delete/", middleware.authenticate,controller.deletedWebinarsForAdmin); + app.get("/admin/topspeaker/", middleware.authenticate,controller.getAllTopSpeakersForAdmin); + app.get("/admin/topspeaker/delete/", middleware.authenticate,controller.getDeletedTopSpeakersForAdmin); // Top Speaker endpoints - Public app.get("/topspeaker/:topSpeakerId/", controller.getTopSpeaker); @@ -73,7 +73,7 @@ export default function (app: Express) { // ExecutiveBoard endpoints - Private app.post("/admin/executive/", middleware.authenticate, controller.insertExecutiveBoard); - app.put("/admin/boardmember/:executiveBoardId", middleware.authenticate,upload.single('boardMemberFlyer'), controller.addBoardMember); + app.put("/admin/executive/boardmember/:executiveBoardId", middleware.authenticate,upload.single('boardMemberFlyer'), controller.addBoardMember); app.put("/admin/executive/:executiveBoardId", middleware.authenticate, controller.updateExecutiveBoardDetails); app.put("/admin/executive/delete/:executiveBoardId/", middleware.authenticate, controller.deleteExecutiveBoardDetails); diff --git a/src/api/services/BoardMember.service.ts b/src/api/services/BoardMember.service.ts index 44490d4..f3422aa 100644 --- a/src/api/services/BoardMember.service.ts +++ b/src/api/services/BoardMember.service.ts @@ -61,7 +61,7 @@ export const updateBoardMemberDetails = async ( return await BoardMemberModel.findById(boardMemberId) .then(async (boardMemberDetails) => { if (boardMemberDetails) { - if (boardMemberDetails.deletedAt) { + if (!boardMemberDetails.deletedAt) { if (updateData.name) { boardMemberDetails.name = updateData.name; } diff --git a/src/api/services/ExecutiveBoard.service.ts b/src/api/services/ExecutiveBoard.service.ts index 8618af8..cf3e067 100644 --- a/src/api/services/ExecutiveBoard.service.ts +++ b/src/api/services/ExecutiveBoard.service.ts @@ -43,7 +43,7 @@ export const getExecutiveBoardbyID = async (executiveBoardId: string) => { get all the executive boards from the database (the details of the existing board members should be populated) */ export const getExecutiveBoard = async () => { - return await ExecutiveBoardModel.find() + return await ExecutiveBoardModel.find({ deletedAt: null }) .populate({ path: "board", match: { deletedAt: null }, diff --git a/src/api/services/TopSpeaker.service.ts b/src/api/services/TopSpeaker.service.ts index d47c71e..e81253b 100644 --- a/src/api/services/TopSpeaker.service.ts +++ b/src/api/services/TopSpeaker.service.ts @@ -29,7 +29,7 @@ export const insertTopSpeaker = async ( export const getTopSpeaker = async (topSpeakerId: string) => { return await TopSpeakerModel.findById(topSpeakerId) .then((topSpeaker) => { - if (topSpeaker && topSpeaker.deletedAt) { + if (topSpeaker && topSpeaker.deletedAt == null) { return topSpeaker; } else { throw new Error("Speaker is not found");