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
|
|
@ -121,7 +121,7 @@ export class CabinetController extends Controller {
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
@SuccessResponse(HttpStatusCode.NO_CONTENT)
|
@SuccessResponse(HttpStatusCode.NO_CONTENT)
|
||||||
public async deleteCabinet(@Path() cabinetName: string) {
|
public async deleteCabinet(@Path() cabinetName: string) {
|
||||||
return new Promise((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
const objects: string[] = [];
|
const objects: string[] = [];
|
||||||
const stream = minioClient.listObjectsV2("ehr", `${cabinetName}/`, true);
|
const stream = minioClient.listObjectsV2("ehr", `${cabinetName}/`, true);
|
||||||
|
|
||||||
|
|
@ -131,10 +131,31 @@ export class CabinetController extends Controller {
|
||||||
objects.push(v.name);
|
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.")));
|
stream.on("error", () => reject(new Error("Object storage error occured.")));
|
||||||
|
|
||||||
resolve(this.setStatus(HttpStatusCode.NO_CONTENT));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const searchResult = await esClient.search({
|
||||||
|
index: process.env.ELASTICSEARCH_INDEX ?? "ehr-index",
|
||||||
|
query: {
|
||||||
|
prefix: { pathname: `${cabinetName}/` },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ export class DrawerController extends Controller {
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
@SuccessResponse(HttpStatusCode.NO_CONTENT)
|
@SuccessResponse(HttpStatusCode.NO_CONTENT)
|
||||||
public async deleteDrawer(@Path() cabinetName: string, @Path() drawerName: string) {
|
public async deleteDrawer(@Path() cabinetName: string, @Path() drawerName: string) {
|
||||||
return new Promise((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
const objects: string[] = [];
|
const objects: string[] = [];
|
||||||
const stream = minioClient.listObjectsV2("ehr", `${cabinetName}/${drawerName}/`, true);
|
const stream = minioClient.listObjectsV2("ehr", `${cabinetName}/${drawerName}/`, true);
|
||||||
|
|
||||||
|
|
@ -142,10 +142,31 @@ export class DrawerController extends Controller {
|
||||||
objects.push(v.name);
|
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.")));
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,11 +147,11 @@ export class FolderController extends Controller {
|
||||||
@Path() drawerName: string,
|
@Path() drawerName: string,
|
||||||
@Path() folderName: string,
|
@Path() folderName: string,
|
||||||
) {
|
) {
|
||||||
return new Promise((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
const objects: string[] = [];
|
const objects: string[] = [];
|
||||||
const stream = minioClient.listObjectsV2(
|
const stream = minioClient.listObjectsV2(
|
||||||
"ehr",
|
"ehr",
|
||||||
`${cabinetName}/${drawerName}/${folderName}`,
|
`${cabinetName}/${drawerName}/${folderName}/`,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -161,10 +161,31 @@ export class FolderController extends Controller {
|
||||||
objects.push(v.name);
|
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.")));
|
stream.on("error", () => reject(new Error("Object storage error occured.")));
|
||||||
|
|
||||||
resolve(this.setStatus(HttpStatusCode.NO_CONTENT));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const searchResult = await esClient.search({
|
||||||
|
index: process.env.ELASTICSEARCH_INDEX ?? "ehr-index",
|
||||||
|
query: {
|
||||||
|
prefix: { pathname: `${cabinetName}/${drawerName}/${folderName}/` },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -154,11 +154,11 @@ export class SubFolderController extends Controller {
|
||||||
@Path() folderName: string,
|
@Path() folderName: string,
|
||||||
@Path() subFolderName: string,
|
@Path() subFolderName: string,
|
||||||
) {
|
) {
|
||||||
return new Promise((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
const objects: string[] = [];
|
const objects: string[] = [];
|
||||||
const stream = minioClient.listObjectsV2(
|
const stream = minioClient.listObjectsV2(
|
||||||
"ehr",
|
"ehr",
|
||||||
`${cabinetName}/${drawerName}/${folderName}/${subFolderName}`,
|
`${cabinetName}/${drawerName}/${folderName}/${subFolderName}/`,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -168,10 +168,31 @@ export class SubFolderController extends Controller {
|
||||||
objects.push(v.name);
|
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.")));
|
stream.on("error", () => reject(new Error("Object storage error occured.")));
|
||||||
|
|
||||||
resolve(this.setStatus(HttpStatusCode.NO_CONTENT));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const searchResult = await esClient.search({
|
||||||
|
index: process.env.ELASTICSEARCH_INDEX ?? "ehr-index",
|
||||||
|
query: {
|
||||||
|
prefix: { pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}` },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
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