refactor: get index from .env
This commit is contained in:
parent
dd1547d7c2
commit
1c3ac35ed1
3 changed files with 21 additions and 21 deletions
|
|
@ -58,7 +58,7 @@ export class FileController extends Controller {
|
||||||
if (!info) throw new Error("Object storage error occured.");
|
if (!info) throw new Error("Object storage error occured.");
|
||||||
|
|
||||||
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
query: {
|
query: {
|
||||||
match: {
|
match: {
|
||||||
pathname: pathname,
|
pathname: pathname,
|
||||||
|
|
@ -82,7 +82,7 @@ export class FileController extends Controller {
|
||||||
if (!exist) {
|
if (!exist) {
|
||||||
await esClient.index({
|
await esClient.index({
|
||||||
pipeline: "attachment",
|
pipeline: "attachment",
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
document: {
|
document: {
|
||||||
data: Buffer.from(file.buffer).toString("base64"),
|
data: Buffer.from(file.buffer).toString("base64"),
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
|
|
@ -96,7 +96,7 @@ export class FileController extends Controller {
|
||||||
await esClient.delete({ index: exist._index, id: exist._id });
|
await esClient.delete({ index: exist._index, id: exist._id });
|
||||||
await esClient.index({
|
await esClient.index({
|
||||||
pipeline: "attachment",
|
pipeline: "attachment",
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
document: {
|
document: {
|
||||||
data: Buffer.from(file.buffer).toString("base64"),
|
data: Buffer.from(file.buffer).toString("base64"),
|
||||||
createdAt: exist._source?.createdAt,
|
createdAt: exist._source?.createdAt,
|
||||||
|
|
@ -124,7 +124,7 @@ export class FileController extends Controller {
|
||||||
attachment: Record<string, string>;
|
attachment: Record<string, string>;
|
||||||
}
|
}
|
||||||
>({
|
>({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
query: {
|
query: {
|
||||||
prefix: {
|
prefix: {
|
||||||
pathname: `${cabinetName}/${drawerName}/${folderName}/`,
|
pathname: `${cabinetName}/${drawerName}/${folderName}/`,
|
||||||
|
|
@ -163,7 +163,7 @@ export class FileController extends Controller {
|
||||||
@FormField() category?: string,
|
@FormField() category?: string,
|
||||||
) {
|
) {
|
||||||
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
query: {
|
query: {
|
||||||
match: {
|
match: {
|
||||||
pathname: `${cabinetName}/${drawerName}/${folderName}/${fileName}`,
|
pathname: `${cabinetName}/${drawerName}/${folderName}/${fileName}`,
|
||||||
|
|
@ -180,7 +180,7 @@ export class FileController extends Controller {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
const esResult = await esClient
|
const esResult = await esClient
|
||||||
.update({
|
.update({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
id: data._id,
|
id: data._id,
|
||||||
doc: {
|
doc: {
|
||||||
title,
|
title,
|
||||||
|
|
@ -216,7 +216,7 @@ export class FileController extends Controller {
|
||||||
await esClient.delete({ index: data._index, id: data._id });
|
await esClient.delete({ index: data._index, id: data._id });
|
||||||
await esClient.index({
|
await esClient.index({
|
||||||
pipeline: "attachment",
|
pipeline: "attachment",
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
document: {
|
document: {
|
||||||
data: Buffer.from(file.buffer).toString("base64"),
|
data: Buffer.from(file.buffer).toString("base64"),
|
||||||
pathname,
|
pathname,
|
||||||
|
|
@ -253,7 +253,7 @@ export class FileController extends Controller {
|
||||||
attachment: Record<string, string>;
|
attachment: Record<string, string>;
|
||||||
}
|
}
|
||||||
>({
|
>({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
query: {
|
query: {
|
||||||
match: {
|
match: {
|
||||||
pathname: `${cabinetName}/${drawerName}/${folderName}/${fileName}`,
|
pathname: `${cabinetName}/${drawerName}/${folderName}/${fileName}`,
|
||||||
|
|
@ -267,7 +267,7 @@ export class FileController extends Controller {
|
||||||
|
|
||||||
const esResult = await esClient
|
const esResult = await esClient
|
||||||
.delete({
|
.delete({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
id: search.hits.hits[0]._id,
|
id: search.hits.hits[0]._id,
|
||||||
})
|
})
|
||||||
.catch((e) => console.error(e));
|
.catch((e) => console.error(e));
|
||||||
|
|
@ -289,7 +289,7 @@ export class FileController extends Controller {
|
||||||
@Path() fileName: string,
|
@Path() fileName: string,
|
||||||
) {
|
) {
|
||||||
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
query: {
|
query: {
|
||||||
match: {
|
match: {
|
||||||
pathname: `${cabinetName}/${drawerName}/${folderName}/${fileName}`,
|
pathname: `${cabinetName}/${drawerName}/${folderName}/${fileName}`,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ export class SearchController extends Controller {
|
||||||
@SuccessResponse(HttpStatusCode.OK)
|
@SuccessResponse(HttpStatusCode.OK)
|
||||||
public async searchFile(@Body() search: Search): Promise<EhrFile[]> {
|
public async searchFile(@Body() search: Search): Promise<EhrFile[]> {
|
||||||
const result = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
const result = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
query: {
|
query: {
|
||||||
bool: {
|
bool: {
|
||||||
must: search.AND?.map((v) => ({ match: { [v.field]: v.value } })),
|
must: search.AND?.map((v) => ({ match: { [v.field]: v.value } })),
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ export class SubFolderFileController extends Controller {
|
||||||
if (!info) throw new Error("Object storage error occured.");
|
if (!info) throw new Error("Object storage error occured.");
|
||||||
|
|
||||||
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
query: {
|
query: {
|
||||||
match: {
|
match: {
|
||||||
pathname: pathname,
|
pathname: pathname,
|
||||||
|
|
@ -85,7 +85,7 @@ export class SubFolderFileController extends Controller {
|
||||||
if (!exist) {
|
if (!exist) {
|
||||||
await esClient.index({
|
await esClient.index({
|
||||||
pipeline: "attachment",
|
pipeline: "attachment",
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
document: {
|
document: {
|
||||||
data: Buffer.from(file.buffer).toString("base64"),
|
data: Buffer.from(file.buffer).toString("base64"),
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
|
|
@ -99,7 +99,7 @@ export class SubFolderFileController extends Controller {
|
||||||
await esClient.delete({ index: exist._index, id: exist._id });
|
await esClient.delete({ index: exist._index, id: exist._id });
|
||||||
await esClient.index({
|
await esClient.index({
|
||||||
pipeline: "attachment",
|
pipeline: "attachment",
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
document: {
|
document: {
|
||||||
data: Buffer.from(file.buffer).toString("base64"),
|
data: Buffer.from(file.buffer).toString("base64"),
|
||||||
createdAt: exist._source?.createdAt,
|
createdAt: exist._source?.createdAt,
|
||||||
|
|
@ -128,7 +128,7 @@ export class SubFolderFileController extends Controller {
|
||||||
attachment: Record<string, string>;
|
attachment: Record<string, string>;
|
||||||
}
|
}
|
||||||
>({
|
>({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
query: {
|
query: {
|
||||||
prefix: {
|
prefix: {
|
||||||
pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}`,
|
pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}`,
|
||||||
|
|
@ -168,7 +168,7 @@ export class SubFolderFileController extends Controller {
|
||||||
@FormField() category?: string,
|
@FormField() category?: string,
|
||||||
) {
|
) {
|
||||||
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
query: {
|
query: {
|
||||||
match: {
|
match: {
|
||||||
pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/${fileName}`,
|
pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/${fileName}`,
|
||||||
|
|
@ -185,7 +185,7 @@ export class SubFolderFileController extends Controller {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
const esResult = await esClient
|
const esResult = await esClient
|
||||||
.update({
|
.update({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
id: data._id,
|
id: data._id,
|
||||||
doc: {
|
doc: {
|
||||||
title,
|
title,
|
||||||
|
|
@ -221,7 +221,7 @@ export class SubFolderFileController extends Controller {
|
||||||
await esClient.delete({ index: data._index, id: data._id });
|
await esClient.delete({ index: data._index, id: data._id });
|
||||||
await esClient.index({
|
await esClient.index({
|
||||||
pipeline: "attachment",
|
pipeline: "attachment",
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
document: {
|
document: {
|
||||||
data: Buffer.from(file.buffer).toString("base64"),
|
data: Buffer.from(file.buffer).toString("base64"),
|
||||||
pathname,
|
pathname,
|
||||||
|
|
@ -259,7 +259,7 @@ export class SubFolderFileController extends Controller {
|
||||||
attachment: Record<string, string>;
|
attachment: Record<string, string>;
|
||||||
}
|
}
|
||||||
>({
|
>({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
query: {
|
query: {
|
||||||
match: {
|
match: {
|
||||||
pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/${fileName}`,
|
pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/${fileName}`,
|
||||||
|
|
@ -273,7 +273,7 @@ export class SubFolderFileController extends Controller {
|
||||||
|
|
||||||
const esResult = await esClient
|
const esResult = await esClient
|
||||||
.delete({
|
.delete({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
id: search.hits.hits[0]._id,
|
id: search.hits.hits[0]._id,
|
||||||
})
|
})
|
||||||
.catch((e) => console.error(e));
|
.catch((e) => console.error(e));
|
||||||
|
|
@ -299,7 +299,7 @@ export class SubFolderFileController extends Controller {
|
||||||
@Path() fileName: string,
|
@Path() fileName: string,
|
||||||
) {
|
) {
|
||||||
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
||||||
index: "ehr-api-client",
|
index: process.env.ELASTICSEARCH_INDEX ?? 'ehr-index',
|
||||||
query: {
|
query: {
|
||||||
match: {
|
match: {
|
||||||
pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/${fileName}`,
|
pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/${fileName}`,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue