feat: delete file

This commit is contained in:
Methapon2001 2023-11-20 12:03:28 +07:00
parent 82ee1ef7f7
commit a0d70fbb38
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
3 changed files with 43 additions and 2 deletions

View file

@ -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);
}
}

View file

@ -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)),

View file

@ -569,7 +569,7 @@
}
},
"/cabinet/{cabinetName}/drawer/{drawerName}/folder/{folderName}/file/{fileName}": {
"get": {
"delete": {
"operationId": "DeleteFile",
"responses": {
"200": {