this.router.get( "/quotation", verifyRoles([rolesStr.SUPERVISOR, rolesStr["BRANCH…
- User
this._router.get( "/quotation", verifyRoles([rolesStr.SUPERVISOR, rolesStr["BRANCH STATISTICIAN"]]), this._controller.getQuotations ); the above route handler is used by both supervisor and branch statistician roles to fetch quotations. And the below code is the function used to fetch quotations to the route async getQuotations(req: Request, res: Response, next: NextFunction) { try { const query: any = req.query; const 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: { quotations: { where: { status: { not: QuotationStatus.SUPERVISOR_APPROVED, }, }, }, item: { include: { translation: true, itemMeasurements: true, }, }, }, }, questionnaireRegionStatus: { where: regionalStatusFilter, }, }, });
code - Assistant
To fetch only quotes that have been SUPERVISOR_APPROVED by a supervisor for the branch statistician role, we need to modify the following code block:
typescript - User
but the above getQuotations functions should also work for superviors aswell to fetch quotations created by data collectors. then a supervisor will either reject or approve them, then branch stastisian can fetch the supervisor approved quotations but should not be able to fetch the supervisor rejected quotations
- Assistant
- User
Oh but supervisors need to only fetch quotations from data collectors assigned to them (their region)
- Assistant
In that case, we can modify the
getQuotationsfunction to fetch only quotations for data collectors assigned to the supervisor. We can add a filter to thecollectorrelation to only fetch quotations where the collector'smarketplace.regionCodematches the supervisor'suserRegionCode.Here's the updated code block:
typescript