fix: error undefined and waiting for index after update

This commit is contained in:
Methapon2001 2023-11-28 15:28:12 +07:00
parent 4fa8ad3adf
commit 93f0ac3431
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
2 changed files with 9 additions and 3 deletions

View file

@ -111,7 +111,7 @@ export class FileController extends Controller {
.catch((e) => console.error(e));
}
const rec = result ? result.hits.hits[0]._source : false;
const rec = result && result.hits.hits.length > 0 ? result.hits.hits[0]._source : false;
const metadata: Partial<StorageFile> = {
pathname,
@ -201,9 +201,11 @@ export class FileController extends Controller {
id,
doc: {
pathname: destination,
fileName: body.file,
updatedAt: new Date().toISOString(),
updatedBy: request.user.preferred_username ?? "n/a",
},
refresh: "wait_for",
})
.then(() => minioClient.removeObject(DEFAULT_BUCKET!, pathname));
} else {
@ -230,6 +232,7 @@ export class FileController extends Controller {
updatedAt: new Date().toISOString(),
updatedBy: request.user.preferred_username ?? "n/a",
},
refresh: "wait_for",
});
}
}

View file

@ -115,7 +115,7 @@ export class SubFolderFileController extends Controller {
.catch((e) => console.error(e));
}
const rec = result ? result.hits.hits[0]._source : false;
const rec = result && result.hits.hits.length > 0 ? result.hits.hits[0]._source : false;
const metadata: Partial<StorageFile> = {
pathname,
@ -205,9 +205,11 @@ export class SubFolderFileController extends Controller {
id,
doc: {
pathname: destination,
fileName: body.file,
updatedAt: new Date().toISOString(),
updatedBy: request.user.preferred_username ?? "n/a",
},
refresh: "wait_for",
})
.then(() => minioClient.removeObject(DEFAULT_BUCKET!, pathname));
} else {
@ -234,6 +236,7 @@ export class SubFolderFileController extends Controller {
updatedAt: new Date().toISOString(),
updatedBy: request.user.preferred_username ?? "n/a",
},
refresh: "wait_for",
});
}
}
@ -261,7 +264,7 @@ export class SubFolderFileController extends Controller {
) {
await minioClient.removeObject(
DEFAULT_BUCKET!,
`${cabinetName}/${drawerName}/${folderName}/${fileName}/${subFolderName}/`,
`${cabinetName}/${drawerName}/${folderName}/${subFolderName}/${fileName}`,
);
return this.setStatus(HttpStatusCode.NO_CONTENT);
}