Added refused_reason to update document + check if file on delete document
This commit is contained in:
parent
9d12381ba8
commit
9a26118839
@ -81,13 +81,13 @@ export default class DocumentsController extends ApiController {
|
||||
}
|
||||
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const prismaEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
||||
const prismaEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity, req.body.refused_reason);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(prismaEntityUpdated, { strategy: "excludeAll" });
|
||||
|
@ -38,8 +38,8 @@ export default class DocumentsService extends BaseService {
|
||||
* @description : Modify a document
|
||||
* @throws {Error} If document cannot be modified
|
||||
*/
|
||||
public async update(uid: string, document: Document): Promise<Documents> {
|
||||
return this.documentsRepository.update(uid, document);
|
||||
public async update(uid: string, document: Document, refused_reason?: string): Promise<Documents> {
|
||||
return this.documentsRepository.update(uid, document, refused_reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,6 +55,12 @@ export default class DocumentsService extends BaseService {
|
||||
* @throws {Error} If document cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: any) {
|
||||
const documentEntity = await this.documentsRepository.findOneByUid(uid, { office_folder_has_customers: true });
|
||||
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||
|
||||
if (document.files && document.files.length !== 0) {
|
||||
throw new Error("Can't delete a document with file");
|
||||
}
|
||||
return this.documentsRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user