async getQuotations(req: Request, res: Response, next: NextFunction) { try { const…
- User
async getQuotations(req: Request, res: Response, next: NextFunction) { try { const query: any = req.query; let regionCodeOrCodes = await getRegionCodeOrCodes(req.user!); const regionalStatusFilter = getQuestionnaireRegionalStatusFilter(regionCodeOrCodes); const questionnaire = await prisma.questionnaire.findFirst({ orderBy: [{ startDate: "desc" }], where: { designatedRole: rolesNum["DATA COLLECTOR"], approved: true, disabled: false, endDate: { gte: addDays(new Date(), -5), }, startDate: { lte: new Date(), }, isDraft: false, }, include: { questionnaireItems: { where: { disabled: false, }, include: { item: { include: { translation: true, itemMeasurements: true, }, }, }, }, questionnaireRegionStatus: { where: regionalStatusFilter, }, }, }); const datacollectors = await prisma.user.findMany({ where: req.user?.role === rolesNum.SUPERVISOR ? { supervisorId: req.user?.id, } : { marketplace: { branchCode: req.user?.branchCode } }, }); if ( req.user?.role === rolesNum.SUPERVISOR && (!datacollectors || datacollectors.length < 1) ) { return res .status(httpStatusCodes.NOT_FOUND) .json( new ResponseJSON( "Supervisor is not assigned any data collectors", true, httpStatusCodes.NOT_FOUND ) ); }
if (!questionnaire) { return res .status(httpStatusCodes.NOT_FOUND) .json( new ResponseJSON( "Not Questionnaires active right now", true, httpStatusCodes.NOT_FOUND ) ); } if (req.user?.role === rolesNum.SUPERVISOR) { regionCodeOrCodes = datacollectors.map((el) => el.id); } else if (req.user?.role === rolesNum["BRANCH STATISTICIAN"]) { const supervisors = await prisma.user.findMany({ where: { supervisorId: req.user?.id, }, }); regionCodeOrCodes = supervisors.map((el) => el.id); query.status = QuotationStatus.SUPERVISOR_APPROVED; } const result = await prisma.quotation.findMany({ where: { questionnaireId: questionnaire?.id, collectorId: { in: datacollectors.map((el) => el.id), }, ...query, }, include: { collector: { select: { fullName: true, id: true, marketplaceCode: true, }, }, quotes: { include: { quoteComments: true, }, }, unfoundQuotes: { include: { quoteComments: true, }, }, }, }); return res .status(httpStatusCodes.OK) .json(new ResponseJSON("Success", false, httpStatusCodes.OK, result)); } catch (error: any) { console.log("Error --- ", error); next( apiErrorHandler( error, req, errorMessages.INTERNAL_SERVER, httpStatusCodes.INTERNAL_SERVER ) ); }} will the above code fetch only supervisor_approved quotations to branch statsticians and show rejected ones
- Assistant
No, the above code will not fetch only
supervisor_approvedquotations for branch statisticians. Thequery.statusparameter is only set toQuotationStatus.SUPERVISOR_APPROVEDif the user's role isBRANCH_STATISTICIAN, which will filter the quotations by that status. However, there is no filtering for rejected quotations in this code. - User
so what status quotations will branch statistician see
- Assistant
The branch statistician will see all quotations that meet the following conditions:
- The quotations belong to the active questionnaire
- The data collector who created the quotation is assigned to the branch statistician or any of their assigned supervisors
- The quotation status matches any value in the
query.statusparameter (if it is set)
Therefore, the branch statistician will see all quotations that are either
PENDING,APPROVED,REJECTED, or any other custom status that may be defined in theQuotationStatusenum (depending on the value ofquery.status).