diff --git a/Services/server/src/controllers/cabinetController.ts b/Services/server/src/controllers/cabinetController.ts index 32d0b68..b900dbb 100644 --- a/Services/server/src/controllers/cabinetController.ts +++ b/Services/server/src/controllers/cabinetController.ts @@ -20,7 +20,7 @@ import esClient from "../elasticsearch"; import { copyCond, listFolder, listItem, replaceIllegalChars } from "../utils/minio"; import HttpStatusCode from "../interfaces/http-status"; -import { EhrFile, EhrFolder } from "../interfaces/ehr-fs"; +import { StorageFile, StorageFolder } from "../interfaces/storage-fs"; const DEFAULT_BUCKET = process.env.MINIO_BUCKET; const DEFAULT_INDEX = process.env.ELASTICSEARCH_INDEX; @@ -38,7 +38,7 @@ export class CabinetController extends Controller { "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการตู้เอกสารได้ กรุณาลองใหม่ในภายหลัง", ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") - public async listCabinet(): Promise { + public async listCabinet(): Promise { const list = await listFolder(DEFAULT_BUCKET!).catch((e) => console.error(`Error List Folder: ${e}`), ); @@ -94,7 +94,7 @@ export class CabinetController extends Controller { return await minioClient.removeObject(DEFAULT_BUCKET!, current.name); } - const search = await esClient.search }>({ + const search = await esClient.search }>({ index: DEFAULT_INDEX!, query: { match: { pathname: current.name } }, }); diff --git a/Services/server/src/controllers/drawerController.ts b/Services/server/src/controllers/drawerController.ts index 00ef246..8e8df67 100644 --- a/Services/server/src/controllers/drawerController.ts +++ b/Services/server/src/controllers/drawerController.ts @@ -20,7 +20,7 @@ import esClient from "../elasticsearch"; import { copyCond, listFolder, listItem, replaceIllegalChars } from "../utils/minio"; import HttpStatusCode from "../interfaces/http-status"; -import { EhrFile, EhrFolder } from "../interfaces/ehr-fs"; +import { StorageFile, StorageFolder } from "../interfaces/storage-fs"; import HttpError from "../interfaces/http-error"; const DEFAULT_BUCKET = process.env.MINIO_BUCKET; @@ -39,7 +39,7 @@ export class DrawerController extends Controller { "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการลิ้นชักได้ กรุณาลองใหม่ในภายหลัง", ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") - public async listDrawer(@Path() cabinetName: string): Promise { + public async listDrawer(@Path() cabinetName: string): Promise { const list = await listFolder(DEFAULT_BUCKET!, `${cabinetName}/`).catch((e) => console.error(`Error List Folder: ${e}`), ); @@ -113,7 +113,7 @@ export class DrawerController extends Controller { return await minioClient.removeObject(DEFAULT_BUCKET!, current.name); } - const search = await esClient.search }>({ + const search = await esClient.search }>({ index: DEFAULT_INDEX!, query: { match: { pathname: current.name } }, }); diff --git a/Services/server/src/controllers/fileController.ts b/Services/server/src/controllers/fileController.ts index 28fb0e9..b764926 100644 --- a/Services/server/src/controllers/fileController.ts +++ b/Services/server/src/controllers/fileController.ts @@ -18,7 +18,7 @@ import esClient from "../elasticsearch"; import minioClient from "../minio"; import HttpStatusCode from "../interfaces/http-status"; -import { EhrFile } from "../interfaces/ehr-fs"; +import { StorageFile } from "../interfaces/storage-fs"; import HttpError from "../interfaces/http-error"; import { copyCond, pathExist } from "../utils/minio"; @@ -39,8 +39,8 @@ export class FileController extends Controller { @Path() cabinetName: string, @Path() drawerName: string, @Path() folderName: string, - ): Promise { - const search = await esClient.search }>({ + ): Promise { + const search = await esClient.search }>({ index: DEFAULT_INDEX!, query: { prefix: { @@ -54,10 +54,10 @@ export class FileController extends Controller { .map((v) => { if (v._source) { const { attachment, ...rest } = v._source; - return rest satisfies EhrFile; + return rest satisfies StorageFile; } }) - .filter((v: EhrFile | undefined): v is EhrFile => !!v); + .filter((v: StorageFile | undefined): v is StorageFile => !!v); return records; } @@ -94,7 +94,7 @@ export class FileController extends Controller { } const result = await esClient - .search }>({ + .search }>({ index: DEFAULT_INDEX!, query: { match: { pathname } }, }) @@ -112,7 +112,7 @@ export class FileController extends Controller { const rec = result ? result.hits.hits[0]._source : false; - const metadata: Partial = { + const metadata: Partial = { pathname, fileName: body.file, fileSize: 0, @@ -185,7 +185,7 @@ export class FileController extends Controller { if (copy) { const search = await esClient - .search }>({ + .search }>({ index: DEFAULT_INDEX!, query: { match: { pathname } }, }) @@ -210,7 +210,7 @@ export class FileController extends Controller { } } else { const search = await esClient - .search }>({ + .search }>({ index: DEFAULT_INDEX!, query: { match: { pathname } }, }) @@ -269,7 +269,7 @@ export class FileController extends Controller { @Path() folderName: string, @Path() fileName: string, ) { - const search = await esClient.search }>({ + const search = await esClient.search }>({ index: DEFAULT_INDEX!, query: { match: { pathname: `${cabinetName}/${drawerName}/${folderName}/${fileName}` }, diff --git a/Services/server/src/controllers/folderController.ts b/Services/server/src/controllers/folderController.ts index f872ffe..ebeef78 100644 --- a/Services/server/src/controllers/folderController.ts +++ b/Services/server/src/controllers/folderController.ts @@ -20,7 +20,7 @@ import esClient from "../elasticsearch"; import { copyCond, listFolder, listItem, replaceIllegalChars } from "../utils/minio"; import HttpStatusCode from "../interfaces/http-status"; -import { EhrFile, EhrFolder } from "../interfaces/ehr-fs"; +import { StorageFile, StorageFolder } from "../interfaces/storage-fs"; import HttpError from "../interfaces/http-error"; const DEFAULT_BUCKET = process.env.MINIO_BUCKET; @@ -42,7 +42,7 @@ export class FolderController extends Controller { public async listFolder( @Path() cabinetName: string, @Path() drawerName: string, - ): Promise { + ): Promise { const list = await listFolder(DEFAULT_BUCKET!, `${cabinetName}/${drawerName}`).catch((e) => console.error(`Error List Folder: ${e}`), ); @@ -117,7 +117,7 @@ export class FolderController extends Controller { return await minioClient.removeObject(DEFAULT_BUCKET!, current.name); } - const search = await esClient.search }>({ + const search = await esClient.search }>({ index: DEFAULT_INDEX!, query: { match: { pathname: current.name } }, }); diff --git a/Services/server/src/controllers/searchController.ts b/Services/server/src/controllers/searchController.ts index af352bf..0a6c669 100644 --- a/Services/server/src/controllers/searchController.ts +++ b/Services/server/src/controllers/searchController.ts @@ -2,7 +2,7 @@ import { Body, Controller, Post, Route, Security, SuccessResponse, Tags } from " import HttpStatusCode from "../interfaces/http-status"; import esClient from "../elasticsearch"; import { Search } from "../interfaces/search"; -import { EhrFile } from "../interfaces/ehr-fs"; +import { StorageFile } from "../interfaces/storage-fs"; const DEFAULT_INDEX = process.env.ELASTICSEARCH_INDEX; @@ -14,8 +14,8 @@ export class SearchController extends Controller { @Tags("ค้นหา") @Security("bearerAuth") @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") - public async searchFile(@Body() search: Search): Promise { - const result = await esClient.search }>({ + public async searchFile(@Body() search: Search): Promise { + const result = await esClient.search }>({ index: DEFAULT_INDEX, query: { bool: { diff --git a/Services/server/src/controllers/subFolderController.ts b/Services/server/src/controllers/subFolderController.ts index 426af62..43dc1fa 100644 --- a/Services/server/src/controllers/subFolderController.ts +++ b/Services/server/src/controllers/subFolderController.ts @@ -20,7 +20,7 @@ import esClient from "../elasticsearch"; import { copyCond, listFolder, listItem, replaceIllegalChars } from "../utils/minio"; import HttpStatusCode from "../interfaces/http-status"; -import { EhrFile, EhrFolder } from "../interfaces/ehr-fs"; +import { StorageFile, StorageFolder } from "../interfaces/storage-fs"; import HttpError from "../interfaces/http-error"; const DEFAULT_BUCKET = process.env.MINIO_BUCKET; @@ -43,7 +43,7 @@ export class SubFolderController extends Controller { @Path() cabinetName: string, @Path() drawerName: string, @Path() folderName: string, - ): Promise { + ): Promise { const list = await listFolder( DEFAULT_BUCKET!, `${cabinetName}/${drawerName}/${folderName}`, @@ -121,7 +121,7 @@ export class SubFolderController extends Controller { return await minioClient.removeObject(DEFAULT_BUCKET!, current.name); } - const search = await esClient.search }>({ + const search = await esClient.search }>({ index: DEFAULT_INDEX!, query: { match: { pathname: current.name } }, }); diff --git a/Services/server/src/controllers/subFolderFileController.ts b/Services/server/src/controllers/subFolderFileController.ts index 1a61cd5..bebfb15 100644 --- a/Services/server/src/controllers/subFolderFileController.ts +++ b/Services/server/src/controllers/subFolderFileController.ts @@ -18,7 +18,7 @@ import esClient from "../elasticsearch"; import minioClient from "../minio"; import HttpStatusCode from "../interfaces/http-status"; -import { EhrFile } from "../interfaces/ehr-fs"; +import { StorageFile } from "../interfaces/storage-fs"; import HttpError from "../interfaces/http-error"; import { copyCond, pathExist } from "../utils/minio"; @@ -42,8 +42,8 @@ export class SubFolderFileController extends Controller { @Path() drawerName: string, @Path() folderName: string, @Path() subFolderName: string, - ): Promise { - const search = await esClient.search }>({ + ): Promise { + const search = await esClient.search }>({ index: DEFAULT_INDEX!, query: { prefix: { @@ -57,10 +57,10 @@ export class SubFolderFileController extends Controller { .map((v) => { if (v._source) { const { attachment, ...rest } = v._source; - return rest satisfies EhrFile; + return rest satisfies StorageFile; } }) - .filter((v: EhrFile | undefined): v is EhrFile => !!v); + .filter((v: StorageFile | undefined): v is StorageFile => !!v); return records; } @@ -98,7 +98,7 @@ export class SubFolderFileController extends Controller { } const result = await esClient - .search }>({ + .search }>({ index: DEFAULT_INDEX!, query: { match: { pathname } }, }) @@ -116,7 +116,7 @@ export class SubFolderFileController extends Controller { const rec = result ? result.hits.hits[0]._source : false; - const metadata: Partial = { + const metadata: Partial = { pathname, fileName: body.file, fileSize: 0, @@ -190,7 +190,7 @@ export class SubFolderFileController extends Controller { if (copy) { const search = await esClient - .search }>({ + .search }>({ index: DEFAULT_INDEX!, query: { match: { pathname } }, }) @@ -215,7 +215,7 @@ export class SubFolderFileController extends Controller { } } else { const search = await esClient - .search }>({ + .search }>({ index: DEFAULT_INDEX!, query: { match: { pathname } }, }) @@ -276,7 +276,7 @@ export class SubFolderFileController extends Controller { @Path() subFolderName: string, @Path() fileName: string, ) { - const search = await esClient.search }>({ + const search = await esClient.search }>({ index: DEFAULT_INDEX!, query: { match: { diff --git a/Services/server/src/interfaces/ehr-fs.ts b/Services/server/src/interfaces/storage-fs.ts similarity index 91% rename from Services/server/src/interfaces/ehr-fs.ts rename to Services/server/src/interfaces/storage-fs.ts index 77a3c9b..58737fd 100644 --- a/Services/server/src/interfaces/ehr-fs.ts +++ b/Services/server/src/interfaces/storage-fs.ts @@ -1,4 +1,4 @@ -export interface EhrFolder { +export interface StorageFolder { /** * @prop Full path to this folder. It is used as key as there are no files or directories at the same location. */ @@ -12,7 +12,7 @@ export interface EhrFolder { createdBy: string | Date; } -export interface EhrFile { +export interface StorageFile { /** * @prop Full path to this folder. It is used as key as there are no files or directories at the same location. */ diff --git a/Services/server/src/rabbitmq/handler.ts b/Services/server/src/rabbitmq/handler.ts index a9a4b13..82c51ae 100644 --- a/Services/server/src/rabbitmq/handler.ts +++ b/Services/server/src/rabbitmq/handler.ts @@ -1,4 +1,4 @@ -import { EhrFile } from "../interfaces/ehr-fs"; +import { StorageFile } from "../interfaces/storage-fs"; import esClient from "../elasticsearch"; import minioClient from "../minio"; @@ -48,7 +48,7 @@ export async function handler(key: string, event: string): Promise { // Get info and delete it from ElasticSearch to re-index async function popInfo(pathname: string) { const result = await esClient - .search }>({ + .search }>({ index: DEFAULT_INDEX!, query: { match: { pathname } }, }) @@ -111,7 +111,7 @@ async function handleNotFoundRecord( createdBy: "n/a", updatedAt: new Date().toISOString(), updatedBy: "n/a", - } satisfies Partial; + } satisfies Partial; const result = await esClient .index({ @@ -127,7 +127,7 @@ async function handleNotFoundRecord( } async function handleFoundRecord( - metadata: EhrFile, + metadata: StorageFile, buffer: Buffer, stat: { size: number; type: string }, ) { diff --git a/Services/server/src/routes.ts b/Services/server/src/routes.ts index d84b67a..396e16c 100644 --- a/Services/server/src/routes.ts +++ b/Services/server/src/routes.ts @@ -24,7 +24,7 @@ import type { RequestHandler, Router } from 'express'; // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa const models: TsoaRoute.Models = { - "EhrFolder": { + "StorageFolder": { "dataType": "refObject", "properties": { "pathname": {"dataType":"string","required":true}, @@ -35,7 +35,7 @@ const models: TsoaRoute.Models = { "additionalProperties": false, }, // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa - "EhrFile": { + "StorageFile": { "dataType": "refObject", "properties": { "pathname": {"dataType":"string","required":true}, diff --git a/Services/server/src/swagger.json b/Services/server/src/swagger.json index d511595..9c56b10 100644 --- a/Services/server/src/swagger.json +++ b/Services/server/src/swagger.json @@ -6,7 +6,7 @@ "requestBodies": {}, "responses": {}, "schemas": { - "EhrFolder": { + "StorageFolder": { "properties": { "pathname": { "type": "string" @@ -46,7 +46,7 @@ "type": "object", "additionalProperties": false }, - "EhrFile": { + "StorageFile": { "properties": { "pathname": { "type": "string" @@ -202,7 +202,7 @@ "application/json": { "schema": { "items": { - "$ref": "#/components/schemas/EhrFolder" + "$ref": "#/components/schemas/StorageFolder" }, "type": "array" } @@ -356,7 +356,7 @@ "application/json": { "schema": { "items": { - "$ref": "#/components/schemas/EhrFolder" + "$ref": "#/components/schemas/StorageFolder" }, "type": "array" } @@ -544,7 +544,7 @@ "application/json": { "schema": { "items": { - "$ref": "#/components/schemas/EhrFile" + "$ref": "#/components/schemas/StorageFile" }, "type": "array" } @@ -1042,7 +1042,7 @@ "application/json": { "schema": { "items": { - "$ref": "#/components/schemas/EhrFolder" + "$ref": "#/components/schemas/StorageFolder" }, "type": "array" } @@ -1262,7 +1262,7 @@ "application/json": { "schema": { "items": { - "$ref": "#/components/schemas/EhrFile" + "$ref": "#/components/schemas/StorageFile" }, "type": "array" } @@ -1301,7 +1301,7 @@ "application/json": { "schema": { "items": { - "$ref": "#/components/schemas/EhrFolder" + "$ref": "#/components/schemas/StorageFolder" }, "type": "array" } @@ -1553,7 +1553,7 @@ "application/json": { "schema": { "items": { - "$ref": "#/components/schemas/EhrFile" + "$ref": "#/components/schemas/StorageFile" }, "type": "array" } diff --git a/Services/server/src/utils/minio.ts b/Services/server/src/utils/minio.ts index 53cf2b2..d3d9088 100644 --- a/Services/server/src/utils/minio.ts +++ b/Services/server/src/utils/minio.ts @@ -1,4 +1,4 @@ -import { EhrFolder } from "../interfaces/ehr-fs"; +import { StorageFolder } from "../interfaces/storage-fs"; import * as Minio from "minio"; import minioClient from "../minio"; @@ -29,7 +29,7 @@ export async function pathExist(path: string): Promise { * @param path - path to list * @return list of folder with metadata */ -export async function listFolder(bucket: string, path?: string): Promise { +export async function listFolder(bucket: string, path?: string): Promise { if (path) path = `${path.replace(/^\/|\/$/g, "")}/`; const list = await new Promise<{ pathname: string; name: string }[]>((resolve, reject) => { @@ -63,11 +63,11 @@ export async function listFolder(bucket: string, path?: string): Promise !!v); + return folder.filter((v: (typeof folder)[number]): v is StorageFolder => !!v); } export async function listItem(