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

@ -58,7 +58,7 @@ export class FileController 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,
@ -82,7 +82,7 @@ export class FileController 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(),
@ -96,7 +96,7 @@ export class FileController 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,
@ -124,7 +124,7 @@ export class FileController extends Controller {
attachment: Record<string, string>;
}
>({
index: "ehr-api-client",
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
query: {
prefix: {
pathname: `${cabinetName}/${drawerName}/${folderName}/`,
@ -163,7 +163,7 @@ export class FileController 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}/${fileName}`,
@ -180,7 +180,7 @@ export class FileController 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,
@ -216,7 +216,7 @@ export class FileController 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,
@ -253,7 +253,7 @@ export class FileController extends Controller {
attachment: Record<string, string>;
}
>({
index: "ehr-api-client",
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
query: {
match: {
pathname: `${cabinetName}/${drawerName}/${folderName}/${fileName}`,
@ -267,7 +267,7 @@ export class FileController 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));
@ -289,7 +289,7 @@ export class FileController 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}/${fileName}`,