Skip to content

Commit

Permalink
Merge pull request #137 from ms-club-sliit/development
Browse files Browse the repository at this point in the history
Development into Main
  • Loading branch information
senuravihanjayadeva authored Dec 25, 2021
2 parents 606b4cd + c70eeb0 commit 637cefc
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 41 deletions.
1 change: 1 addition & 0 deletions src/api/controllers/Event.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
50 changes: 30 additions & 20 deletions src/api/controllers/ExecutiveBoard.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/api/controllers/TopSpeaker.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/api/controllers/Webinar.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 8 additions & 6 deletions src/api/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,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);
Expand All @@ -71,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);

Expand Down
2 changes: 1 addition & 1 deletion src/api/services/BoardMember.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 6 additions & 8 deletions src/api/services/Contact.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ export const insertContact = async (contactData: DocumentDefinition<IContact>) =
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);
Expand Down
2 changes: 1 addition & 1 deletion src/api/services/ExecutiveBoard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion src/api/services/TopSpeaker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion src/api/services/Webinar.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ export const updateWebinar = async (
webinarData: DocumentDefinition<IWebinar>,
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;
}
Expand Down

0 comments on commit 637cefc

Please sign in to comment.