fix seeder (#39)
This commit is contained in:
commit
56cbdb50b9
@ -4,13 +4,14 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/private-services/FilesService/FilesService";
|
||||
import { Files } from "@prisma/client";
|
||||
import { File } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { File, Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class FilesController extends ApiController {
|
||||
constructor(private filesService: FilesService) {
|
||||
constructor(private filesService: FilesService, private documentService: DocumentsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
@ -58,6 +59,10 @@ export default class FilesController extends ApiController {
|
||||
//call service to get prisma entity
|
||||
const prismaEntityCreated = await this.filesService.create(fileEntity, req.file);
|
||||
|
||||
const document: Document = await this.documentService.getByUid(fileEntity.document!.uid!)
|
||||
document.document_status = "DEPOSITED";
|
||||
await this.documentService.update(document.uid!, document);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const fileEntityCreated = File.hydrate<File>(prismaEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
|
@ -47,6 +47,8 @@ import {
|
||||
|
||||
const uidAddress1: string = randomString();
|
||||
const uidAddress2: string = randomString();
|
||||
const uidAddress3: string = randomString();
|
||||
const uidAddress4: string = randomString();
|
||||
|
||||
const uidOffice1: string = randomString();
|
||||
const uidOffice2: string = randomString();
|
||||
@ -124,6 +126,22 @@ import {
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
},
|
||||
{
|
||||
uid: uidAddress3,
|
||||
address: "Rue Pierre Charles",
|
||||
city: "Paris",
|
||||
zip_code: 75003,
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
},
|
||||
{
|
||||
uid: uidAddress4,
|
||||
address: "Rue Pierre Pologne",
|
||||
city: "Paris",
|
||||
zip_code: 75003,
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
},
|
||||
];
|
||||
|
||||
const contacts: Contacts[] = [
|
||||
@ -155,7 +173,7 @@ import {
|
||||
},
|
||||
{
|
||||
uid: uidContact3,
|
||||
address_uid: uidAddress2,
|
||||
address_uid: uidAddress3,
|
||||
first_name: "Maitre Marcelino",
|
||||
last_name: "Jack",
|
||||
email: "Marcelino.Jack@example.com",
|
||||
@ -168,7 +186,7 @@ import {
|
||||
},
|
||||
{
|
||||
uid: uidContact4,
|
||||
address_uid: uidAddress2,
|
||||
address_uid: uidAddress4,
|
||||
first_name: "Maitre Massi",
|
||||
last_name: "Jack",
|
||||
email: "Massi.Jack@example.com",
|
||||
|
@ -48,10 +48,15 @@ export default class FilesService extends BaseService {
|
||||
* @throws {Error} If file cannot be deleted
|
||||
*/
|
||||
public async delete(uid: string) {
|
||||
try {
|
||||
const fileToUnpin = await this.filesRepository.findOneByUid(uid);
|
||||
const decryptedFilePath = await this.cryptoService.decrypt(fileToUnpin.file_path, fileToUnpin.iv);
|
||||
const fileHash= decryptedFilePath.substring(this.variables.PINATA_GATEWAY.length);
|
||||
await this.ipfsService.unpinFile(fileHash)
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
return this.filesRepository.delete(uid);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user