refactor: word
This commit is contained in:
parent
d8cf568206
commit
3820a05704
12 changed files with 56 additions and 56 deletions
|
|
@ -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<EhrFolder[]> {
|
||||
public async listCabinet(): Promise<StorageFolder[]> {
|
||||
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<EhrFile & { attachment: Record<string, string> }>({
|
||||
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
||||
index: DEFAULT_INDEX!,
|
||||
query: { match: { pathname: current.name } },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<EhrFolder[]> {
|
||||
public async listDrawer(@Path() cabinetName: string): Promise<StorageFolder[]> {
|
||||
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<EhrFile & { attachment: Record<string, string> }>({
|
||||
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
||||
index: DEFAULT_INDEX!,
|
||||
query: { match: { pathname: current.name } },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<EhrFile[]> {
|
||||
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
||||
): Promise<StorageFile[]> {
|
||||
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
||||
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<EhrFile & { attachment?: Record<string, unknown> }>({
|
||||
.search<StorageFile & { attachment?: Record<string, unknown> }>({
|
||||
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<EhrFile> = {
|
||||
const metadata: Partial<StorageFile> = {
|
||||
pathname,
|
||||
fileName: body.file,
|
||||
fileSize: 0,
|
||||
|
|
@ -185,7 +185,7 @@ export class FileController extends Controller {
|
|||
|
||||
if (copy) {
|
||||
const search = await esClient
|
||||
.search<EhrFile & { attachment?: Record<string, unknown> }>({
|
||||
.search<StorageFile & { attachment?: Record<string, unknown> }>({
|
||||
index: DEFAULT_INDEX!,
|
||||
query: { match: { pathname } },
|
||||
})
|
||||
|
|
@ -210,7 +210,7 @@ export class FileController extends Controller {
|
|||
}
|
||||
} else {
|
||||
const search = await esClient
|
||||
.search<EhrFile & { attachment?: Record<string, unknown> }>({
|
||||
.search<StorageFile & { attachment?: Record<string, unknown> }>({
|
||||
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<EhrFile & { attachment: Record<string, string> }>({
|
||||
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
||||
index: DEFAULT_INDEX!,
|
||||
query: {
|
||||
match: { pathname: `${cabinetName}/${drawerName}/${folderName}/${fileName}` },
|
||||
|
|
|
|||
|
|
@ -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<EhrFolder[]> {
|
||||
): Promise<StorageFolder[]> {
|
||||
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<EhrFile & { attachment: Record<string, string> }>({
|
||||
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
||||
index: DEFAULT_INDEX!,
|
||||
query: { match: { pathname: current.name } },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<EhrFile[]> {
|
||||
const result = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
||||
public async searchFile(@Body() search: Search): Promise<StorageFile[]> {
|
||||
const result = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
||||
index: DEFAULT_INDEX,
|
||||
query: {
|
||||
bool: {
|
||||
|
|
|
|||
|
|
@ -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<EhrFolder[]> {
|
||||
): Promise<StorageFolder[]> {
|
||||
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<EhrFile & { attachment: Record<string, string> }>({
|
||||
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
||||
index: DEFAULT_INDEX!,
|
||||
query: { match: { pathname: current.name } },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<EhrFile[]> {
|
||||
const search = await esClient.search<EhrFile & { attachment: Record<string, string> }>({
|
||||
): Promise<StorageFile[]> {
|
||||
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
||||
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<EhrFile & { attachment?: Record<string, unknown> }>({
|
||||
.search<StorageFile & { attachment?: Record<string, unknown> }>({
|
||||
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<EhrFile> = {
|
||||
const metadata: Partial<StorageFile> = {
|
||||
pathname,
|
||||
fileName: body.file,
|
||||
fileSize: 0,
|
||||
|
|
@ -190,7 +190,7 @@ export class SubFolderFileController extends Controller {
|
|||
|
||||
if (copy) {
|
||||
const search = await esClient
|
||||
.search<EhrFile & { attachment?: Record<string, unknown> }>({
|
||||
.search<StorageFile & { attachment?: Record<string, unknown> }>({
|
||||
index: DEFAULT_INDEX!,
|
||||
query: { match: { pathname } },
|
||||
})
|
||||
|
|
@ -215,7 +215,7 @@ export class SubFolderFileController extends Controller {
|
|||
}
|
||||
} else {
|
||||
const search = await esClient
|
||||
.search<EhrFile & { attachment?: Record<string, unknown> }>({
|
||||
.search<StorageFile & { attachment?: Record<string, unknown> }>({
|
||||
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<EhrFile & { attachment: Record<string, string> }>({
|
||||
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
||||
index: DEFAULT_INDEX!,
|
||||
query: {
|
||||
match: {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
|
|
@ -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<boolean> {
|
|||
// Get info and delete it from ElasticSearch to re-index
|
||||
async function popInfo(pathname: string) {
|
||||
const result = await esClient
|
||||
.search<EhrFile & { attachment?: Record<string, unknown> }>({
|
||||
.search<StorageFile & { attachment?: Record<string, unknown> }>({
|
||||
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<EhrFile>;
|
||||
} satisfies Partial<StorageFile>;
|
||||
|
||||
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 },
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -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},
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<boolean> {
|
|||
* @param path - path to list
|
||||
* @return list of folder with metadata
|
||||
*/
|
||||
export async function listFolder(bucket: string, path?: string): Promise<EhrFolder[]> {
|
||||
export async function listFolder(bucket: string, path?: string): Promise<StorageFolder[]> {
|
||||
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<EhrFold
|
|||
...v,
|
||||
createdAt: createdat ?? "n/a",
|
||||
createdBy: createdby ?? "n/a",
|
||||
} satisfies EhrFolder;
|
||||
} satisfies StorageFolder;
|
||||
}),
|
||||
);
|
||||
|
||||
return folder.filter((v: (typeof folder)[number]): v is EhrFolder => !!v);
|
||||
return folder.filter((v: (typeof folder)[number]): v is StorageFolder => !!v);
|
||||
}
|
||||
|
||||
export async function listItem(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue