:sparkles add status téléchargé in documents notary table
This commit is contained in:
parent
510fe26f1e
commit
19db483739
@ -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",
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
54
src/app/api/customer/FilesNotaryController.ts
Normal file
54
src/app/api/customer/FilesNotaryController.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
},
|
||||
};
|
||||
|
@ -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';
|
@ -227,17 +227,18 @@ model Documents {
|
||||
}
|
||||
|
||||
model DocumentsNotary {
|
||||
uid String @id @unique @default(uuid())
|
||||
folder OfficeFolders @relation(fields: [folder_uid], references: [uid])
|
||||
folder_uid String @db.VarChar(255)
|
||||
depositor Users @relation(fields: [depositor_uid], references: [uid], onDelete: Cascade)
|
||||
depositor_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
files FilesNotary[]
|
||||
customer Customers @relation(fields: [customer_uid], references: [uid], onDelete: Cascade)
|
||||
customer_uid String @db.VarChar(255)
|
||||
document String @default("") @db.VarChar(255)
|
||||
uid String @id @unique @default(uuid())
|
||||
folder OfficeFolders @relation(fields: [folder_uid], references: [uid])
|
||||
folder_uid String @db.VarChar(255)
|
||||
depositor Users @relation(fields: [depositor_uid], references: [uid], onDelete: Cascade)
|
||||
depositor_uid String @db.VarChar(255)
|
||||
created_at DateTime? @default(now())
|
||||
updated_at DateTime? @updatedAt
|
||||
files FilesNotary[]
|
||||
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
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user