-
Notifications
You must be signed in to change notification settings - Fork 278
Add feature to approve or reject OOO request #2384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 10 commits
ebb4ee4
0e60e6d
5540a2e
9ca4038
e33183a
a87f032
f171027
398d1f9
aacbff2
b22e969
680fe42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,17 +12,20 @@ import { | |
| REQUEST_ALREADY_PENDING, | ||
| USER_STATUS_NOT_FOUND, | ||
| OOO_STATUS_ALREADY_EXIST, | ||
| UNAUTHORIZED_TO_UPDATE_REQUEST, | ||
| ERROR_WHILE_ACKNOWLEDGING_REQUEST, | ||
| } from "../constants/requests"; | ||
| import { statusState } from "../constants/userStatus"; | ||
| import { logType } from "../constants/logs"; | ||
| import { addLog } from "../models/logs"; | ||
| import { getRequestByKeyValues, getRequests, updateRequest } from "../models/requests"; | ||
| import { createUserFutureStatus } from "../models/userFutureStatus"; | ||
| import { getUserStatus, addFutureStatus } from "../models/userStatus"; | ||
| import { createOooRequest, validateUserStatus } from "../services/oooRequest"; | ||
| import { createOooRequest, validateUserStatus, acknowledgeOooRequest } from "../services/oooRequest"; | ||
| import { CustomResponse } from "../typeDefinitions/global"; | ||
| import { OooRequestCreateRequest, OooRequestResponse, OooStatusRequest } from "../types/oooRequest"; | ||
| import { AcknowledgeOooRequest, OooRequestCreateRequest, OooRequestResponse, OooStatusRequest } from "../types/oooRequest"; | ||
| import { UpdateRequest } from "../types/requests"; | ||
| import { NextFunction } from "express"; | ||
|
|
||
| /** | ||
| * Controller to handle the creation of OOO requests. | ||
|
|
@@ -148,3 +151,45 @@ export const updateOooRequestController = async (req: UpdateRequest, res: Custom | |
| return res.boom.badImplementation(ERROR_WHILE_UPDATING_REQUEST); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Acknowledges an Out-of-Office (OOO) request | ||
| * | ||
| * @param {AcknowledgeOooRequest} req - The request object. | ||
| * @param {OooRequestResponse} res - The response object. | ||
| * @returns {Promise<OooRequestResponse>} Resolves with success or failure. | ||
| */ | ||
| export const acknowledgeOooRequestController = async ( | ||
|
vinit717 marked this conversation as resolved.
Outdated
|
||
| req: AcknowledgeOooRequest, | ||
| res: OooRequestResponse, | ||
| next: NextFunction | ||
| ) | ||
| : Promise<OooRequestResponse> => { | ||
|
|
||
| const dev = req.query.dev === "true"; | ||
|
|
||
| if(!dev) return res.boom.notImplemented("Feature not implemented"); | ||
|
AnujChhikara marked this conversation as resolved.
Outdated
|
||
|
|
||
| const isSuperuser = req.userData.roles?.super_user; | ||
|
pankajjs marked this conversation as resolved.
Outdated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add optional chaining to req.userData?.roles to prevent potential null/undefined errors if userData isn't properly initialized.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Amit sir, |
||
|
|
||
| if (!isSuperuser) { | ||
| return res.boom.forbidden(UNAUTHORIZED_TO_UPDATE_REQUEST); | ||
| } | ||
|
|
||
| const requestBody = req.body; | ||
| const superUserId = req.userData.id; | ||
| const requestId = req.params.id; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add validation for requestId
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Amit sir, |
||
|
|
||
| try { | ||
|
|
||
| const response = await acknowledgeOooRequest(requestId, requestBody, superUserId); | ||
|
|
||
| return res.status(200).json({ | ||
| message: response.message, | ||
| }); | ||
| } | ||
|
surajmaity1 marked this conversation as resolved.
|
||
| catch(error){ | ||
| logger.error(ERROR_WHILE_ACKNOWLEDGING_REQUEST, error); | ||
| next(error); | ||
| } | ||
| }; | ||
|
vinit717 marked this conversation as resolved.
|
Uh oh!
There was an error while loading. Please reload this page.