✨ Refacto archive/restore
This commit is contained in:
parent
bc53a14b1a
commit
95bcb05340
@ -46,7 +46,7 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
OR: [
|
OR: [
|
||||||
{ contact: { first_name: { contains: filter, mode: "insensitive" } } },
|
{ contact: { first_name: { contains: filter, mode: "insensitive" } } },
|
||||||
{ contact: { last_name: { contains: filter, mode: "insensitive" } } },
|
{ contact: { last_name: { contains: filter, mode: "insensitive" } } },
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -111,7 +111,9 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const officeFolderFound = await this.officeFoldersService.getByUid(uid);
|
const officeFolderFound = await this.officeFoldersService.getByUid(uid, {
|
||||||
|
folder_anchor: true,
|
||||||
|
});
|
||||||
|
|
||||||
if (!officeFolderFound) {
|
if (!officeFolderFound) {
|
||||||
this.httpNotFoundRequest(response, "office folder not found");
|
this.httpNotFoundRequest(response, "office folder not found");
|
||||||
@ -119,13 +121,17 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//init OfficeFolder resource with request body values
|
//init OfficeFolder resource with request body values
|
||||||
const officeFolderEntity = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
const officefolderToUpdate = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||||
|
|
||||||
//validate folder
|
//validate folder
|
||||||
await validateOrReject(officeFolderEntity, { groups: ["updateFolder"], forbidUnknownValues: false });
|
await validateOrReject(officefolderToUpdate, { groups: ["updateFolder"], forbidUnknownValues: false });
|
||||||
|
|
||||||
|
if ((officeFolderFound as any).folder_anchor?.status === "VERIFIED_ON_CHAIN") {
|
||||||
|
this.httpBadRequest(response, "Cannot update a verified folder");
|
||||||
|
return;
|
||||||
|
}
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const officeFolderEntityUpdated = await this.officeFoldersService.update(uid, officeFolderEntity);
|
const officeFolderEntityUpdated = await this.officeFoldersService.update(uid, officefolderToUpdate);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityUpdated, {
|
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityUpdated, {
|
||||||
@ -140,6 +146,102 @@ export default class OfficeFoldersController extends ApiController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Modify a specific folder by uid
|
||||||
|
*/
|
||||||
|
@Put("/api/v1/notary/folders/:uid/archive", [authHandler, ruleHandler, folderHandler])
|
||||||
|
protected async archive(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
this.httpBadRequest(response, "No uid provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const officeFolderFound = await this.officeFoldersService.getByUid(uid, {
|
||||||
|
folder_anchor: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!officeFolderFound) {
|
||||||
|
this.httpNotFoundRequest(response, "office folder not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//init OfficeFolder resource with request body values
|
||||||
|
const officefolderToUpdate = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound);
|
||||||
|
|
||||||
|
officefolderToUpdate.status = "ARCHIVED";
|
||||||
|
officefolderToUpdate.archived_description = req.body.archived_description ?? "";
|
||||||
|
|
||||||
|
//validate folder
|
||||||
|
await validateOrReject(officefolderToUpdate, { groups: ["updateFolder"], forbidUnknownValues: false });
|
||||||
|
|
||||||
|
if ((officeFolderFound as any).folder_anchor?.status !== "VERIFIED_ON_CHAIN") {
|
||||||
|
this.httpBadRequest(response, "Cannot archive a not anchored folder");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const officeFolderEntityUpdated = await this.officeFoldersService.update(uid, officefolderToUpdate);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityUpdated, {
|
||||||
|
strategy: "excludeAll",
|
||||||
|
});
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, officeFolders);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Modify a specific folder by uid
|
||||||
|
*/
|
||||||
|
@Put("/api/v1/notary/folders/:uid/restore", [authHandler, ruleHandler, folderHandler])
|
||||||
|
protected async restore(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
if (!uid) {
|
||||||
|
this.httpBadRequest(response, "No uid provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const officeFolderFound = await this.officeFoldersService.getByUid(uid, {
|
||||||
|
folder_anchor: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!officeFolderFound) {
|
||||||
|
this.httpNotFoundRequest(response, "office folder not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//init OfficeFolder resource with request body values
|
||||||
|
const officefolderToUpdate = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound);
|
||||||
|
|
||||||
|
officefolderToUpdate.status = "LIVE";
|
||||||
|
officefolderToUpdate.archived_description = "";
|
||||||
|
|
||||||
|
//validate folder
|
||||||
|
await validateOrReject(officefolderToUpdate, { groups: ["updateFolder"], forbidUnknownValues: false });
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const officeFolderEntityUpdated = await this.officeFoldersService.update(uid, officefolderToUpdate);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityUpdated, {
|
||||||
|
strategy: "excludeAll",
|
||||||
|
});
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, officeFolders);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @description Get a specific folder by uid
|
* @description Get a specific folder by uid
|
||||||
* @returns IFolder
|
* @returns IFolder
|
||||||
|
Loading…
x
Reference in New Issue
Block a user