fix: delete does not remove data from database
This commit is contained in:
parent
9b5a65ce02
commit
bd8290b6b1
4 changed files with 102 additions and 18 deletions
|
|
@ -132,7 +132,7 @@ export class DrawerController extends Controller {
|
|||
@Security("bearerAuth")
|
||||
@SuccessResponse(HttpStatusCode.NO_CONTENT)
|
||||
public async deleteDrawer(@Path() cabinetName: string, @Path() drawerName: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const objects: string[] = [];
|
||||
const stream = minioClient.listObjectsV2("ehr", `${cabinetName}/${drawerName}/`, true);
|
||||
|
||||
|
|
@ -142,10 +142,31 @@ export class DrawerController extends Controller {
|
|||
objects.push(v.name);
|
||||
});
|
||||
|
||||
stream.on("close", () => minioClient.removeObjects("ehr", objects));
|
||||
stream.on("close", async () => {
|
||||
minioClient.removeObjects("ehr", objects);
|
||||
resolve();
|
||||
});
|
||||
stream.on("error", () => reject(new Error("Object storage error occured.")));
|
||||
|
||||
resolve(true);
|
||||
});
|
||||
|
||||
const searchResult = await esClient.search({
|
||||
index: process.env.ELASTICSEARCH_INDEX ?? "ehr-index",
|
||||
query: {
|
||||
prefix: { pathname: `${cabinetName}/${drawerName}/` },
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
searchResult.hits.hits.map(async (v) => {
|
||||
return esClient
|
||||
.delete({
|
||||
index: process.env.ELASTICSEARCH_INDEX ?? "ehr-index",
|
||||
id: v._id,
|
||||
})
|
||||
.catch((e) => console.error(`ElasticSearch Error: ${e}`));
|
||||
}),
|
||||
);
|
||||
|
||||
return this.setStatus(HttpStatusCode.NO_CONTENT);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue