refactor: get index from .env

This commit is contained in:
Methapon2001 2023-11-23 10:32:49 +07:00
parent dd1547d7c2
commit 1c3ac35ed1
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
3 changed files with 21 additions and 21 deletions

View file

@ -61,7 +61,7 @@ export class SubFolderFileController extends Controller {
if (!info) throw new Error("Object storage error occured.");
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
index: "ehr-api-client",
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
query: {
match: {
pathname: pathname,
@ -85,7 +85,7 @@ export class SubFolderFileController extends Controller {
if (!exist) {
await esClient.index({
pipeline: "attachment",
index: "ehr-api-client",
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
document: {
data: Buffer.from(file.buffer).toString("base64"),
createdAt: new Date().toISOString(),
@ -99,7 +99,7 @@ export class SubFolderFileController extends Controller {
await esClient.delete({ index: exist._index, id: exist._id });
await esClient.index({
pipeline: "attachment",
index: "ehr-api-client",
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
document: {
data: Buffer.from(file.buffer).toString("base64"),
createdAt: exist._source?.createdAt,
@ -128,7 +128,7 @@ export class SubFolderFileController extends Controller {
attachment: Record<string, string>;
}
>({
index: "ehr-api-client",
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
query: {
prefix: {
pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}`,
@ -168,7 +168,7 @@ export class SubFolderFileController extends Controller {
@FormField() category?: string,
) {
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
index: "ehr-api-client",
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
query: {
match: {
pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/${fileName}`,
@ -185,7 +185,7 @@ export class SubFolderFileController extends Controller {
if (!file) {
const esResult = await esClient
.update({
index: "ehr-api-client",
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
id: data._id,
doc: {
title,
@ -221,7 +221,7 @@ export class SubFolderFileController extends Controller {
await esClient.delete({ index: data._index, id: data._id });
await esClient.index({
pipeline: "attachment",
index: "ehr-api-client",
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
document: {
data: Buffer.from(file.buffer).toString("base64"),
pathname,
@ -259,7 +259,7 @@ export class SubFolderFileController extends Controller {
attachment: Record<string, string>;
}
>({
index: "ehr-api-client",
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
query: {
match: {
pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/${fileName}`,
@ -273,7 +273,7 @@ export class SubFolderFileController extends Controller {
const esResult = await esClient
.delete({
index: "ehr-api-client",
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
id: search.hits.hits[0]._id,
})
.catch((e) => console.error(e));
@ -299,7 +299,7 @@ export class SubFolderFileController extends Controller {
@Path() fileName: string,
) {
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
index: "ehr-api-client",
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
query: {
match: {
pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/${fileName}`,