feat: delete file
This commit is contained in:
parent
82ee1ef7f7
commit
a0d70fbb38
3 changed files with 43 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
Controller,
|
||||
Delete,
|
||||
FormField,
|
||||
Get,
|
||||
Path,
|
||||
|
|
@ -165,4 +166,44 @@ export class FileController extends Controller {
|
|||
|
||||
return records;
|
||||
}
|
||||
|
||||
@Delete("/{cabinetName}/drawer/{drawerName}/folder/{folderName}/file/{fileName}")
|
||||
@Tags("File")
|
||||
@SuccessResponse(HttpStatusCode.OK)
|
||||
public async deleteFile(
|
||||
@Path() cabinetName: string,
|
||||
@Path() drawerName: string,
|
||||
@Path() folderName: string,
|
||||
@Path() fileName: string,
|
||||
) {
|
||||
const search = await esClient.search<
|
||||
EhrFile & {
|
||||
attachment: Record<string, string>;
|
||||
}
|
||||
>({
|
||||
index: "ehr-api-client",
|
||||
query: {
|
||||
match: {
|
||||
pathname: `${cabinetName}/${drawerName}/${folderName}/${fileName}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (search && search.hits.hits.length === 0) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "Not found");
|
||||
}
|
||||
|
||||
const esResult = await esClient
|
||||
.delete({
|
||||
index: "ehr-api-client",
|
||||
id: search.hits.hits[0]._id,
|
||||
})
|
||||
.catch((e) => console.error(e));
|
||||
|
||||
if (!esResult) throw new Error("An error occured, cannot perform this action.");
|
||||
|
||||
await minioClient.removeObject("ehr", `${cabinetName}/${drawerName}/${folderName}/${fileName}`);
|
||||
|
||||
return this.setStatus(HttpStatusCode.NO_CONTENT);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -317,7 +317,7 @@ export function RegisterRoutes(app: Router) {
|
|||
}
|
||||
});
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
app.get('/cabinet/:cabinetName/drawer/:drawerName/folder/:folderName/file/:fileName',
|
||||
app.delete('/cabinet/:cabinetName/drawer/:drawerName/folder/:folderName/file/:fileName',
|
||||
...(fetchMiddlewares<RequestHandler>(FileController)),
|
||||
...(fetchMiddlewares<RequestHandler>(FileController.prototype.deleteFile)),
|
||||
|
||||
|
|
|
|||
|
|
@ -569,7 +569,7 @@
|
|||
}
|
||||
},
|
||||
"/cabinet/{cabinetName}/drawer/{drawerName}/folder/{folderName}/file/{fileName}": {
|
||||
"get": {
|
||||
"delete": {
|
||||
"operationId": "DeleteFile",
|
||||
"responses": {
|
||||
"200": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue