docs: cabinet
This commit is contained in:
parent
3820a05704
commit
75025ca596
2 changed files with 72 additions and 11 deletions
|
|
@ -12,6 +12,7 @@ import {
|
|||
Tags,
|
||||
Request,
|
||||
Response,
|
||||
Example,
|
||||
} from "tsoa";
|
||||
|
||||
import minioClient from "../minio";
|
||||
|
|
@ -38,6 +39,20 @@ export class CabinetController extends Controller {
|
|||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการตู้เอกสารได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
@Example([
|
||||
{
|
||||
path: "ตู้เอกสาร 1/",
|
||||
name: "ตู้เอกสาร 1",
|
||||
createdAt: "2021-07-20T12:33:13.018Z",
|
||||
createdBy: "admin",
|
||||
},
|
||||
{
|
||||
path: "ตู้เอกสาร 2/",
|
||||
name: "ตู้เอกสาร 2",
|
||||
createdAt: "2022-01-23T16:05:02.114Z",
|
||||
createdBy: "admin",
|
||||
},
|
||||
])
|
||||
public async listCabinet(): Promise<StorageFolder[]> {
|
||||
const list = await listFolder(DEFAULT_BUCKET!).catch((e) =>
|
||||
console.error(`Error List Folder: ${e}`),
|
||||
|
|
@ -54,7 +69,13 @@ export class CabinetController extends Controller {
|
|||
@SuccessResponse(HttpStatusCode.CREATED, "สำเร็จ")
|
||||
public async createCabinet(
|
||||
@Request() request: { user: { preferred_username: string } },
|
||||
@Body() body: { name: string },
|
||||
@Body()
|
||||
body: {
|
||||
/**
|
||||
* @example "ตู้เอกสาร 1"
|
||||
*/
|
||||
name: string;
|
||||
},
|
||||
) {
|
||||
const created = await minioClient
|
||||
.putObject(DEFAULT_BUCKET!, `${replaceIllegalChars(body.name)}/.keep`, "", 0, {
|
||||
|
|
@ -68,6 +89,9 @@ export class CabinetController extends Controller {
|
|||
return this.setStatus(HttpStatusCode.CREATED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example cabinetName "ตู้เอกสาร 1"
|
||||
*/
|
||||
@Put("/{cabinetName}")
|
||||
@Tags("ตู้เอกสาร")
|
||||
@Security("bearerAuth", ["admin"])
|
||||
|
|
@ -75,7 +99,13 @@ export class CabinetController extends Controller {
|
|||
@SuccessResponse(HttpStatusCode.NO_CONTENT, "สำเร็จ")
|
||||
public async editCabinet(
|
||||
@Path() cabinetName: string,
|
||||
@Body() body: { name: string },
|
||||
@Body()
|
||||
body: {
|
||||
/**
|
||||
* @example "ตู้เอกสารใหม่"
|
||||
*/
|
||||
name: string;
|
||||
},
|
||||
): Promise<void> {
|
||||
const path = `${cabinetName}/`;
|
||||
const list = await listItem(DEFAULT_BUCKET!, path, true);
|
||||
|
|
@ -94,7 +124,9 @@ export class CabinetController extends Controller {
|
|||
return await minioClient.removeObject(DEFAULT_BUCKET!, current.name);
|
||||
}
|
||||
|
||||
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
||||
const search = await esClient.search<
|
||||
StorageFile & { attachment: Record<string, string> }
|
||||
>({
|
||||
index: DEFAULT_INDEX!,
|
||||
query: { match: { pathname: current.name } },
|
||||
});
|
||||
|
|
@ -121,6 +153,9 @@ export class CabinetController extends Controller {
|
|||
return this.setStatus(HttpStatusCode.NO_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example cabinetName "ตู้เอกสาร 1"
|
||||
*/
|
||||
@Delete("/{cabinetName}")
|
||||
@Tags("ตู้เอกสาร")
|
||||
@Security("bearerAuth", ["admin"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue