Merge branch 'dev' into staging

This commit is contained in:
Max S 2024-09-20 13:12:55 +02:00
commit ce0ba510e5
8 changed files with 103 additions and 19 deletions

View File

@ -59,7 +59,7 @@
"file-type-checker": "^1.0.8",
"fp-ts": "^2.16.1",
"jsonwebtoken": "^9.0.0",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.160",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.167",
"module-alias": "^2.2.2",
"monocle-ts": "^2.3.13",
"multer": "^1.4.5-lts.1",

View File

@ -4,16 +4,16 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
import { Service } from "typedi";
import DocumentsNotaryService from "@Services/notary/DocumentsNotaryService/DocumentsNotaryService";
import { Prisma } from "@prisma/client";
import { DocumentNotary } from "le-coffre-resources/dist/Notary";
import authHandler from "@App/middlewares/AuthHandler";
import DocumentNotary from "le-coffre-resources/dist/Notary/DocumentNotary";
// import NotificationBuilder from "@Common/notifications/NotificationBuilder";
@Controller()
@Service()
export default class DocumentsNotaryController extends ApiController {
constructor(
private documentsNotaryService: DocumentsNotaryService,
) {
constructor(private documentsNotaryService: DocumentsNotaryService) {
super();
}

View File

@ -0,0 +1,54 @@
import authHandler from "@App/middlewares/AuthHandler";
import ApiController from "@Common/system/controller-pattern/ApiController";
import { Controller, Get } from "@ControllerPattern/index";
import { EDocumentNotaryStatus } from "@prisma/client";
import FilesNotaryService from "@Services/common/FilesNotaryService/FilesNotaryService";
import DocumentsNotaryService from "@Services/notary/DocumentsNotaryService/DocumentsNotaryService";
import { Request, Response } from "express";
import { Service } from "typedi";
@Controller()
@Service()
export default class FilesNotaryController extends ApiController {
constructor(private filesNotaryService: FilesNotaryService, private documentsNotaryService: DocumentsNotaryService) {
super();
}
/**
* @description Get a specific File by uid
*/
@Get("/api/v1/customer/files-notary/:filesNotaryUid/documents-notary/:documentsNotaryUid/download", [authHandler])
protected async download(req: Request, response: Response) {
const filesNotaryUid = req.params["filesNotaryUid"];
const documentsNotaryUid = req.params["documentsNotaryUid"];
if (!filesNotaryUid) {
this.httpBadRequest(response, "filesNotaryUid not found");
return;
}
if (!documentsNotaryUid) {
this.httpBadRequest(response, "documentsNotaryUid not found");
return;
}
try {
const fileInfo = await this.filesNotaryService.download(filesNotaryUid);
if (!fileInfo) {
this.httpNotFoundRequest(response, "file not found");
return;
}
response.setHeader("Content-Type", fileInfo.file.mimetype);
response.setHeader("Content-Disposition", `inline; filename=${encodeURIComponent(fileInfo.file.file_name)}`);
await this.documentsNotaryService.changeStatus(documentsNotaryUid, EDocumentNotaryStatus.DOWNLOADED);
this.httpSuccess(response, fileInfo.buffer);
} catch (error) {
this.httpInternalError(response, error);
return;
}
}
}

View File

@ -57,7 +57,9 @@ import NotesController from "./api/customer/NotesController";
import MailchimpController from "./api/notary/MailchimpController";
import DocumentsReminderController from "./api/notary/DocumentsReminderController";
import DocumentsNotaryController from "./api/notary/DocumentsNotaryController";
import DocumentsNotaryControllerCustomer from "./api/customer/DocumentsNotaryController";
import FilesNotaryController from "./api/notary/FilesNotaryController";
import FilesNotaryControllerCustomer from "./api/customer/FilesNotaryController";
/**
* @description This allow to declare all controllers used in the application
@ -124,5 +126,7 @@ export default {
Container.get(DocumentsReminderController);
Container.get(DocumentsNotaryController);
Container.get(FilesNotaryController);
Container.get(DocumentsNotaryControllerCustomer);
Container.get(FilesNotaryControllerCustomer);
},
};

View File

@ -0,0 +1,5 @@
-- CreateEnum
CREATE TYPE "EDocumentNotaryStatus" AS ENUM ('SENT', 'DOWNLOADED');
-- AlterTable
ALTER TABLE "documents_notary" ADD COLUMN "document_status" "EDocumentNotaryStatus" NOT NULL DEFAULT 'SENT';

View File

@ -238,6 +238,7 @@ model DocumentsNotary {
customer Customers @relation(fields: [customer_uid], references: [uid], onDelete: Cascade)
customer_uid String @db.VarChar(255)
document String @default("") @db.VarChar(255)
document_status EDocumentNotaryStatus @default(SENT)
@@map("documents_notary")
}
@ -558,3 +559,8 @@ enum EAnchoringStatus {
VERIFYING_ON_CHAIN
ABANDONED
}
enum EDocumentNotaryStatus {
SENT
DOWNLOADED
}

View File

@ -1,7 +1,7 @@
import Database from "@Common/databases/database";
import BaseRepository from "@Repositories/BaseRepository";
import { Service } from "typedi";
import { DocumentsNotary, Prisma } from "@prisma/client";
import { DocumentsNotary, EDocumentNotaryStatus, Prisma } from "@prisma/client";
import { DocumentNotary } from "le-coffre-resources/dist/Notary";
@Service()
@ -99,4 +99,15 @@ export default class DocumentsNotaryRepository extends BaseRepository {
include: { files: true },
});
}
public async changeStatus(uid: string, status: EDocumentNotaryStatus) {
return this.model.update({
where: {
uid: uid,
},
data: {
document_status: status,
},
});
}
}

View File

@ -1,11 +1,11 @@
import { DocumentsNotary, Prisma } from "@prisma/client";
import { DocumentsNotary, EDocumentNotaryStatus, Prisma } from "@prisma/client";
import { Document, DocumentNotary } from "le-coffre-resources/dist/Notary";
import DocumentsNotaryRepository from "@Repositories/DocumentsNotaryRepository";
import BaseService from "@Services/BaseService";
import { Service } from "typedi";
@Service()
export default class DocumentsService extends BaseService {
export default class DocumentsNotaryService extends BaseService {
constructor(private documentsNotaryRepository: DocumentsNotaryRepository) {
super();
}
@ -58,4 +58,8 @@ export default class DocumentsService extends BaseService {
public async getByUidWithOffice(uid: string) {
return this.documentsNotaryRepository.findOneByUidWithOffice(uid);
}
public changeStatus(uid: string, status: EDocumentNotaryStatus) {
return this.documentsNotaryRepository.changeStatus(uid, status);
}
}