🐛 Fixing hydrate

This commit is contained in:
Maxime Lalo 2023-05-15 16:08:32 +02:00
parent 3403b563d8
commit 090daafe5d
13 changed files with 26 additions and 17 deletions

View File

@ -28,7 +28,7 @@ export default class DocumentsController extends ApiController {
const documentEntities: Documents[] = await this.documentsService.get(query); const documentEntities: Documents[] = await this.documentsService.get(query);
//Hydrate ressource with prisma entity //Hydrate ressource with prisma entity
const documents = Document.hydrateArray<Document>(Document, documentEntities, { strategy: "excludeAll" }); const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });
//success //success
this.httpSuccess(response, documents); this.httpSuccess(response, documents);

View File

@ -27,7 +27,7 @@ export default class CustomersController extends ApiController {
const customersEntities = await this.customersService.get(query); const customersEntities = await this.customersService.get(query);
//Hydrate ressource with prisma entity //Hydrate ressource with prisma entity
const customers = Customer.hydrateArray<Customer>(Customer, customersEntities, { strategy: "excludeAll" }); const customers = Customer.hydrateArray<Customer>(customersEntities, { strategy: "excludeAll" });
//success //success
this.httpSuccess(response, customers); this.httpSuccess(response, customers);

View File

@ -27,7 +27,7 @@ export default class DeedTypesController extends ApiController {
const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query); const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query);
//Hydrate ressource with prisma entity //Hydrate ressource with prisma entity
const DeedTypes = DeedType.hydrateArray<DeedType>(DeedType, deedTypeEntities, { strategy: "excludeAll" }); const DeedTypes = DeedType.hydrateArray<DeedType>(deedTypeEntities, { strategy: "excludeAll" });
//success //success
this.httpSuccess(response, DeedTypes); this.httpSuccess(response, DeedTypes);

View File

@ -27,7 +27,7 @@ export default class DeedsController extends ApiController {
const deedEntities: Deeds[] = await this.deedsService.get(query); const deedEntities: Deeds[] = await this.deedsService.get(query);
//Hydrate ressource with prisma entity //Hydrate ressource with prisma entity
const deeds = Deed.hydrateArray<Deed>(Deed, deedEntities, { strategy: "excludeAll" }); const deeds = Deed.hydrateArray<Deed>(deedEntities, { strategy: "excludeAll" });
//success //success
this.httpSuccess(response, deeds); this.httpSuccess(response, deeds);

View File

@ -28,7 +28,7 @@ export default class DocumentTypesController extends ApiController {
const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query); const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query);
//Hydrate ressource with prisma entity //Hydrate ressource with prisma entity
const documentTypes = DocumentType.hydrateArray<DocumentType>(DocumentType, documentTypeEntities, { const documentTypes = DocumentType.hydrateArray<DocumentType>(documentTypeEntities, {
strategy: "excludeAll", strategy: "excludeAll",
}); });

View File

@ -28,7 +28,7 @@ export default class DocumentsController extends ApiController {
const documentEntities: Documents[] = await this.documentsService.get(query); const documentEntities: Documents[] = await this.documentsService.get(query);
//Hydrate ressource with prisma entity //Hydrate ressource with prisma entity
const documents = Document.hydrateArray<Document>(Document, documentEntities, { strategy: "excludeAll" }); const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });
//success //success
this.httpSuccess(response, documents); this.httpSuccess(response, documents);

View File

@ -29,7 +29,7 @@ export default class FilesController extends ApiController {
const fileEntities = await this.filesService.get(query); const fileEntities = await this.filesService.get(query);
//Hydrate ressource with prisma entity //Hydrate ressource with prisma entity
const files = File.hydrateArray<File>(File, fileEntities, { strategy: "excludeAll" }); const files = File.hydrateArray<File>(fileEntities, { strategy: "excludeAll" });
//success //success
this.httpSuccess(response, files); this.httpSuccess(response, files);

View File

@ -27,7 +27,7 @@ export default class OfficeFoldersController extends ApiController {
const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query); const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);
//Hydrate ressource with prisma entity //Hydrate ressource with prisma entity
const officeFolders = OfficeFolder.hydrateArray<OfficeFolder>(OfficeFolder, officeFolderEntities, { const officeFolders = OfficeFolder.hydrateArray<OfficeFolder>(officeFolderEntities, {
strategy: "excludeAll", strategy: "excludeAll",
}); });
//success //success
@ -45,14 +45,13 @@ export default class OfficeFoldersController extends ApiController {
protected async post(req: Request, response: Response) { protected async post(req: Request, response: Response) {
try { try {
//init OfficeFolder resource with request body values //init OfficeFolder resource with request body values
const officeFolderEntity = OfficeFolder.hydrate<OfficeFolder>(req.body); const officeFolderRessource = OfficeFolder.hydrate<OfficeFolder>(req.body);
await officeFolderRessource.validateOrReject?.({ groups: ["createFolder"] , forbidUnknownValues: false });
//validate folder //validate folder
await validateOrReject(officeFolderEntity, { groups: ["createFolder"] , forbidUnknownValues: false });
//call service to get prisma entity //call service to get prisma entity
const officeFolderEntityCreated = await this.officeFoldersService.create(officeFolderEntity); const officeFolderEntity = await this.officeFoldersService.create(officeFolderRessource);
//Hydrate ressource with prisma entity //Hydrate ressource with prisma entity
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityCreated, { const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, {
strategy: "excludeAll", strategy: "excludeAll",
}); });
//success //success

View File

@ -24,7 +24,7 @@ export default class OfficesController extends ApiController {
//call service to get prisma entity //call service to get prisma entity
const officesEntities: Offices[] = await this.officesService.get(query); const officesEntities: Offices[] = await this.officesService.get(query);
//Hydrate ressource with prisma entity //Hydrate ressource with prisma entity
const offices = OfficeResource.hydrateArray<OfficeResource>(OfficeResource, officesEntities, { strategy: "excludeAll" }); const offices = OfficeResource.hydrateArray<OfficeResource>(officesEntities, { strategy: "excludeAll" });
//success //success
this.httpSuccess(response, offices); this.httpSuccess(response, offices);
} catch (error) { } catch (error) {

View File

@ -27,7 +27,7 @@ export default class UsersController extends ApiController {
const usersEntities = await this.usersService.get(query); const usersEntities = await this.usersService.get(query);
//Hydrate ressource with prisma entity //Hydrate ressource with prisma entity
const users = User.hydrateArray<User>(User, usersEntities, { strategy: "excludeAll" }); const users = User.hydrateArray<User>(usersEntities, { strategy: "excludeAll" });
//success //success
this.httpSuccess(response, users); this.httpSuccess(response, users);

View File

@ -0,0 +1,10 @@
/*
Warnings:
- Added the required column `mimetype` to the `files` table without a default value. This is not possible if the table is not empty.
- Added the required column `size` to the `files` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "files" ADD COLUMN "mimetype" VARCHAR(255) NOT NULL,
ADD COLUMN "size" INTEGER NOT NULL;

View File

@ -78,7 +78,7 @@ export default class DocumentsRepository extends BaseRepository {
/** /**
* @description : Update data of a document * @description : Update data of a document
*/ */
public async update(uid: string, document: Document, refusedReason?: string): Promise<Documents> { public async update(uid: string, document: Partial<Document>, refusedReason?: string): Promise<Documents> {
return this.model.update({ return this.model.update({
where: { where: {
uid: uid, uid: uid,

View File

@ -38,7 +38,7 @@ export default class DocumentsService extends BaseService {
* @description : Modify a document * @description : Modify a document
* @throws {Error} If document cannot be modified * @throws {Error} If document cannot be modified
*/ */
public async update(uid: string, document: Document, refused_reason?: string): Promise<Documents> { public async update(uid: string, document: Partial<Document>, refused_reason?: string): Promise<Documents> {
return this.documentsRepository.update(uid, document, refused_reason); return this.documentsRepository.update(uid, document, refused_reason);
} }