-
Notifications
You must be signed in to change notification settings - Fork 279
Feat/user ooo approve reject #2425
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 ( | ||||||||||||||||||||
| 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; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+193
to
+197
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. 🧹 Nitpick (assertive) Return the error response, not the stale In the - next(error);
- return res;
+ return next(error);📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
| }; | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,8 +5,8 @@ import { | |||||||||||||||||||||
| } from "../constants/requests"; | ||||||||||||||||||||||
| import { getRequests } from "../models/requests"; | ||||||||||||||||||||||
| import { getPaginatedLink } from "../utils/helper"; | ||||||||||||||||||||||
| import { createOooRequestController, updateOooRequestController } from "./oooRequests"; | ||||||||||||||||||||||
| import { OooRequestCreateRequest, OooRequestResponse } from "../types/oooRequest"; | ||||||||||||||||||||||
| import { acknowledgeOooRequest, createOooRequestController, updateOooRequestController } from "./oooRequests"; | ||||||||||||||||||||||
| import { AcknowledgeOooRequest, OooRequestCreateRequest, OooRequestResponse } from "../types/oooRequest"; | ||||||||||||||||||||||
| import { CustomResponse } from "../typeDefinitions/global"; | ||||||||||||||||||||||
| import { ExtensionRequestRequest, ExtensionRequestResponse } from "../types/extensionRequests"; | ||||||||||||||||||||||
| import { createTaskExtensionRequest, updateTaskExtensionRequest } from "./extensionRequestsv2"; | ||||||||||||||||||||||
|
|
@@ -16,8 +16,7 @@ import { createTaskRequestController } from "./taskRequestsv2"; | |||||||||||||||||||||
| import { OnboardingExtensionCreateRequest, OnboardingExtensionResponse, UpdateOnboardingExtensionStateRequest } from "../types/onboardingExtension"; | ||||||||||||||||||||||
| import { createOnboardingExtensionRequestController, updateOnboardingExtensionRequestController, updateOnboardingExtensionRequestState } from "./onboardingExtension"; | ||||||||||||||||||||||
| import { UpdateOnboardingExtensionRequest } from "../types/onboardingExtension"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import { Request } from "express"; | ||||||||||||||||||||||
| import { NextFunction, Request } from "express"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export const createRequestController = async ( | ||||||||||||||||||||||
| req: OooRequestCreateRequest | ExtensionRequestRequest | TaskRequestRequest | OnboardingExtensionCreateRequest, | ||||||||||||||||||||||
|
|
@@ -121,9 +120,13 @@ export const getRequestsController = async (req: any, res: any) => { | |||||||||||||||||||||
| * @param {CustomResponse} res - The response object. | ||||||||||||||||||||||
| * @returns {Promise<void>} Resolves or sends an error for invalid types. | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| export const updateRequestBeforeAcknowledgedController = async (req: Request, res: CustomResponse) => { | ||||||||||||||||||||||
| export const updateRequestBeforeAcknowledgedController = async (req: Request, res: CustomResponse, next: NextFunction) => { | ||||||||||||||||||||||
|
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. 🛠️ Refactor suggestion Updated function signature with missing JSDoc. The function signature has been updated to include the Update the JSDoc comment to include the /**
* Processes update requests before acknowledgment based on type.
*
* @param {Request} req - The request object.
* @param {CustomResponse} res - The response object.
+ * @param {NextFunction} next - The next middleware function.
* @returns {Promise<void>} Resolves or sends an error for invalid types.
*/
export const updateRequestBeforeAcknowledgedController = async (req: Request, res: CustomResponse, next: NextFunction) => {📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
| const type = req.body.type; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| switch(type){ | ||||||||||||||||||||||
| case REQUEST_TYPE.OOO: | ||||||||||||||||||||||
| await acknowledgeOooRequest(req as AcknowledgeOooRequest, res as OooRequestResponse, next); | ||||||||||||||||||||||
| break; | ||||||||||||||||||||||
| case REQUEST_TYPE.ONBOARDING: | ||||||||||||||||||||||
| await updateOnboardingExtensionRequestController(req as UpdateOnboardingExtensionRequest, res as OnboardingExtensionResponse); | ||||||||||||||||||||||
| break; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import joi from "joi"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { NextFunction } from "express"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { REQUEST_STATE, REQUEST_TYPE } from "../../constants/requests"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { OooRequestCreateRequest, OooRequestResponse } from "../../types/oooRequest"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { AcknowledgeOooRequest, OooRequestCreateRequest, OooRequestResponse } from "../../types/oooRequest"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const createOooStatusRequestValidator = async ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| req: OooRequestCreateRequest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -38,3 +38,46 @@ export const createOooStatusRequestValidator = async ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await schema.validateAsync(req.body, { abortEarly: false }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const schema = joi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .object() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .strict() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .keys({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| comment: joi.string().optional() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .messages({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "string.empty": "comment cannot be empty", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| status: joi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .string() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .valid(REQUEST_STATE.APPROVED, REQUEST_STATE.REJECTED) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .required() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .messages({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "any.only": "status must be APPROVED or REJECTED", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: joi.string().equal(REQUEST_TYPE.OOO).required().messages({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "type.any": "type is required", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Middleware to validate the acknowledge Out-Of-Office (OOO) request payload. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {AcknowledgeOooRequest} req - The request object containing the body to be validated. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {OooRequestResponse} res - The response object used to send error responses if validation fails. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {NextFunction} next - The next middleware function to call if validation succeeds. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @returns {Promise<void>} Resolves or sends errors. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const acknowledgeOooRequest = async ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| req: AcknowledgeOooRequest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| res: OooRequestResponse, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| next: NextFunction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): Promise<void> => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await schema.validateAsync(req.body, { abortEarly: false }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| next(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const errorMessages = error.details.map((detail:{message: string}) => detail.message); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.error(`Error while validating request payload : ${errorMessages}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return res.boom.badRequest(errorMessages); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+70
to
+83
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. Missing logger import. The middleware uses Add the missing import at the top of the file: import joi from "joi";
import { NextFunction } from "express";
import { REQUEST_STATE, REQUEST_TYPE } from "../../constants/requests";
import { AcknowledgeOooRequest, OooRequestCreateRequest, OooRequestResponse } from "../../types/oooRequest";
+import logger from "../../utils/logger";📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,8 @@ | ||||||||||||||||||||||||
| import joi from "joi"; | ||||||||||||||||||||||||
| import { NextFunction } from "express"; | ||||||||||||||||||||||||
| import { REQUEST_STATE, REQUEST_TYPE } from "../../constants/requests"; | ||||||||||||||||||||||||
| import { OooRequestCreateRequest, OooRequestResponse } from "../../types/oooRequest"; | ||||||||||||||||||||||||
| import { createOooStatusRequestValidator } from "./oooRequests"; | ||||||||||||||||||||||||
| import { AcknowledgeOooRequest, OooRequestCreateRequest, OooRequestResponse } from "../../types/oooRequest"; | ||||||||||||||||||||||||
| import { acknowledgeOooRequest, createOooStatusRequestValidator } from "./oooRequests"; | ||||||||||||||||||||||||
| import { createExtensionRequestValidator } from "./extensionRequestsv2"; | ||||||||||||||||||||||||
| import {createTaskRequestValidator} from "./taskRequests"; | ||||||||||||||||||||||||
| import { ExtensionRequestRequest, ExtensionRequestResponse } from "../../types/extensionRequests"; | ||||||||||||||||||||||||
|
|
@@ -125,18 +125,24 @@ export const getRequestsMiddleware = async (req: OooRequestCreateRequest, res: O | |||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * Validates update requests based on their type. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * @param {UpdateOnboardingExtensionRequest} req - Request object. | ||||||||||||||||||||||||
| * @param {UpdateOnboardingExtensionRequest | AcknowledgeOooRequest} req - Request object. | ||||||||||||||||||||||||
| * @param {CustomResponse} res - Response object. | ||||||||||||||||||||||||
| * @param {NextFunction} next - Next middleware if valid. | ||||||||||||||||||||||||
| * @returns {Promise<void>} Resolves or sends errors. | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| export const updateRequestValidator = async ( | ||||||||||||||||||||||||
| req: UpdateOnboardingExtensionRequest, | ||||||||||||||||||||||||
| req: UpdateOnboardingExtensionRequest | AcknowledgeOooRequest, | ||||||||||||||||||||||||
| res: CustomResponse, | ||||||||||||||||||||||||
| next: NextFunction | ||||||||||||||||||||||||
| ): Promise<void> => { | ||||||||||||||||||||||||
| const type = req.body.type; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| switch (type) { | ||||||||||||||||||||||||
| case REQUEST_TYPE.OOO: | ||||||||||||||||||||||||
| await acknowledgeOooRequest( | ||||||||||||||||||||||||
| req, | ||||||||||||||||||||||||
| res as OooRequestResponse, next); | ||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||
|
Comment on lines
+141
to
+145
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. 🧹 Nitpick (assertive) OOO request handling integration looks good, minor formatting issue. The OOO request case is properly integrated into the validator switch statement, but there's inconsistent spacing after the comma. Improve formatting consistency: case REQUEST_TYPE.OOO:
await acknowledgeOooRequest(
req,
- res as OooRequestResponse, next);
+ res as OooRequestResponse,
+ next);
break;📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
| case REQUEST_TYPE.ONBOARDING: | ||||||||||||||||||||||||
| await updateOnboardingExtensionRequestValidator( | ||||||||||||||||||||||||
| req, | ||||||||||||||||||||||||
|
|
@@ -145,4 +151,4 @@ export const updateRequestValidator = async ( | |||||||||||||||||||||||
| default: | ||||||||||||||||||||||||
| return res.boom.badRequest("Invalid type"); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REQUEST_DOES_NOT_EXIST, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from "../constants/requests"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { getUserId } from "../utils/users"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { NotFound } from "http-errors"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const SIZE = 5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const createRequest = async (body: any) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -69,6 +70,21 @@ export const updateRequest = async (id: string, body: any, lastModifiedBy: strin | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const getRequestById = async (id: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const requestDoc = await requestModel.doc(id).get(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!requestDoc.exists) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new NotFound(REQUEST_DOES_NOT_EXIST); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return requestDoc.data(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.error(ERROR_WHILE_FETCHING_REQUEST, error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+73
to
+86
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. 🧹 Nitpick (assertive) Well-implemented getRequestById function. The function correctly retrieves a request by ID and returns appropriate errors when the document doesn't exist. The error handling follows the established pattern in the codebase. Consider adding JSDoc documentation to clarify the function's purpose and parameters: +/**
+ * Retrieves a request document by its ID
+ * @param {string} id - The ID of the request to retrieve
+ * @returns {Promise<any>} The request document data
+ * @throws {NotFound} When the request document doesn't exist
+ */
export const getRequestById = async (id: string) => {
try {
const requestDoc = await requestModel.doc(id).get();
if (!requestDoc.exists) {
throw new NotFound(REQUEST_DOES_NOT_EXIST);
}
return requestDoc.data();
} catch (error) {
logger.error(ERROR_WHILE_FETCHING_REQUEST, error);
throw error;
}
};📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const getRequests = async (query: any) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let { id, type, requestedBy, state, prev, next, page, size = SIZE } = query; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const dev = query.dev === "true"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,12 +5,22 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REQUEST_LOG_TYPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REQUEST_STATE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| USER_STATUS_NOT_FOUND, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REQUEST_TYPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REQUEST_ALREADY_APPROVED, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REQUEST_ALREADY_REJECTED, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REQUEST_APPROVED_SUCCESSFULLY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REQUEST_REJECTED_SUCCESSFULLY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| INVALID_REQUEST_TYPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from "../constants/requests"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { userState } from "../constants/userStatus"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { createRequest } from "../models/requests"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { createRequest, getRequestById } from "../models/requests"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { OooStatusRequest, OooStatusRequestBody } from "../types/oooRequest"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { UserStatus } from "../types/userStatus"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { addLog } from "./logService"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { BadRequest, Conflict } from "http-errors"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { updateRequest } from "../models/requests"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { AcknowledgeOooRequestBody } from "../types/oooRequest"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { addFutureStatus } from "../models/userStatus"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Validates the user status. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -93,3 +103,101 @@ export const createOooRequest = async ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Validates an Out-Of-Office (OOO) acknowledge request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {string} requestId - The unique identifier of the request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {string} requestType - The type of the request (expected to be 'OOO'). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {string} requestStatus - The current status of the request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @throws {Error} Throws an error if an issue occurs during validation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const validateOooAcknowledgeRequest = async ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestType: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestStatus: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+115
to
+118
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. 🧹 Nitpick (assertive)
-export const validateOooAcknowledgeRequest = async (
+export const validateOooAcknowledgeRequest = (📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (requestType !== REQUEST_TYPE.OOO) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new BadRequest(INVALID_REQUEST_TYPE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (requestStatus === REQUEST_STATE.APPROVED) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Conflict(REQUEST_ALREADY_APPROVED); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (requestStatus === REQUEST_STATE.REJECTED) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Conflict(REQUEST_ALREADY_REJECTED); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.error("Error while validating OOO acknowledge request", error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+107
to
+137
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. 🧹 Nitpick (assertive) JSDoc parameters don’t match implementation The comment lists Keeping docs accurate prevents false assumptions: - * @param {string} requestId - The unique identifier of the request.
- * @param {string} requestType - The type of the request (expected to be 'OOO').
- * @param {string} requestStatus - The current status of the request.
+ * @param {string} requestType - The type of the request (expected to be 'OOO').
+ * @param {string} requestStatus - The current status of the request.📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Acknowledges an Out-of-Office (OOO) request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {string} requestId - The ID of the OOO request to acknowledge. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {AcknowledgeOooRequestBody} body - The acknowledgement body containing acknowledging details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {string} superUserId - The unique identifier of the superuser user. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @returns {Promise<object>} The acknowledged OOO request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @throws {Error} Throws an error if an issue occurs during acknowledgment process. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const acknowledgeOooRequest = async ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestId: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: AcknowledgeOooRequestBody, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| superUserId: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const requestData = await getRequestById(requestId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await validateOooAcknowledgeRequest(requestData.type, requestData.status); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const requestResult = await updateRequest(requestId, body, superUserId, REQUEST_TYPE.OOO); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ("error" in requestResult) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new BadRequest(requestResult.error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [acknowledgeLogType, returnMessage] = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestResult.status === REQUEST_STATE.APPROVED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? [REQUEST_LOG_TYPE.REQUEST_APPROVED, REQUEST_APPROVED_SUCCESSFULLY] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : [REQUEST_LOG_TYPE.REQUEST_REJECTED, REQUEST_REJECTED_SUCCESSFULLY]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const requestLog = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: acknowledgeLogType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| meta: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| action: LOG_ACTION.UPDATE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| userId: superUserId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: requestResult, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await addLog(requestLog.type, requestLog.meta, requestLog.body); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (requestResult.status === REQUEST_STATE.APPROVED) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await addFutureStatus({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| state: REQUEST_TYPE.OOO, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from: requestData.from, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| endsOn: requestData.until, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| userId: requestData.userId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| message: body.comment, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| message: returnMessage, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: requestResult.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...requestResult, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+148
to
+199
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. 🧹 Nitpick (assertive) Potential race: request data may change between fetch and update Between calling If the underlying data store supports atomic conditional updates (Firestore transaction, SQL |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.error("Error while acknowledging OOO request", error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Avoid feature-flag sprawl in controller layer
The early return gated by
devquery param (?dev=true) spreads flag logic into controllers. Prefer feature-flag middleware (or config switch) so the controller focuses only on domain logic:Moving this behind a dedicated middleware keeps controllers clean and prevents accidental flag omission on other routes.
📝 Committable suggestion