From 4576a38b852d8662d77090272c27cff9d2f9392c Mon Sep 17 00:00:00 2001 From: TarteelTamimi Date: Mon, 6 Nov 2023 23:35:59 +0200 Subject: [PATCH] remove logs to DB --- src/routes/organizationAdmin.ts | 136 --------- src/routes/organizationProfile.ts | 80 ------ src/routes/permission.ts | 64 ----- src/routes/role.ts | 64 ----- src/routes/voluntaryWork.ts | 441 ------------------------------ src/routes/volunteer.ts | 160 ----------- 6 files changed, 945 deletions(-) diff --git a/src/routes/organizationAdmin.ts b/src/routes/organizationAdmin.ts index 4351451a..60054815 100644 --- a/src/routes/organizationAdmin.ts +++ b/src/routes/organizationAdmin.ts @@ -13,14 +13,6 @@ const router = express.Router(); router.post('/signup', authenticate, authorize("POST_organizationAdmin"), validateOrganizationAdmin, (req, res, next) => { createOrganizationAdmin(req.body).then(async (data) => { - log({ - userId: data.id, - userName: req.body.name, - userType: 'root' as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Create Organization Admin ' + data.name - }).then().catch() - logToCloudWatch( 'success', 'organization admin', @@ -31,14 +23,6 @@ router.post('/signup', authenticate, authorize("POST_organizationAdmin"), valida const { password, ...dataWithoutPassword } = data; res.status(201).send({ message: "Organization Admin created successfully!!", dataWithoutPassword }) }).catch(async err => { - log({ - userId: "", - userName: req.body.name, - userType: 'root' as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Create Organization Admin ' + req.body.name - }).then().catch() - logToCloudWatch( 'failed', 'organization admin', @@ -63,14 +47,6 @@ router.post('/login', validateLogin, (req, res, next) => { sameSite: "lax" // Protect against CSRF attacks }); - log({ - userId: id, - userName: name, - userType: (data.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Login ' + (name) - }).then().catch() - logToCloudWatch( 'success', 'organization admin', @@ -82,14 +58,6 @@ router.post('/login', validateLogin, (req, res, next) => { res.status(200).send("You logged in successfully !"); }) .catch(err => { - log({ - userId: id, - userName: name, - userType: 'volunteer' as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Login ' + (name) - }).then().catch() - logToCloudWatch( 'failed', 'organization admin', @@ -109,14 +77,6 @@ router.get("/logout", authenticate, (req, res, next) => { res.cookie("myApp", '', { maxAge: -1 }) - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Logout ' + (res.locals.organizationAdmin?.name) - }).then().catch() - logToCloudWatch( 'success', 'volunteer', @@ -133,14 +93,6 @@ router.delete('/:id', authenticate, validateAdminId, authorize("DELETE_organizat deleteOrganizationAdmin(id) .then(async data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Delete Organization Admin with id: ' + id - }).then().catch() - logToCloudWatch( 'success', 'organization admin', @@ -152,14 +104,6 @@ router.delete('/:id', authenticate, validateAdminId, authorize("DELETE_organizat res.send(data); }) .catch(async err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Delete Organization Admin with id: ' + id - }).then().catch() - logToCloudWatch( 'failed', 'organization admin', @@ -174,14 +118,6 @@ router.delete('/:id', authenticate, validateAdminId, authorize("DELETE_organizat router.put("/:id", authenticate, authorize("PUT_organizationAdmin"), validateAdminEdited, async (req, res, next) => { editOrganizationAdmin({ ...req.body, id: req.params.id }).then(async () => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Edit Organization Admin with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'organization admin', @@ -192,14 +128,6 @@ router.put("/:id", authenticate, authorize("PUT_organizationAdmin"), validateAdm res.status(200).send("Organization Admin edited successfully!!") }).catch(async err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Edit Organization Admin with id: ' + req.params.id - }) - logToCloudWatch( 'failed', 'organization admin', @@ -224,14 +152,6 @@ router.get('/search', authenticate, authorize("GET_organizationAdmins"), async ( getOrganizationAdmins(payload) .then(async data => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer?.type ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Get Organization Admin/s' - }).then().catch() - logToCloudWatch( 'success', 'organization admin', @@ -243,14 +163,6 @@ router.get('/search', authenticate, authorize("GET_organizationAdmins"), async ( res.send(data); }) .catch(async err => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer?.type ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Get Organization Admin/s' - }).then().catch() - logToCloudWatch( 'failed', 'organization admin', @@ -265,14 +177,6 @@ router.get('/search', authenticate, authorize("GET_organizationAdmins"), async ( router.get("/forget-password", authenticate, authorize("POST_voluntaryWork"), (req, res, next) => { forgetPassword(res.locals.organizationAdmin?.id, res.locals.organizationAdmin?.email).then(() => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Forget password organization admin id ' + res.locals.organizationAdmin?.id - }).then().catch() - logToCloudWatch( 'success', 'organization admin', @@ -283,14 +187,6 @@ router.get("/forget-password", authenticate, authorize("POST_voluntaryWork"), (r res.send("Password reset link has been sent to your email") }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Forget password organization admin id ' + res.locals.organizationAdmin?.id - }).then().catch() - logToCloudWatch( 'failed', 'organization admin', @@ -313,14 +209,6 @@ router.get("/reset-password/:id/:token", authenticate, authorize("POST_voluntary maxAge: 15 * 60 * 1000, sameSite: "lax" }); - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Validate token to reset password for organization admin id ' + res.locals.organizationAdmin?.id - }).then().catch() - logToCloudWatch( 'success', 'organization admin', @@ -330,14 +218,6 @@ router.get("/reset-password/:id/:token", authenticate, authorize("POST_voluntary ).then().catch() res.send("You can now set your new password by making a POST request to /reset-password/:id with your new password in the request body."); } catch (error) { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Validate token to reset password for organization admin id ' + res.locals.organizationAdmin?.id - }).then().catch() - logToCloudWatch( 'failed', 'organization admin', @@ -356,14 +236,6 @@ router.post("/reset-password/:id", authenticate, authorize("POST_voluntaryWork") const password = req.body.password; // if(!password || !isValidPassword(password) )next() bad request resetPassword(id, token, password).then(data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Reset password for organization admin id ' + res.locals.organizationAdmin?.id - }).then().catch() - logToCloudWatch( 'success', 'organization admin', @@ -374,14 +246,6 @@ router.post("/reset-password/:id", authenticate, authorize("POST_voluntaryWork") res.status(200).send(data) }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Reset password for organization admin id ' + res.locals.organizationAdmin?.id - }).then().catch() - logToCloudWatch( 'failed', 'organization admin', diff --git a/src/routes/organizationProfile.ts b/src/routes/organizationProfile.ts index 04830839..042031d4 100644 --- a/src/routes/organizationProfile.ts +++ b/src/routes/organizationProfile.ts @@ -10,14 +10,6 @@ const router = express.Router(); router.post('/', authorize("POST_organizationProfile"), validateOrganizationProfile, (req, res, next) => { createOrganizationProfile(req.body).then((data) => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Create Organization Profile ' + data.name - }).then().catch() - logToCloudWatch( 'success', 'organization profile', @@ -28,14 +20,6 @@ router.post('/', authorize("POST_organizationProfile"), validateOrganizationProf res.status(201).send({message:"Organization Profile created successfully!!" , data}) }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Create Organization Profile ' + req.body.name - }).then().catch() - logToCloudWatch( 'failed', 'organization profile', @@ -53,14 +37,6 @@ router.delete('/:id', validateOrgId, authorize("DELETE_organizationProfile"), as deleteOrganizationProfile(id) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Delete Organization Profile with id: ' + id - }).then().catch() - logToCloudWatch( 'success', 'organization profile', @@ -72,14 +48,6 @@ router.delete('/:id', validateOrgId, authorize("DELETE_organizationProfile"), as res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Delete Organization Profile with id: ' + id - }).then().catch() - logToCloudWatch( 'failed', 'organization profile', @@ -94,14 +62,6 @@ router.delete('/:id', validateOrgId, authorize("DELETE_organizationProfile"), as router.put("/:id", validateOrgId, authorize("PUT_organizationProfile"), async (req, res, next) => { editOrganizationProfile(req.body).then(() => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Edit Organization Profile with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'organization profile', @@ -112,14 +72,6 @@ router.put("/:id", validateOrgId, authorize("PUT_organizationProfile"), async (r res.status(200).send("Organization Profile edited successfully!!") }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Edit Organization Profile with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'organization profile', @@ -143,14 +95,6 @@ router.get('/search', authorize("GET_organizationProfiles"), async (req, res, ne searchOrganizationProfile(payload) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Search Organization Profiles' - }).then().catch() - logToCloudWatch( 'success', 'organization profile', @@ -162,14 +106,6 @@ router.get('/search', authorize("GET_organizationProfiles"), async (req, res, ne res.status(200).send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer?.type ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Search Organization Profiles' - }).then().catch() - logToCloudWatch( 'failed', 'organization profile', @@ -190,14 +126,6 @@ router.get('/', authorize("GET_organizationProfiles"), async (req, res, next) => getOrganizationProfile(payload) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Get Organization Profiles' - }).then().catch() - logToCloudWatch( 'success', 'organization profile', @@ -209,14 +137,6 @@ router.get('/', authorize("GET_organizationProfiles"), async (req, res, next) => res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer?.type ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Get Organization Profiles' - }).then().catch() - logToCloudWatch( 'failed', 'organization profile', diff --git a/src/routes/permission.ts b/src/routes/permission.ts index 2326479b..81917bfe 100644 --- a/src/routes/permission.ts +++ b/src/routes/permission.ts @@ -11,14 +11,6 @@ var router = express.Router(); router.post('/', authorize("POST_permission"), validatePermission, (req, res, next) => { createPermission(req.body).then((data) => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Create Permission ' + req.body.name - }).then().catch() - logToCloudWatch( 'success', 'permission', @@ -29,14 +21,6 @@ router.post('/', authorize("POST_permission"), validatePermission, (req, res, ne res.status(201).send({ message: "Permission created successfully!!", data }) }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Create Permission ' + req.body.name - }).then().catch() - logToCloudWatch( 'failed', 'permission', @@ -54,14 +38,6 @@ router.delete('/:id', validatePermissionId, authorize("DELETE_permission"), asyn deletePermission(id) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Delete Permission with id: ' + id - }).then().catch() - logToCloudWatch( 'success', 'permission', @@ -73,14 +49,6 @@ router.delete('/:id', validatePermissionId, authorize("DELETE_permission"), asyn res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Delete Permission with id: ' + id - }).then().catch() - logToCloudWatch( 'failed', 'permission', @@ -95,14 +63,6 @@ router.delete('/:id', validatePermissionId, authorize("DELETE_permission"), asyn router.put("/:id", authorize("PUT_permission"), validatePermissionId, async (req, res, next) => { editPermission({ ...req.body, id: req.params.id?.toString() }).then(() => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Edit Permission with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'permission', @@ -113,14 +73,6 @@ router.put("/:id", authorize("PUT_permission"), validatePermissionId, async (req res.status(200).send("Permission edited successfully!!") }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Edit Permission with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'permission', @@ -143,14 +95,6 @@ router.get('/', authorize("GET_permissions"), async (req, res, next) => { getPermissions(payload) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Get Permission/s' - }).then().catch() - logToCloudWatch( 'success', 'permission', @@ -162,14 +106,6 @@ router.get('/', authorize("GET_permissions"), async (req, res, next) => { res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Get Permission/s' - }).then().catch() - logToCloudWatch( 'failed', 'permission', diff --git a/src/routes/role.ts b/src/routes/role.ts index 2e03f0a4..57f9d375 100644 --- a/src/routes/role.ts +++ b/src/routes/role.ts @@ -11,14 +11,6 @@ var router = express.Router(); router.post('/', authorize("POST_role"), validateRole, (req, res, next) => { createRole(req.body).then((data) => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Create Role ' + req.body.name - }).then().catch() - logToCloudWatch( 'success', 'role', @@ -29,14 +21,6 @@ router.post('/', authorize("POST_role"), validateRole, (req, res, next) => { res.status(201).send({message:"Role created successfully!!",data}) }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Create Role ' + req.body.name - }).then().catch() - logToCloudWatch( 'failed', 'role', @@ -54,14 +38,6 @@ router.delete('/:id', validateRoleId, authorize("DELETE_role"), async (req, res, deleteRole(id) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Delete Role with id: ' + id - }).then().catch() - logToCloudWatch( 'success', 'role', @@ -73,14 +49,6 @@ router.delete('/:id', validateRoleId, authorize("DELETE_role"), async (req, res, res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Delete Role with id: ' + id - }).then().catch() - logToCloudWatch( 'failed', 'role', @@ -95,14 +63,6 @@ router.delete('/:id', validateRoleId, authorize("DELETE_role"), async (req, res, router.put("/:id", authorize("PUT_role"), validateEditedRole, async (req, res, next) => { editRole({ ...req.body, id: req.params.id?.toString() }).then(() => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Edit Role with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'role', @@ -113,14 +73,6 @@ router.put("/:id", authorize("PUT_role"), validateEditedRole, async (req, res, n res.status(200).send("Role edited successfully!!") }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Edit Role with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'role', @@ -143,14 +95,6 @@ router.get('/', authorize("GET_roles"), async (req, res, next) => { getRoles(payload) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Get Role/s' - }).then().catch() - logToCloudWatch( 'success', 'role', @@ -162,14 +106,6 @@ router.get('/', authorize("GET_roles"), async (req, res, next) => { res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Get Role/s' - }).then().catch() - logToCloudWatch( 'failed', 'role', diff --git a/src/routes/voluntaryWork.ts b/src/routes/voluntaryWork.ts index 762640fd..d4fae940 100644 --- a/src/routes/voluntaryWork.ts +++ b/src/routes/voluntaryWork.ts @@ -22,14 +22,6 @@ var router = express.Router(); router.post('/', authorize("POST_voluntaryWork"), validateVoluntaryWork, (req, res, next) => { createVoluntaryWork({ ...req.body, creatorId: res.locals.volunteer?.id || res.locals.organizationAdmin?.id }).then((data) => { sendingEmails(data.name).then(()=>{ - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Create Voluntary Work ' + req.body.name - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -40,14 +32,6 @@ router.post('/', authorize("POST_voluntaryWork"), validateVoluntaryWork, (req, r res.status(201).send({ message: "Voluntary work created successfully!!", data }) }).catch(err=>{ - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Sending emails to announce new voluntary work ' + req.body.name - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -60,14 +44,6 @@ router.post('/', authorize("POST_voluntaryWork"), validateVoluntaryWork, (req, r }) }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Create Voluntary Work ' + req.body.name - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -82,14 +58,6 @@ router.post('/', authorize("POST_voluntaryWork"), validateVoluntaryWork, (req, r router.put("/:id", authorize("PUT_voluntaryWork"), validateEditedVoluntaryWork, async (req, res, next) => { editVoluntaryWork({ ...req.body, id: req.params.id?.toString() }).then(() => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Edit Voluntary Work with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -100,14 +68,6 @@ router.put("/:id", authorize("PUT_voluntaryWork"), validateEditedVoluntaryWork, res.status(201).send("Voluntary Work edited successfully!!") }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Edit Voluntary Work with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -126,14 +86,6 @@ router.delete('/:id', validateVoluntaryWorkId, authorize("DELETE_voluntaryWork") deleteVoluntaryWork(id) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Delete Voluntary Work with id: ' + id - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -145,14 +97,6 @@ router.delete('/:id', validateVoluntaryWorkId, authorize("DELETE_voluntaryWork") res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Delete Voluntary Work with id: ' + id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -180,14 +124,6 @@ router.put("/image/:id", validateVoluntaryWorkId, authorize("PUT_images"), async await putImages(Number(req.params.id), uploadedFiles, organizationName); - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Add images to voluntary work with id ' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -198,14 +134,6 @@ router.put("/image/:id", validateVoluntaryWorkId, authorize("PUT_images"), async res.status(201).send("Images added successfully!!"); } catch (err) { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Add images to voluntary work with id ' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -221,14 +149,6 @@ router.put("/image/:id", validateVoluntaryWorkId, authorize("PUT_images"), async router.get('/image/:id', validateVoluntaryWorkId, async (req, res, next) => { getImages(Number(req.params.id)) .then(data => { - log({ - userId: res.locals.volunteer?.id || res.locals.organizationAdmin?.id, - userName: res.locals.volunteer?.name || res.locals.organizationAdmin?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Get image/s for voluntary work with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -240,14 +160,6 @@ router.get('/image/:id', validateVoluntaryWorkId, async (req, res, next) => { res.send(data); }) .catch(err => { - log({ - userId: res.locals.volunteer?.id || res.locals.organizationAdmin?.id, - userName: res.locals.volunteer?.name || res.locals.organizationAdmin?.name, - userType: res.locals.volunteer?.type as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Get image/s for voluntary work with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -270,14 +182,6 @@ router.delete('/image/:id', validateVoluntaryWorkId, authorize("PUT_images"), va deleteImage(id, req.body.imageName + '.png').then(() => { deleteFromS3(key, 'image') .then(data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Delete image from Voluntary Work with id: ' + id - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -289,14 +193,6 @@ router.delete('/image/:id', validateVoluntaryWorkId, authorize("PUT_images"), va res.status(200).send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Delete image from Voluntary Work with id: ' + id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -318,15 +214,6 @@ router.delete('/image/:id', validateVoluntaryWorkId, authorize("PUT_images"), va router.post("/rating/:id", validateVoluntaryWorkId, authorize("DELETE_voluntaryWork"), async (req, res, next) => { volunteerReminder(Number(req.params.id)).then(() => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Reminder to add rating and feedback for voluntary work with id: ' + req.params.id, - - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -337,14 +224,6 @@ router.post("/rating/:id", validateVoluntaryWorkId, authorize("DELETE_voluntaryW res.status(201).send("Create remainder for rate and feedback successfully!!") }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Reminder to add rating and feedback for voluntary work with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -359,14 +238,6 @@ router.post("/rating/:id", validateVoluntaryWorkId, authorize("DELETE_voluntaryW router.put("/rating/:id", validateVoluntaryWorkId, authorize("PUT_rating"), checkParticipation,validateRating, async (req, res, next) => { putRating(Number(req.params.id), Number(req.body.rating), res.locals.volunteer?.name).then(() => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: res.locals.volunteer?.type as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Add or update Rating to voluntary work with id' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -377,14 +248,6 @@ router.put("/rating/:id", validateVoluntaryWorkId, authorize("PUT_rating"), chec res.status(201).send("Rating added or updated successfully!!") }).catch(err => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: res.locals.volunteer?.type as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Add or update Rating to voluntary work with id' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -400,14 +263,6 @@ router.put("/rating/:id", validateVoluntaryWorkId, authorize("PUT_rating"), chec router.put("/feedback/:id", validateVoluntaryWorkId, authorize("PUT_feedback"), checkParticipation, async (req, res, next) => { if (!req.body.feedback)res.status(400).send("Feedback is required!") putFeedback(Number(req.params.id), req.body.feedback, res.locals.volunteer?.name).then(() => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: res.locals.volunteer?.type as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Add or update feedback to voluntary work with id' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -418,14 +273,6 @@ router.put("/feedback/:id", validateVoluntaryWorkId, authorize("PUT_feedback"), res.status(201).send("Feedback or update added successfully!!") }).catch(err => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name, - userType: res.locals.volunteer?.type as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Add or update feedback to voluntary work with id' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -440,14 +287,6 @@ router.put("/feedback/:id", validateVoluntaryWorkId, authorize("PUT_feedback"), router.delete("/rating/:id", validateVoluntaryWorkId, authorize("PUT_rating"), checkParticipation, async (req, res, next) => { deleteRating(Number(req.params.id), res.locals.volunteer?.name).then(() => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: res.locals.volunteer?.type as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Delete Rating to voluntary work with id' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -458,14 +297,6 @@ router.delete("/rating/:id", validateVoluntaryWorkId, authorize("PUT_rating"), c res.status(200).send("Rating deleted successfully!!") }).catch(err => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: res.locals.volunteer?.type as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Delete Rating to voluntary work with id' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -480,14 +311,6 @@ router.delete("/rating/:id", validateVoluntaryWorkId, authorize("PUT_rating"), c router.delete("/feedback/:id", validateVoluntaryWorkId, authorize("PUT_rating"), checkParticipation, async (req, res, next) => { deleteFeedback(Number(req.params.id), res.locals.volunteer?.name).then(() => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: res.locals.volunteer?.type as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Delete Feedback to voluntary work with id' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -498,14 +321,6 @@ router.delete("/feedback/:id", validateVoluntaryWorkId, authorize("PUT_rating"), res.status(200).send("Feedback deleted successfully!!") }).catch(err => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: res.locals.volunteer?.type as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Delete Feedback to voluntary work with id' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -543,14 +358,6 @@ router.get('/search', authorize("GET_voluntaryWorks"), async (req, res, next) => getVoluntaryWorks(payload) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Search Voluntary Work/s' - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -562,14 +369,6 @@ router.get('/search', authorize("GET_voluntaryWorks"), async (req, res, next) => res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Search Voluntary Work/s' - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -610,14 +409,6 @@ router.get('/advanced-search', authorize("GET_analysis"), async (req, res, next) getVoluntaryWorks(payload) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Advanced search for Voluntary Work/s' - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -629,14 +420,6 @@ router.get('/advanced-search', authorize("GET_analysis"), async (req, res, next) res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: "root" as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Advanced search for Voluntary Work/s' - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -652,14 +435,6 @@ router.get('/advanced-search', authorize("GET_analysis"), async (req, res, next) router.get('/analysis', authorize("GET_analysis"), async (req, res, next) => { getAnalysis() .then(data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Analyze the system ' - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -671,14 +446,6 @@ router.get('/analysis', authorize("GET_analysis"), async (req, res, next) => { res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: "root" as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Analyze the system ' - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -694,14 +461,6 @@ router.get('/analysis', authorize("GET_analysis"), async (req, res, next) => { router.get('/analysis/:id', authorize("DELETE_organizationProfile"), validateOrgId, async (req, res, next) => { getOrganizationAnalysis(req.params.id.toString()) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: 'root' as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Analyze the organization voluntary works with id ' + req.params.id.toString() - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -713,14 +472,6 @@ router.get('/analysis/:id', authorize("DELETE_organizationProfile"), validateOrg res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: "root" as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Analyze the organization voluntary works with id ' + req.params.id.toString() - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -747,14 +498,6 @@ router.get('/recommendation', authorize("GET_recommendation"), async (req, res, getRecommendation(payload) .then(data => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: res.locals.volunteer?.type as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Get recommendation' - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -766,14 +509,6 @@ router.get('/recommendation', authorize("GET_recommendation"), async (req, res, res.send(data); }) .catch(err => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: res.locals.volunteer?.type as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Get recommendation' - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -788,14 +523,6 @@ router.get('/recommendation', authorize("GET_recommendation"), async (req, res, router.get('/volunteer/:id', validateVolunteerId, async (req, res, next) => { getVoluntaryWorksForVolunteer(req.params.id) .then(data => { - log({ - userId: res.locals.volunteer?.id || res.locals.organizationAdmin?.id, - userName: res.locals.volunteer?.name || res.locals.organizationAdmin?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Get voluntary works for volunteer with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -807,14 +534,6 @@ router.get('/volunteer/:id', validateVolunteerId, async (req, res, next) => { res.send(data); }) .catch(err => { - log({ - userId: res.locals.volunteer?.id || res.locals.organizationAdmin?.id, - userName: res.locals.volunteer?.name || res.locals.organizationAdmin?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Get voluntary works for volunteer with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -830,14 +549,6 @@ router.get('/volunteer/:id', validateVolunteerId, async (req, res, next) => { router.get('/rating-and-feedback/:id', validateVoluntaryWorkId, async (req, res, next) => { getFeedbackAndRating(Number(req.params.id.toString())) .then(data => { - log({ - userId: res.locals.volunteer?.id || res.locals.organizationAdmin?.id, - userName: res.locals.volunteer?.name || res.locals.organizationAdmin?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Get rating and feedback for voluntary work with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -849,14 +560,6 @@ router.get('/rating-and-feedback/:id', validateVoluntaryWorkId, async (req, res, res.send(data); }) .catch(err => { - log({ - userId: res.locals.volunteer?.id || res.locals.organizationAdmin?.id, - userName: res.locals.volunteer?.name || res.locals.organizationAdmin?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Get rating and feedback for voluntary work with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -872,14 +575,6 @@ router.get('/rating-and-feedback/:id', validateVoluntaryWorkId, async (req, res, router.get('/sufficient-team/:id', validateVoluntaryWorkId, async (req, res, next) => { findSmallestSufficientTeam(Number(req.params.id.toString())) .then(data => { - log({ - userId: res.locals.volunteer?.id || res.locals.organizationAdmin?.id, - userName: res.locals.volunteer?.name || res.locals.organizationAdmin?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Get smallest sufficient team for voluntary work with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -891,14 +586,6 @@ router.get('/sufficient-team/:id', validateVoluntaryWorkId, async (req, res, nex res.send(data); }) .catch(err => { - log({ - userId: res.locals.volunteer?.id || res.locals.organizationAdmin?.id, - userName: res.locals.volunteer?.name || res.locals.organizationAdmin?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Get smallest sufficient team for voluntary work with id: ' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -915,14 +602,6 @@ router.put("/register/:id", validateVoluntaryWorkId, authorize("REGISTER_volunta const voluntaryWork = await VoluntaryWork.findOne({ where: { id: Number(req.params.id) } }) if (res.locals.volunteer) { registerByVolunteer(Number(req.params.id), res.locals.volunteer?.volunteerProfile).then(async () => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: res.locals.volunteer?.type as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Register to voluntary work with id' + req.params.id - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -939,14 +618,6 @@ router.put("/register/:id", validateVoluntaryWorkId, authorize("REGISTER_volunta res.status(201).send("Registration done successfully!!") }).catch(err => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: res.locals.volunteer?.type as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Register to voluntary work with id' + req.params.id - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -963,14 +634,6 @@ router.put("/register/:id", validateVoluntaryWorkId, authorize("REGISTER_volunta } const volunteer = await Volunteer.findOne({ where: { id: (req.body.volunteerId.toString()) } }) registerByOrganizationAdmin(Number(req.params.id), req.body.volunteerId.toString()).then(() => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Register By Organization Admin to voluntary work with id' + req.params.id + " volunteer id: " + req.body.volunteerId.toString() - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -989,14 +652,6 @@ router.put("/register/:id", validateVoluntaryWorkId, authorize("REGISTER_volunta res.status(201).send("Registration done successfully!!") }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Register By Organization Admin to voluntary work with id' + req.params.id + " volunteer id: " + req.body.volunteerId.toString() - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -1015,14 +670,6 @@ router.put("/deregister/:id", validateVoluntaryWorkId, authorize("DEREGISTER_vol const volunteer = await Volunteer.findOne({ where: { id: (req.body.volunteerId.toString()) } }) deregisterVoluntaryWork(Number(req.params.id), res.locals.volunteer.id || req.body.volunteerId.toString()).then(() => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Deregister to voluntary work with id' + req.params.id + " volunteer id: " + res.locals.volunteer?.id || req.body.volunteerId.toString() - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -1039,14 +686,6 @@ router.put("/deregister/:id", validateVoluntaryWorkId, authorize("DEREGISTER_vol res.status(201).send("Deregistration done successfully!!") }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Deregister to voluntary work with id' + req.params.id + " volunteer id: " + res.locals.volunteer?.id || req.body.volunteerId.toString() - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -1068,14 +707,6 @@ router.post("/generate-certificate/:id", validateVoluntaryWorkId, authorize("PUT const organizationName = organization?.name || ''; generateCertificate(Number(req.params.id), organizationName, req.body.date || date).then(() => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Certifications generated successfully for organization: ' + organizationName - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -1087,14 +718,6 @@ router.post("/generate-certificate/:id", validateVoluntaryWorkId, authorize("PUT res.status(201).send("Certifications generated and sent successfully!!") }).catch((err) => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Generating certifications for organization: ' + organizationName - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -1121,14 +744,6 @@ router.put("/template/:id", validateVoluntaryWorkId, authorize("PUT_images"), as const organizationName = organization?.name || req.body.organizationName; await putCertificateTemplate(organizationName, uploadedFiles).then(() => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Template added successfully for organization: ' + organizationName - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -1140,14 +755,6 @@ router.put("/template/:id", validateVoluntaryWorkId, authorize("PUT_images"), as res.status(201).send("Template added successfully!!") }).catch((err) => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Adding template for organization: ' + organizationName - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -1169,14 +776,6 @@ router.delete('/certificate/:id', validateVoluntaryWorkId, authorize("DELETE_vol deleteFromS3(key, "certificate") .then(data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Delete certificate for volunteer: ' + req.body.volunteerName - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -1188,14 +787,6 @@ router.delete('/certificate/:id', validateVoluntaryWorkId, authorize("DELETE_vol res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Delete image for volunteer: ' + req.body.volunteerName - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -1216,14 +807,6 @@ router.delete('/template/:id', validateOrganizationProfile, authorize("DELETE_vo deleteFromS3(key, "template") .then(data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Delete template for organization :' + req.body.organizationName - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -1235,14 +818,6 @@ router.delete('/template/:id', validateOrganizationProfile, authorize("DELETE_vo res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Delete template for organization :' + req.body.organizationName - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', @@ -1262,14 +837,6 @@ router.get('/template/:id', authorize("PUT_images"), async (req, res, next) => { const prefix = `templates/${organizationProfile?.name || req.body.organizationName}` loadFromS3(process.env.AWS_CERTIFICATES_BUCKET_NAME || '', prefix) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Get template/s for organization: ' + req.body.organizationName - }).then().catch() - logToCloudWatch( 'success', 'voluntary work', @@ -1281,14 +848,6 @@ router.get('/template/:id', authorize("PUT_images"), async (req, res, next) => { res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Get template/s for organization: ' + req.body.organizationName - }).then().catch() - logToCloudWatch( 'failed', 'voluntary work', diff --git a/src/routes/volunteer.ts b/src/routes/volunteer.ts index 67013162..6744f94a 100644 --- a/src/routes/volunteer.ts +++ b/src/routes/volunteer.ts @@ -14,14 +14,6 @@ var router = express.Router(); router.post('/signup', validateVolunteer, (req, res, next) => { createVolunteer({ ...req.body, type: "volunteer" }).then((data) => { - log({ - userId: data.id, - userName: req.body.name, - userType: data.type as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Signup volunteer ' + req.body.name - }).then().catch() - logToCloudWatch( 'success', 'volunteer', @@ -43,14 +35,6 @@ router.post('/signup', validateVolunteer, (req, res, next) => { const data = await Volunteer.findOne({ where: { id: req.body.id } }); if (data) { - log({ - userId: data.id, - userName: req.body.name, - userType: data.type as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Signup volunteer ' + req.body.name - }).then().catch() - logToCloudWatch( 'success', 'volunteer', @@ -70,14 +54,6 @@ router.post('/signup', validateVolunteer, (req, res, next) => { } } else { - log({ - userId: "", - userName: req.body.name, - userType: req.body.type as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Signup volunteer ' + req.body.name - }).then().catch() - logToCloudWatch( 'failed', 'volunteer', @@ -102,14 +78,6 @@ router.post('/login', validateLogin, (req, res, next) => { sameSite: "lax" // Protect against CSRF attacks }); - log({ - userId: id, - userName: name, - userType: (data.volunteer?.type) as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Login ' + (name) - }).then().catch() - logToCloudWatch( 'success', 'volunteer', @@ -121,14 +89,6 @@ router.post('/login', validateLogin, (req, res, next) => { res.status(201).send("You logged in successfully !"); }) .catch(err => { - log({ - userId: id, - userName: name, - userType: 'volunteer' as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Login ' + (name) - }).then().catch() - logToCloudWatch( 'failed', 'volunteer', @@ -146,14 +106,6 @@ router.delete('/:id', authenticate, authorize("DELETE_volunteer"), validateVolun deleteVolunteer(id) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Delete Volunteer with id: ' + id - }).then().catch() - logToCloudWatch( 'success', 'volunteer', @@ -165,14 +117,6 @@ router.delete('/:id', authenticate, authorize("DELETE_volunteer"), validateVolun res.send(data); }) .catch(error => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Delete Volunteer with id: ' + id - }).then().catch() - logToCloudWatch( 'failed', 'volunteer', @@ -187,14 +131,6 @@ router.delete('/:id', authenticate, authorize("DELETE_volunteer"), validateVolun router.put("/:id", authenticate, authorize("PUT_volunteer"), validateEditedVolunteer, async (req, res, next) => { editVolunteer({ ...req.body, id: req.params.id?.toString() }).then(() => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Edit Volunteer with id: ' + req.params.id?.toString() - }).then().catch() - logToCloudWatch( 'success', 'volunteer', @@ -205,14 +141,6 @@ router.put("/:id", authenticate, authorize("PUT_volunteer"), validateEditedVolun res.status(201).send("Volunteer edited successfully!!") }).catch(err => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Edit Volunteer with id: ' + req.params.id?.toString() - }).then().catch() - logToCloudWatch( 'failed', 'volunteer', @@ -242,14 +170,6 @@ router.get('/search', authenticate, authorize("GET_volunteers"), async (req, res getVolunteers(payload) .then(data => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'get Volunteer/s' - }).then().catch() - logToCloudWatch( 'success', 'volunteer', @@ -261,14 +181,6 @@ router.get('/search', authenticate, authorize("GET_volunteers"), async (req, res res.send(data); }) .catch(err => { - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Get Volunteer/s' - }).then().catch() - logToCloudWatch( 'failed', 'volunteer', @@ -288,14 +200,6 @@ router.get("/logout", authenticate, (req, res, next) => { res.cookie("myApp", '', { maxAge: -1 }) - log({ - userId: res.locals.organizationAdmin?.id || res.locals.volunteer?.id, - userName: res.locals.organizationAdmin?.name || res.locals.volunteer?.name, - userType: (res.locals.volunteer ? res.locals.volunteer?.type : res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Logout ' + (res.locals.organizationAdmin?.name || res.locals.volunteer?.name) - }).then().catch() - logToCloudWatch( 'success', 'volunteer', @@ -309,14 +213,6 @@ router.get("/logout", authenticate, (req, res, next) => { router.get('/me', authenticate, async (req, res, next) => { if (res.locals.volunteer) { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: (res.locals.volunteer?.type) as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Get my information' - }).then().catch() - logToCloudWatch( 'success', 'volunteer', @@ -327,14 +223,6 @@ router.get('/me', authenticate, async (req, res, next) => { res.send(res.locals.volunteer); } else if (res.locals.organizationAdmin) { - log({ - userId: res.locals.organizationAdmin?.id, - userName: res.locals.organizationAdmin?.name, - userType: (res.locals.organizationAdmin?.name === "root" ? "root" : 'admin') as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Get my information' - }).then().catch() - logToCloudWatch( 'failed', 'organization admin', @@ -349,14 +237,6 @@ router.get('/me', authenticate, async (req, res, next) => { router.get("/forget-password", authenticate, authorize("PUT_rating"), (req, res, next) => { forgetPassword(res.locals.volunteer?.id, res.locals.volunteer?.email).then(() => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: (res.locals.volunteer?.type) as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Forget password volunteer id ' + res.locals.volunteer?.id - }).then().catch() - logToCloudWatch( 'success', 'volunteer', @@ -367,14 +247,6 @@ router.get("/forget-password", authenticate, authorize("PUT_rating"), (req, res, res.send("Password reset link has been sent to your email") }).catch(err => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: (res.locals.volunteer?.type) as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Forget password volunteer id ' + res.locals.volunteer?.id - }).then().catch() - logToCloudWatch( 'failed', 'volunteer', @@ -397,14 +269,6 @@ router.get("/reset-password/:id/:token", authenticate, authorize("PUT_rating"), maxAge: 15 * 60 * 1000, sameSite: "lax" }); - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: (res.locals.volunteer?.type) as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Validate token to reset password for volunteer id ' + res.locals.volunteer?.id - }).then().catch() - logToCloudWatch( 'success', 'volunteer', @@ -414,14 +278,6 @@ router.get("/reset-password/:id/:token", authenticate, authorize("PUT_rating"), ).then().catch() res.send("You can now set your new password by making a POST request to /reset-password/:id with your new password in the request body."); } catch (error) { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: (res.locals.volunteer?.type) as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Validate token to reset password for volunteer id ' + res.locals.volunteer?.id - }).then().catch() - logToCloudWatch( 'failed', 'volunteer', @@ -440,14 +296,6 @@ router.post("/reset-password/:id", authenticate, authorize("PUT_rating"), valida const password = req.body.password; // if(!password || !isValidPassword(password) )next() bad request resetPassword(id, token, password).then(data => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: (res.locals.volunteer?.type) as NSLogs.userType, - type: 'success' as NSLogs.Type, - request: 'Reset password for volunteer id ' + res.locals.volunteer?.id - }).then().catch() - logToCloudWatch( 'success', 'volunteer', @@ -458,14 +306,6 @@ router.post("/reset-password/:id", authenticate, authorize("PUT_rating"), valida res.status(200).send(data) }).catch(err => { - log({ - userId: res.locals.volunteer?.id, - userName: res.locals.volunteer?.name, - userType: (res.locals.volunteer?.type) as NSLogs.userType, - type: 'failed' as NSLogs.Type, - request: 'Reset password for volunteer id ' + res.locals.volunteer?.id - }).then().catch() - logToCloudWatch( 'failed', 'volunteer',