Skip to content

Commit

Permalink
Merge pull request #143 from ms-club-sliit/development
Browse files Browse the repository at this point in the history
Development into Main
  • Loading branch information
senuravihanjayadeva authored Jan 3, 2022
2 parents 637cefc + e023e75 commit 18d4cc4
Show file tree
Hide file tree
Showing 9 changed files with 13,573 additions and 93 deletions.
13,387 changes: 13,342 additions & 45 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"author": "MS CLUB SLIIT",
"license": "ISC",
"dependencies": {
"@sendgrid/mail": "^7.6.0",
"@types/bcrypt": "^5.0.0",
"@types/bcryptjs": "^2.4.2",
"@types/cors": "^2.8.12",
Expand Down Expand Up @@ -46,7 +47,8 @@
"moment": "^2.29.1",
"multer": "^1.4.3",
"node-fetch": "^3.1.0",
"nodemailer": "^6.7.1",
"nodemailer": "^6.7.2",
"nodemailer-sendgrid": "^1.0.3",
"pino": "^7.4.0",
"pino-pretty": "^7.2.0",
"sharp": "^0.29.3",
Expand Down
147 changes: 131 additions & 16 deletions src/api/controllers/Application.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import ApplicationService from "../services";
import EmailService from "../../util/email.handler";
import logger from "../../util/logger";
import { IApplication } from "../interfaces";
import { request } from "http";

/**
* @param {Request} request - Request from the frontend
* @param {Response} response - Response that need to send to the client
* @param {NextFunction} next - Next function
* @returns {IApplication} - New application document
*/
export const addApplication = async (request: Request, response: Response, next: NextFunction) => {
export const addApplication = async (
request: Request,
response: Response,
next: NextFunction
) => {
await ApplicationService.addApplication(request.body)
.then((data) => {
// Send email
Expand All @@ -23,16 +28,15 @@ export const addApplication = async (request: Request, response: Response, next:
email: data.email,
contactNumber: data.contactNumber,
currentAcademicYear: data.currentAcademicYear,
linkedIn : data.linkedIn,
linkedIn: data.linkedIn,
gitHub: data.gitHub,
skillsAndTalents: data.skillsAndTalents
skillsAndTalents: data.skillsAndTalents,
};

EmailService.sendEmailWithTemplate(emailTemplate, to, subject, emailBodyData)
.then((emailData) => {
.then(() => {
request.handleResponse.successRespond(response)({
applicationData: data,
emailData: emailData,
});
})
.catch((error) => {
Expand All @@ -54,10 +58,14 @@ export const addApplication = async (request: Request, response: Response, next:
* @param {NextFunction} next - Next function
* @returns {IApplication} - Application document that relevent to the passed ID
*/
export const getApplicationById = async (request: Request, response: Response, next: NextFunction) => {
export const getApplicationById = async (
request: Request,
response: Response,
next: NextFunction
) => {
const applicationId = request.params.applicationId;
if (applicationId) {
await ApplicationService.fetchApplicationById(request.params.applicationId)
await ApplicationService.fetchApplicationById(applicationId)
.then((data) => {
request.handleResponse.successRespond(response)(data);
next();
Expand All @@ -77,7 +85,11 @@ export const getApplicationById = async (request: Request, response: Response, n
* @param {NextFunction} next - Next function
* @returns {IApplication} - All application documents
*/
export const getApplications = async (request: Request, response: Response, next: NextFunction) => {
export const getApplications = async (
request: Request,
response: Response,
next: NextFunction
) => {
await ApplicationService.fetchApplications()
.then((data) => {
request.handleResponse.successRespond(response)(data);
Expand All @@ -95,10 +107,14 @@ export const getApplications = async (request: Request, response: Response, next
* @param {NextFunction} next - Next function
* @returns {IApplication} - Updated application document
*/
export const setApplicationArchive = async (request: Request, response: Response, next: NextFunction) => {
export const setApplicationArchive = async (
request: Request,
response: Response,
next: NextFunction
) => {
const applicationId = request.params.applicationId;
if (applicationId) {
await ApplicationService.archiveApplication(request.params.applicationId)
await ApplicationService.archiveApplication(applicationId)
.then((data) => {
request.handleResponse.successRespond(response)(data);
next();
Expand Down Expand Up @@ -128,7 +144,10 @@ export const changeApplicationStatusIntoInterview = async (
) => {
const applicationId = request.params.applicationId;
if (applicationId) {
await ApplicationService.changeApplicationStatusIntoInterview(request.params.applicationId, request.body)
await ApplicationService.changeApplicationStatusIntoInterview(
applicationId,
request.body
)
.then((data) => {
request.handleResponse.successRespond(response)(data);
next();
Expand All @@ -151,10 +170,17 @@ export const changeApplicationStatusIntoInterview = async (
* @param {NextFunction} next - Next function
* @returns {IApplication} updated application document in the system
*/
export const changeApplicationStatusIntoSelected = async (request: Request, response: Response, next: NextFunction) => {
export const changeApplicationStatusIntoSelected = async (
request: Request,
response: Response,
next: NextFunction
) => {
const applicationId = request.params.applicationId;
if (applicationId) {
await ApplicationService.changeApplicationStatusIntoSelected(request.params.applicationId, request.body)
await ApplicationService.changeApplicationStatusIntoSelected(
applicationId,
request.body
)
.then((data) => {
request.handleResponse.successRespond(response)(data);
next();
Expand All @@ -176,10 +202,16 @@ export const changeApplicationStatusIntoSelected = async (request: Request, resp
* @param {NextFunction} next - Next function
* @returns {IApplication} updated application document in the system
*/
export const changeApplicationStatusIntoRejected = async (request: Request, response: Response, next: NextFunction) => {
export const changeApplicationStatusIntoRejected = async (
request: Request,
response: Response,
next: NextFunction
) => {
const applicationId = request.params.applicationId;
if (applicationId) {
await ApplicationService.changeApplicationStatusIntoRejected(request.params.applicationId)
await ApplicationService.changeApplicationStatusIntoRejected(
applicationId
)
.then((data) => {
request.handleResponse.successRespond(response)(data);
next();
Expand All @@ -192,3 +224,86 @@ export const changeApplicationStatusIntoRejected = async (request: Request, resp
request.handleResponse.errorRespond(response)("applicationId not found");
}
};

/**
* @function fetchPendingApplications that calls
* @function fetchPendingApplications in the ApplicationService
*
* @param {Request} request - Request from the frontend
* @param {Response} response - Response that need to send to the client
* @param {NextFunction} next - Next function
* @returns {IApplication} fetched pending applications
*/
export const fetchPendingApplications = async (request: Request, response:Response, next: NextFunction) =>{
await ApplicationService.fetchPendingApplications()
.then((data: any) => {
request.handleResponse.successRespond(response)(data);
next();
})
.catch((error: any) => {
request.handleResponse.errorRespond(response)(error.message);
next();
});
}
/**
* @function fetchSelectedApplications that calls
* @function fetchSelectedApplications in the ApplicationService
*
* @param {Request} request - Request from the frontend
* @param {Response} response - Response that need to send to the client
* @param {NextFunction} next - Next function
* @returns {IApplication} fetched selected applications
*/
export const fetchSelectedApplications = async (request: Request, response:Response, next: NextFunction) =>{
await ApplicationService.fetchSelectedApplications()
.then((data) => {
request.handleResponse.successRespond(response)(data);
next();
})
.catch((error: any) => {
request.handleResponse.errorRespond(response)(error.message);
next();
});
}
/**
* @function fetchInterviewApplications that calls
* @function fetchInterviewApplications in the ApplicationService
*
* @param {Request} request - Request from the frontend
* @param {Response} response - Response that need to send to the client
* @param {NextFunction} next - Next function
* @returns {IApplication} fetched interview applications
*/
export const fetchInterviewApplications = async (request: Request, response:Response, next: NextFunction) =>{
await ApplicationService.fetchInterviewApplications()
.then((data) => {
request.handleResponse.successRespond(response)(data);
next();
})
.catch((error: any) => {
request.handleResponse.errorRespond(response)(error.message);
next();
});
}

/**
* @function fetchRejectedApplications that calls
* @function fetchRejectedApplications in the ApplicationService
*
* @param {Request} request - Request from the frontend
* @param {Response} response - Response that need to send to the client
* @param {NextFunction} next - Next function
* @returns {IApplication} fetched rejected applications
*/

export const fetchRejectedApplications = async (request: Request, response:Response, next: NextFunction) =>{
await ApplicationService.fetchRejectedApplications()
.then((data) => {
request.handleResponse.successRespond(response)(data);
next();
})
.catch((error: any) => {
request.handleResponse.errorRespond(response)(error.message);
next();
});
}
8 changes: 8 additions & 0 deletions src/api/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ import {
changeApplicationStatusIntoInterview,
changeApplicationStatusIntoSelected,
changeApplicationStatusIntoRejected,
fetchPendingApplications,
fetchSelectedApplications,
fetchInterviewApplications,
fetchRejectedApplications
} from "./Application.controller";

import {
Expand Down Expand Up @@ -139,4 +143,8 @@ export default {
changeApplicationStatusIntoInterview,
changeApplicationStatusIntoSelected,
changeApplicationStatusIntoRejected,
fetchPendingApplications,
fetchSelectedApplications,
fetchInterviewApplications,
fetchRejectedApplications
};
7 changes: 7 additions & 0 deletions src/api/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,20 @@ export default function (app: Express) {
app.get("/executive/", controller.getExecutiveBoard);

// Application endpoints - Private
app.get("/admin/applications/pending/",middleware.authenticate, controller.fetchPendingApplications);
app.get("/admin/applications/selected/", middleware.authenticate, controller.fetchSelectedApplications);
app.get("/admin/applications/interview/", middleware.authenticate, controller.fetchInterviewApplications);
app.get("/admin/applications/rejected/", middleware.authenticate, controller.fetchRejectedApplications);
app.get("/admin/application/:applicationId/", middleware.authenticate, controller.getApplicationById);
app.get("/admin/application/", middleware.authenticate, controller.getApplications);
app.put("/admin/application/delete/:applicationId", middleware.authenticate, controller.setApplicationArchive);
app.put("/admin/application/interview/:applicationId", middleware.authenticate, controller.changeApplicationStatusIntoInterview);
app.put("/admin/application/selected/:applicationId", middleware.authenticate, controller.changeApplicationStatusIntoSelected);
app.put("/admin/application/rejected/:applicationId", middleware.authenticate, controller.changeApplicationStatusIntoRejected);
//@todo create @routes fetchPendingApplications,fetchInterviewApplications,fetchSelectedApplications,fetchRejectedApplications to filter INTERVIEW applications in the system


// Application endpoints - Public
app.post("/application/", controller.addApplication);

}
57 changes: 56 additions & 1 deletion src/api/services/Application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const changeApplicationStatusIntoInterview = async (
// Send email
const emailTemplate = "Interview-Email-Template.html";
const to = application.email;
const subject = "Interview for the MS Club of SLIIT";
const subject = "MS Club of SLIIT - Interview";
const emailBodyData = {
name: application.name,
email: application.email,
Expand Down Expand Up @@ -176,3 +176,58 @@ export const changeApplicationStatusIntoRejected = async (
throw new Error(error.message);
});
};


/**
* @todo create @function fetchPendingApplications to filter PENDING applications in the system
*/
export const fetchPendingApplications = async () =>{
return await ApplicationModel.aggregate([
{$match : {status: {$eq: "PENDING"}, deletedAt : {$eq: null} } },
])
.then((applications) => {
return applications;
}).catch((err) => {
throw new Error(err.message);
});
};
/**
* @todo create @function fetchInterviewApplications to filter INTERVIEW applications in the system
*/
export const fetchInterviewApplications = async () =>{
return await ApplicationModel.aggregate([
{$match : {status: {$eq: "INTERVIEW"}, deletedAt : {$eq: null} } },
])
.then((applications) => {
return applications;
}).catch((err) => {
throw new Error(err.message);
});
};
/**
* @todo create @function fetchSelectedApplications to filter SELECTED applications in the system
*/
export const fetchSelectedApplications = async () =>{
return await ApplicationModel.aggregate([
{$match : {status: {$eq: "SELECTED"}, deletedAt : {$eq: null} } },
])
.then((applications) => {
return applications;
}).catch((err) => {
throw new Error(err.message);
});
};
/**
* @todo create @function fetchRejectedApplications to filter REJECTED applications in the system
*/
export const fetchRejectedApplications = async () =>{
return await ApplicationModel.aggregate([
{$match : {status: {$eq: "REJECTED"}, deletedAt : {$eq: null} } },
])
.then((applications) => {
return applications;
}).catch((err) => {
throw new Error(err.message);
});
}

9 changes: 9 additions & 0 deletions src/api/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ import {
changeApplicationStatusIntoInterview,
changeApplicationStatusIntoSelected,
changeApplicationStatusIntoRejected,
fetchPendingApplications,
fetchInterviewApplications,
fetchSelectedApplications,
fetchRejectedApplications,

} from "./Application.service";

import {
Expand Down Expand Up @@ -126,6 +131,10 @@ export default {
changeApplicationStatusIntoInterview,
changeApplicationStatusIntoSelected,
changeApplicationStatusIntoRejected,
fetchPendingApplications,
fetchInterviewApplications,
fetchSelectedApplications,
fetchRejectedApplications,
// BoardMember Service
insertBoardMember,
getBoardMemberbyID,
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import routes from "./api/routes";
import { configs } from "./config";
import connect from "./util/database.connection";

const app: Express = express();
export const app: Express = express();
const PORT: string = configs.port;
const ENVIRONMENT = configs.environment;
const MONGO_URI = configs.mongodb.uri;
Expand Down
Loading

0 comments on commit 18d4cc4

Please sign in to comment.