-
Notifications
You must be signed in to change notification settings - Fork 273
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 all 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,6 +12,9 @@ import { | |
REQUEST_ALREADY_PENDING, | ||
USER_STATUS_NOT_FOUND, | ||
OOO_STATUS_ALREADY_EXIST, | ||
UNAUTHORIZED_TO_UPDATE_REQUEST, | ||
ERROR_WHILE_ACKNOWLEDGING_REQUEST, | ||
REQUEST_ID_REQUIRED, | ||
} from "../constants/requests"; | ||
import { statusState } from "../constants/userStatus"; | ||
import { logType } from "../constants/logs"; | ||
|
@@ -20,9 +23,11 @@ import { getRequestByKeyValues, getRequests, updateRequest } from "../models/req | |
import { createUserFutureStatus } from "../models/userFutureStatus"; | ||
import { getUserStatus, addFutureStatus } from "../models/userStatus"; | ||
import { createOooRequest, validateUserStatus } from "../services/oooRequest"; | ||
import * as oooRequestService 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 +153,46 @@ 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 acknowledgeOooRequest = async ( | ||
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. NIT: please move the entire function body inside the try-catch block to capture all potential errors, including those that might occur during parameter extraction 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, |
||
req: AcknowledgeOooRequest, | ||
res: OooRequestResponse, | ||
next: NextFunction | ||
) | ||
: Promise<OooRequestResponse> => { | ||
try { | ||
const dev = req.query.dev === "true"; | ||
if(!dev) return res.boom.notImplemented("Feature not implemented"); | ||
|
||
const isSuperuser = req.userData?.roles?.super_user; | ||
if (!isSuperuser) { | ||
return res.boom.forbidden(UNAUTHORIZED_TO_UPDATE_REQUEST); | ||
} | ||
|
||
const requestBody = req.body; | ||
const superUserId = req.userData.id; | ||
const requestId = req.params.id; | ||
|
||
if (!requestId) { | ||
return res.boom.badRequest(REQUEST_ID_REQUIRED); | ||
} | ||
|
||
const response = await oooRequestService.acknowledgeOooRequest(requestId, requestBody, superUserId); | ||
|
||
return res.status(200).json({ | ||
message: response.message, | ||
}); | ||
} | ||
catch(error){ | ||
logger.error(ERROR_WHILE_ACKNOWLEDGING_REQUEST, error); | ||
next(error); | ||
return res; | ||
} | ||
}; |
vinit717 marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.