✨ 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 { Service } from "typedi";
|
||||||
import DocumentsService from "@Services/notary/DocumentsService/DocumentsService";
|
import DocumentsService from "@Services/notary/DocumentsService/DocumentsService";
|
||||||
import { Documents, Prisma } from "@prisma/client";
|
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 { validateOrReject } from "class-validator";
|
||||||
import authHandler from "@App/middlewares/AuthHandler";
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||||
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
|
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
|
||||||
import EmailBuilder from "@Common/emails/EmailBuilder";
|
import EmailBuilder from "@Common/emails/EmailBuilder";
|
||||||
|
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
|
||||||
// import NotificationBuilder from "@Common/notifications/NotificationBuilder";
|
// import NotificationBuilder from "@Common/notifications/NotificationBuilder";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
export default class DocumentsController extends ApiController {
|
export default class DocumentsController extends ApiController {
|
||||||
constructor(private documentsService: DocumentsService, private emailBuilder: EmailBuilder) {
|
constructor(
|
||||||
|
private documentsService: DocumentsService,
|
||||||
|
private emailBuilder: EmailBuilder,
|
||||||
|
private officeFoldersService: OfficeFoldersService,
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +65,20 @@ export default class DocumentsController extends ApiController {
|
|||||||
//init Document resource with request body values
|
//init Document resource with request body values
|
||||||
const documentEntity = Document.hydrate<Document>(req.body);
|
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
|
//validate document
|
||||||
await validateOrReject(documentEntity, { groups: ["createDocument"], forbidUnknownValues: false });
|
await validateOrReject(documentEntity, { groups: ["createDocument"], forbidUnknownValues: false });
|
||||||
|
|
||||||
@ -104,8 +123,6 @@ export default class DocumentsController extends ApiController {
|
|||||||
//init Document resource with request body values
|
//init Document resource with request body values
|
||||||
const documentEntity = Document.hydrate<Document>(req.body);
|
const documentEntity = Document.hydrate<Document>(req.body);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//validate document
|
//validate document
|
||||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user