refactor: .env compat
This commit is contained in:
parent
2c4d3846f1
commit
eed1a863d3
1 changed files with 9 additions and 3 deletions
|
|
@ -1,23 +1,29 @@
|
||||||
import { Body, Controller, Post, Route, SuccessResponse, Tags } from "tsoa";
|
import { Body, Controller, Post, Route, Security, SuccessResponse, Tags } from "tsoa";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import esClient from "../elasticsearch";
|
import esClient from "../elasticsearch";
|
||||||
import { Search } from "../interfaces/search";
|
import { Search } from "../interfaces/search";
|
||||||
import { EhrFile } from "../interfaces/ehr-fs";
|
import { EhrFile } from "../interfaces/ehr-fs";
|
||||||
|
|
||||||
|
const DEFAULT_INDEX = process.env.ELASTICSEARCH_INDEX;
|
||||||
|
|
||||||
|
if (!DEFAULT_INDEX) throw Error("Default ElasticSearch index must be specified.");
|
||||||
|
|
||||||
@Route("/search")
|
@Route("/search")
|
||||||
export class SearchController extends Controller {
|
export class SearchController extends Controller {
|
||||||
@Post("/")
|
@Post("/")
|
||||||
@Tags("Search")
|
@Tags("Search")
|
||||||
@SuccessResponse(HttpStatusCode.OK)
|
@Security("bearerAuth")
|
||||||
|
@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: process.env.ELASTICSEARCH_INDEX ?? "ehr-index",
|
index: DEFAULT_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 } })),
|
||||||
should: search.OR?.map((v) => ({ match: { [v.field]: v.value } })),
|
should: search.OR?.map((v) => ({ match: { [v.field]: v.value } })),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
size: 10000,
|
||||||
});
|
});
|
||||||
|
|
||||||
return result.hits.hits.length > 0
|
return result.hits.hits.length > 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue