delete folder done (#36)
This commit is contained in:
commit
7a3a0ce8cd
@ -1,5 +1,5 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficeFoldersService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService";
|
||||
import { Service } from "typedi";
|
||||
@ -126,4 +126,29 @@ export default class OfficeFoldersController extends ApiController {
|
||||
}
|
||||
this.httpSuccess(response, await this.officeFoldersService.getByUid("uid"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific folder
|
||||
*/
|
||||
@Delete("/api/v1/super-admin/folders/:uid")
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFoldertEntity: OfficeFolders = await this.officeFoldersService.delete(uid);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFoldertEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolder);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,4 +143,15 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
|
||||
return officeFolderEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Delete a folder
|
||||
*/
|
||||
public async delete(uid: string): Promise<OfficeFolders> {
|
||||
return this.model.delete({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -48,4 +48,16 @@ export default class OfficeFoldersService extends BaseService {
|
||||
public async getByUid(uid: string, query?: any) {
|
||||
return this.officeFoldersRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Delete a folder
|
||||
* @throws {Error} If document cannot be deleted
|
||||
*/
|
||||
public async delete(uid: string): Promise<OfficeFolders> {
|
||||
const officeFolder = await this.officeFoldersRepository.findOneByUid(uid);
|
||||
if (officeFolder.status !== "ARCHIVED") {
|
||||
throw new Error("Cannot delete a folder that is not archived");
|
||||
}
|
||||
return this.officeFoldersRepository.delete(uid);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user