Merge branch 'dev' into staging
This commit is contained in:
commit
579dc15c96
@ -9,6 +9,7 @@ import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import customerHandler from "@App/middlewares/OfficeMembershipHandlers/CustomerHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -78,7 +79,7 @@ export default class CustomersController extends ApiController {
|
||||
/**
|
||||
* @description Modify a specific customer by uid
|
||||
*/
|
||||
@Put("/api/v1/admin/customers/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
@Put("/api/v1/admin/customers/:uid", [authHandler, roleHandler, ruleHandler, customerHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
@ -119,7 +120,7 @@ export default class CustomersController extends ApiController {
|
||||
/**
|
||||
* @description Get a specific customer by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/customers/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
@Get("/api/v1/admin/customers/:uid", [authHandler, roleHandler, ruleHandler, customerHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
|
@ -3,7 +3,7 @@ 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/admin/DocumentsService/DocumentsService";
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import { Documents, EDocumentStatus, Prisma } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/Admin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
@ -31,8 +31,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
|
||||
@ -104,7 +104,55 @@ export default class DocumentsController extends ApiController {
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity, req.body.refused_reason);
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific document
|
||||
*/
|
||||
@Put("/api/v1/notary/documents/:uid/refuse", [authHandler, ruleHandler, documentHandler])
|
||||
protected async refuseDocument(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentFound = await this.documentsService.getByUid(uid, {
|
||||
files: true,
|
||||
});
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(documentFound);
|
||||
|
||||
// Status to refuse
|
||||
documentEntity.document_status = EDocumentStatus.REFUSED;
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityUpdated: Documents = await this.documentsService.refuse(uid, documentEntity, req.body.refused_reason);
|
||||
|
||||
//create email for asked document
|
||||
// this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
|
||||
// this.notificationBuilder.sendDocumentAnchoredNotificatiom(documentEntityUpdated);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||
|
@ -58,10 +58,10 @@ export default class OfficeFoldersController extends ApiController {
|
||||
};
|
||||
}
|
||||
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { office: officeWhereInput};
|
||||
query.where.office = officeWhereInput;
|
||||
const userId: string = req.body.user.userId;
|
||||
if (query.where?.stakeholders) delete query.where.stakeholders;
|
||||
const officeFoldersWhereInput: Prisma.OfficeFoldersWhereInput = { ...query.where, stakeholders: { some: { uid: userId } } };
|
||||
query.where = officeFoldersWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);
|
||||
|
@ -8,6 +8,7 @@ import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import customerHandler from "@App/middlewares/OfficeMembershipHandlers/CustomerHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -76,7 +77,7 @@ export default class CustomersController extends ApiController {
|
||||
/**
|
||||
* @description Modify a specific customer by uid
|
||||
*/
|
||||
@Put("/api/v1/notary/customers/:uid", [authHandler, ruleHandler])
|
||||
@Put("/api/v1/notary/customers/:uid", [authHandler, ruleHandler, customerHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
@ -117,7 +118,7 @@ export default class CustomersController extends ApiController {
|
||||
/**
|
||||
* @description Get a specific customer by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/customers/:uid", [authHandler, ruleHandler])
|
||||
@Get("/api/v1/notary/customers/:uid", [authHandler, ruleHandler, customerHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
|
@ -3,7 +3,7 @@ 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/notary/DocumentsService/DocumentsService";
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import { Documents, EDocumentStatus, Prisma } from "@prisma/client";
|
||||
import { Document, OfficeFolder } from "le-coffre-resources/dist/Notary";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
@ -127,7 +127,55 @@ export default class DocumentsController extends ApiController {
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity, req.body.refused_reason);
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
||||
|
||||
//create email for asked document
|
||||
// this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
|
||||
// this.notificationBuilder.sendDocumentAnchoredNotificatiom(documentEntityUpdated);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific document
|
||||
*/
|
||||
@Put("/api/v1/notary/documents/:uid/refuse", [authHandler, ruleHandler, documentHandler])
|
||||
protected async refuseDocument(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentFound = await this.documentsService.getByUid(uid, {
|
||||
files: true,
|
||||
});
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(documentFound);
|
||||
|
||||
// Status to refuse
|
||||
documentEntity.document_status = EDocumentStatus.REFUSED;
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityUpdated: Documents = await this.documentsService.refuse(uid, documentEntity, req.body.refused_reason);
|
||||
|
||||
//create email for asked document
|
||||
// this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
|
||||
|
@ -2,7 +2,7 @@ import { Response, Request } from "express";
|
||||
import { Controller, Get, Post } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Notary";
|
||||
import { Document, OfficeFolder } from "le-coffre-resources/dist/Notary";
|
||||
import { getFolderHashes } from "@Common/optics/notary";
|
||||
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
|
||||
import OfficeFolderAnchorsRepository from "@Repositories/OfficeFolderAnchorsRepository";
|
||||
@ -136,6 +136,18 @@ export default class OfficeFoldersController extends ApiController {
|
||||
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound, { strategy: "excludeAll" });
|
||||
|
||||
// Check if every document is validated in a folder
|
||||
const documents = officeFolder.documents ?? [];
|
||||
const documentsValidated = documents.filter((document) => {
|
||||
let documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
|
||||
return documentHydrated.document_status === "VALIDATED";
|
||||
});
|
||||
|
||||
if (documentsValidated.length !== documents.length && documents.length !== 0) {
|
||||
this.httpBadRequest(response, "Cannot anchor a folder with non validated documents");
|
||||
return;
|
||||
}
|
||||
|
||||
const folderHashes = getFolderHashes(officeFolder);
|
||||
|
||||
if (folderHashes.length === 0) {
|
||||
|
@ -9,6 +9,7 @@ import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import customerHandler from "@App/middlewares/OfficeMembershipHandlers/CustomerHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -78,7 +79,7 @@ export default class CustomersController extends ApiController {
|
||||
/**
|
||||
* @description Modify a specific customer by uid
|
||||
*/
|
||||
@Put("/api/v1/super-admin/customers/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
@Put("/api/v1/super-admin/customers/:uid", [authHandler, roleHandler, ruleHandler, customerHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
@ -119,7 +120,7 @@ export default class CustomersController extends ApiController {
|
||||
/**
|
||||
* @description Get a specific customer by uid
|
||||
*/
|
||||
@Get("/api/v1/super-admin/customers/:uid", [authHandler, roleHandler, ruleHandler])
|
||||
@Get("/api/v1/super-admin/customers/:uid", [authHandler, roleHandler, ruleHandler, customerHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
|
@ -4,7 +4,7 @@ import roleHandler from "@App/middlewares/RolesHandler";
|
||||
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 { Documents, EDocumentStatus, Prisma } from "@prisma/client";
|
||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import { Request, Response } from "express";
|
||||
@ -32,11 +32,11 @@ export default class DocumentsController extends ApiController {
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId };
|
||||
|
||||
if(!query.where) query.where = { document_type : {office: officeWhereInput}};
|
||||
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
|
||||
|
||||
@ -108,7 +108,55 @@ export default class DocumentsController extends ApiController {
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity, req.body.refused_reason);
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific document
|
||||
*/
|
||||
@Put("/api/v1/notary/documents/:uid/refuse", [authHandler, ruleHandler, documentHandler])
|
||||
protected async refuseDocument(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentFound = await this.documentsService.getByUid(uid, {
|
||||
files: true,
|
||||
});
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(documentFound);
|
||||
|
||||
// Status to refuse
|
||||
documentEntity.document_status = EDocumentStatus.REFUSED;
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityUpdated: Documents = await this.documentsService.refuse(uid, documentEntity, req.body.refused_reason);
|
||||
|
||||
//create email for asked document
|
||||
// this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
|
||||
// this.notificationBuilder.sendDocumentAnchoredNotificatiom(documentEntityUpdated);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||
|
@ -44,12 +44,10 @@ export default class OfficeFoldersController extends ApiController {
|
||||
{
|
||||
customers: {
|
||||
some: {
|
||||
contact: {
|
||||
OR: [
|
||||
{ first_name: { contains: filter, mode: "insensitive" } },
|
||||
{ last_name: { contains: filter, mode: "insensitive" } },
|
||||
],
|
||||
},
|
||||
OR: [
|
||||
{ contact: { first_name: { contains: filter, mode: "insensitive" } } },
|
||||
{ contact: { last_name: { contains: filter, mode: "insensitive" } } },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -57,10 +55,11 @@ export default class OfficeFoldersController extends ApiController {
|
||||
},
|
||||
};
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId };
|
||||
if (!query.where) query.where = { office: officeWhereInput };
|
||||
query.where.office = officeWhereInput;
|
||||
|
||||
const userId: string = req.body.user.userId;
|
||||
if (query.where?.stakeholders) delete query.where.stakeholders;
|
||||
const officeFoldersWhereInput: Prisma.OfficeFoldersWhereInput = { ...query.where, stakeholders: { some: { uid: userId } } };
|
||||
query.where = officeFoldersWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);
|
||||
|
@ -109,24 +109,25 @@ export default class UsersController extends ApiController {
|
||||
//init IUser resource with request body values
|
||||
const userEntity = User.hydrate<User>(req.body);
|
||||
|
||||
if(userEntity.role) {
|
||||
if (userEntity.role) {
|
||||
const role = await this.roleService.getByUid(userEntity.role.uid!);
|
||||
if(!role) {
|
||||
if (!role) {
|
||||
this.httpBadRequest(response, "Role not found");
|
||||
return;
|
||||
}
|
||||
if (role.name === "super-admin" || userFound.role.name === "super-admin" ) {
|
||||
if (role.name === "super-admin" || userFound.role.name === "super-admin") {
|
||||
this.httpBadRequest(response, "Cannot assign or remove super-admin role");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(userEntity.office_role) {
|
||||
if (userEntity.office_role) {
|
||||
const officeRole = await this.officeRoleService.getByUid(userEntity.office_role.uid!);
|
||||
if(!officeRole) {
|
||||
if (!officeRole) {
|
||||
this.httpBadRequest(response, "Office role not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (officeRole.office_uid != userFound.office_uid) {
|
||||
this.httpBadRequest(response, "Cannot assign an office role from another office");
|
||||
return;
|
||||
|
@ -0,0 +1,28 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
import CustomersService from "@Services/super-admin/CustomersService/CustomersService";
|
||||
|
||||
export default async function customerHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
const officeId = req.body.user.office_Id;
|
||||
const uid = req.path && req.path.split("/")[5];
|
||||
|
||||
if (uid) {
|
||||
const customerService = Container.get(CustomersService);
|
||||
const customer = await customerService.get({where:{AND: [{uid: uid}, {office_folders: {some: {office_uid: officeId}}}]}});
|
||||
|
||||
if (!customer[0]) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Customer not found");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
return;
|
||||
}
|
||||
}
|
@ -21,7 +21,6 @@ export default class DocumentsRepository extends BaseRepository {
|
||||
* @description : Find many documents
|
||||
*/
|
||||
public async findMany(query: Prisma.DocumentsFindManyArgs) {
|
||||
|
||||
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
|
||||
return this.model.findMany(query);
|
||||
}
|
||||
@ -96,7 +95,26 @@ export default class DocumentsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Update data of a document
|
||||
*/
|
||||
public async update(uid: string, document: Partial<DocumentCustomer>, refusedReason?: string): Promise<Documents> {
|
||||
public async update(uid: string, document: Partial<DocumentCustomer>): Promise<Documents> {
|
||||
return this.model.update({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
data: {
|
||||
document_status: EDocumentStatus[document.document_status as keyof typeof EDocumentStatus],
|
||||
document_history: {
|
||||
create: {
|
||||
document_status: EDocumentStatus[document.document_status as keyof typeof EDocumentStatus],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update data of a document
|
||||
*/
|
||||
public async refuse(uid: string, document: Partial<DocumentCustomer>, refusedReason?: string): Promise<Documents> {
|
||||
return this.model.update({
|
||||
where: {
|
||||
uid: uid,
|
||||
|
@ -3,10 +3,11 @@ import { Document } from "le-coffre-resources/dist/Admin";
|
||||
import DocumentsRepository from "@Repositories/DocumentsRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
import FilesRepository from "@Repositories/FilesRepository";
|
||||
|
||||
@Service()
|
||||
export default class DocumentsService extends BaseService {
|
||||
constructor(private documentsRepository: DocumentsRepository) {
|
||||
constructor(private documentsRepository: DocumentsRepository, private filesRepository: FilesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
@ -38,8 +39,19 @@ export default class DocumentsService extends BaseService {
|
||||
* @description : Modify a document
|
||||
* @throws {Error} If document cannot be modified
|
||||
*/
|
||||
public async update(uid: string, document: Partial<Document>, refused_reason?: string): Promise<Documents> {
|
||||
return this.documentsRepository.update(uid, document, refused_reason);
|
||||
public async update(uid: string, document: Partial<Document>): Promise<Documents> {
|
||||
return this.documentsRepository.update(uid, document);
|
||||
}
|
||||
|
||||
public async refuse(uid: string, document: Partial<Document>, refused_reason: string): Promise<Documents> {
|
||||
if (document.files) {
|
||||
for (let i = 0; i < document.files.length; i++) {
|
||||
console.log("archiving file", document.files[i]?.uid);
|
||||
await this.filesRepository.deleteKeyAndArchive(document.files[i]?.uid as string);
|
||||
}
|
||||
}
|
||||
|
||||
return this.documentsRepository.refuse(uid, document, refused_reason);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +72,7 @@ export default class AnchoringProofService extends BaseService {
|
||||
*/
|
||||
public async generate(data: AnchoringProofData): Promise<Buffer> {
|
||||
const browser = await puppeteer.launch({
|
||||
headless: true,
|
||||
headless: 'new',
|
||||
args: ["--no-sandbox", "--disable-gpu"],
|
||||
});
|
||||
const page = await browser.newPage();
|
||||
|
@ -3,10 +3,11 @@ import { Document } from "le-coffre-resources/dist/Notary";
|
||||
import DocumentsRepository from "@Repositories/DocumentsRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
import FilesRepository from "@Repositories/FilesRepository";
|
||||
|
||||
@Service()
|
||||
export default class DocumentsService extends BaseService {
|
||||
constructor(private documentsRepository: DocumentsRepository) {
|
||||
constructor(private documentsRepository: DocumentsRepository, private filesRepository: FilesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
@ -38,8 +39,19 @@ export default class DocumentsService extends BaseService {
|
||||
* @description : Modify a document
|
||||
* @throws {Error} If document cannot be modified
|
||||
*/
|
||||
public async update(uid: string, document: Partial<Document>, refused_reason?: string): Promise<Documents> {
|
||||
return this.documentsRepository.update(uid, document, refused_reason);
|
||||
public async update(uid: string, document: Partial<Document>): Promise<Documents> {
|
||||
return this.documentsRepository.update(uid, document);
|
||||
}
|
||||
|
||||
public async refuse(uid: string, document: Partial<Document>, refused_reason: string): Promise<Documents> {
|
||||
if (document.files) {
|
||||
for (let i = 0; i < document.files.length; i++) {
|
||||
console.log("archiving file", document.files[i]?.uid);
|
||||
await this.filesRepository.deleteKeyAndArchive(document.files[i]?.uid as string);
|
||||
}
|
||||
}
|
||||
|
||||
return this.documentsRepository.refuse(uid, document, refused_reason);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,10 +3,11 @@ import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import DocumentsRepository from "@Repositories/DocumentsRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
import FilesRepository from "@Repositories/FilesRepository";
|
||||
|
||||
@Service()
|
||||
export default class DocumentsService extends BaseService {
|
||||
constructor(private documentsRepository: DocumentsRepository) {
|
||||
constructor(private documentsRepository: DocumentsRepository, private filesRepository: FilesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
@ -38,8 +39,19 @@ export default class DocumentsService extends BaseService {
|
||||
* @description : Modify a document
|
||||
* @throws {Error} If document cannot be modified
|
||||
*/
|
||||
public async update(uid: string, document: Partial<Document>, refused_reason?: string): Promise<Documents> {
|
||||
return this.documentsRepository.update(uid, document, refused_reason);
|
||||
public async update(uid: string, document: Partial<Document>): Promise<Documents> {
|
||||
return this.documentsRepository.update(uid, document);
|
||||
}
|
||||
|
||||
public async refuse(uid: string, document: Partial<Document>, refused_reason: string): Promise<Documents> {
|
||||
if (document.files) {
|
||||
for (let i = 0; i < document.files.length; i++) {
|
||||
console.log("archiving file", document.files[i]?.uid);
|
||||
await this.filesRepository.deleteKeyAndArchive(document.files[i]?.uid as string);
|
||||
}
|
||||
}
|
||||
|
||||
return this.documentsRepository.refuse(uid, document, refused_reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,7 +81,7 @@ export default class DocumentsService extends BaseService {
|
||||
* @description : Get a document by uid
|
||||
* @throws {Error} If document cannot be get by uid
|
||||
*/
|
||||
public async getByUidWithFiles(uid: string): Promise<Documents & {files: Files[] | null} | null> {
|
||||
public async getByUidWithFiles(uid: string): Promise<(Documents & { files: Files[] | null }) | null> {
|
||||
return this.documentsRepository.findOneByUidWithFiles(uid);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user