🐛 Fixing documents get

This commit is contained in:
Maxime Lalo 2023-08-01 15:35:40 +02:00
parent 77f24af33c
commit 7777bc6e91

View File

@ -1,14 +1,14 @@
import { Response, Request } from "express";
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
import ApiController from "@Common/system/controller-pattern/ApiController";
import { Service } from "typedi";
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
import { Documents, Prisma } from "@prisma/client";
import { Document } from "le-coffre-resources/dist/SuperAdmin";
import { validateOrReject } from "class-validator";
import authHandler from "@App/middlewares/AuthHandler";
import ruleHandler from "@App/middlewares/RulesHandler";
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
import ruleHandler from "@App/middlewares/RulesHandler";
import ApiController from "@Common/system/controller-pattern/ApiController";
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
import { Documents, Prisma } from "@prisma/client";
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
import { validateOrReject } from "class-validator";
import { Request, Response } from "express";
import { Document } from "le-coffre-resources/dist/SuperAdmin";
import { Service } from "typedi";
@Controller()
@Service()
@ -30,12 +30,18 @@ export default class DocumentsController extends ApiController {
query = JSON.parse(req.query["q"] as string);
}
const officeId: string = req.body.user.office_Id;
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
if(!query.where) query.where = { document_type : {office: officeWhereInput}};
query.where.document_type!.office = officeWhereInput;
// query.where.document_type!.office = officeWhereInput;
//call service to get prisma entity
const documentEntities = await this.documentsService.get(query);
console.log(documentEntities);
//Hydrate ressource with prisma entity
const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });