✨ Cannot ask documents on an anchored folder
This commit is contained in:
parent
95bcb05340
commit
2e47e7a820
@ -4,18 +4,23 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DocumentsService from "@Services/notary/DocumentsService/DocumentsService";
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/Notary";
|
||||
import { Document, OfficeFolder } from "le-coffre-resources/dist/Notary";
|
||||
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 EmailBuilder from "@Common/emails/EmailBuilder";
|
||||
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
|
||||
// import NotificationBuilder from "@Common/notifications/NotificationBuilder";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DocumentsController extends ApiController {
|
||||
constructor(private documentsService: DocumentsService, private emailBuilder: EmailBuilder) {
|
||||
constructor(
|
||||
private documentsService: DocumentsService,
|
||||
private emailBuilder: EmailBuilder,
|
||||
private officeFoldersService: OfficeFoldersService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
@ -32,8 +37,8 @@ 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}};
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId };
|
||||
if (!query.where) query.where = { document_type: { office: officeWhereInput } };
|
||||
query.where.document_type!.office = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
@ -60,6 +65,20 @@ export default class DocumentsController extends ApiController {
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
const folder = await this.officeFoldersService.getByUid(documentEntity.folder?.uid!, {
|
||||
folder_anchor: true,
|
||||
});
|
||||
if (!folder) {
|
||||
this.httpBadRequest(response, "Folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
const folderRessource = OfficeFolder.hydrate<OfficeFolder>(folder);
|
||||
if (folderRessource.folder_anchor) {
|
||||
this.httpBadRequest(response, "Cannot ask document on an anchored or anchoring folder");
|
||||
return;
|
||||
}
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["createDocument"], forbidUnknownValues: false });
|
||||
|
||||
@ -104,8 +123,6 @@ export default class DocumentsController extends ApiController {
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user