From bc13f0e5ce4b9b7dfb17a642f430777ef7734f57 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Mon, 27 Nov 2023 17:30:20 +0700 Subject: [PATCH] refactor: optional metadata field (for file upload only) --- .../server/src/controllers/fileController.ts | 17 +++++++++-------- .../controllers/subFolderFileController.ts | 16 ++++++++-------- Services/server/src/routes.ts | 4 ++-- Services/server/src/swagger.json | 19 +++---------------- 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/Services/server/src/controllers/fileController.ts b/Services/server/src/controllers/fileController.ts index 945917c..4ecf5cb 100644 --- a/Services/server/src/controllers/fileController.ts +++ b/Services/server/src/controllers/fileController.ts @@ -75,10 +75,10 @@ export class FileController extends Controller { @Body() body: { file: string; - title: string; - description: string; - category: string; - keyword: string; + title?: string; + description?: string; + category?: string; + keyword?: string; }, @Path() cabinetName: string, @Path() drawerName: string, @@ -118,10 +118,10 @@ export class FileController extends Controller { fileName: body.file, fileSize: 0, fileType: "", - title: body.title, - description: body.description, - category: body.category.split(","), - keyword: body.keyword.split(","), + title: body.title ?? "", + description: body.description ?? "", + category: body.category?.split(",") ?? [], + keyword: body.keyword?.split(",") ?? [], upload: false, createdAt: new Date().toISOString(), createdBy: rec ? rec.createdBy : "n/a", @@ -148,6 +148,7 @@ export class FileController extends Controller { @Tags("ไฟล์") @Security("bearerAuth", ["admin"]) @Response(HttpStatusCode.NOT_FOUND, "ไม่พบตำแหน่งที่ต้องการสร้างแฟ้ม") + @Response(HttpStatusCode.NO_CONTENT, "สำเร็จ") @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") public async updateFile( @Request() request: { user: { preferred_username: string } }, diff --git a/Services/server/src/controllers/subFolderFileController.ts b/Services/server/src/controllers/subFolderFileController.ts index 19c5def..7d9ca33 100644 --- a/Services/server/src/controllers/subFolderFileController.ts +++ b/Services/server/src/controllers/subFolderFileController.ts @@ -78,10 +78,10 @@ export class SubFolderFileController extends Controller { @Body() body: { file: string; - title: string; - description: string; - category: string; - keyword: string; + title?: string; + description?: string; + category?: string; + keyword?: string; }, @Path() cabinetName: string, @Path() drawerName: string, @@ -122,10 +122,10 @@ export class SubFolderFileController extends Controller { fileName: body.file, fileSize: 0, fileType: "", - title: body.title, - description: body.description, - category: body.category.split(","), - keyword: body.keyword.split(","), + title: body.title ?? "", + description: body.description ?? "", + category: body.category?.split(",") ?? [], + keyword: body.keyword?.split(",") ?? [], upload: false, createdAt: new Date().toISOString(), createdBy: rec ? rec.createdBy : "n/a", diff --git a/Services/server/src/routes.ts b/Services/server/src/routes.ts index 2dfd5a0..845fb8b 100644 --- a/Services/server/src/routes.ts +++ b/Services/server/src/routes.ts @@ -326,7 +326,7 @@ export function RegisterRoutes(app: Router) { function FileController_uploadFile(request: any, response: any, next: any) { const args = { request: {"in":"request","name":"request","required":true,"dataType":"object"}, - body: {"in":"body","name":"body","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"keyword":{"dataType":"string","required":true},"category":{"dataType":"string","required":true},"description":{"dataType":"string","required":true},"title":{"dataType":"string","required":true},"file":{"dataType":"string","required":true}}}, + body: {"in":"body","name":"body","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"keyword":{"dataType":"string"},"category":{"dataType":"string"},"description":{"dataType":"string"},"title":{"dataType":"string"},"file":{"dataType":"string","required":true}}}, cabinetName: {"in":"path","name":"cabinetName","required":true,"dataType":"string"}, drawerName: {"in":"path","name":"drawerName","required":true,"dataType":"string"}, folderName: {"in":"path","name":"folderName","required":true,"dataType":"string"}, @@ -730,7 +730,7 @@ export function RegisterRoutes(app: Router) { function SubFolderFileController_uploadFile(request: any, response: any, next: any) { const args = { request: {"in":"request","name":"request","required":true,"dataType":"object"}, - body: {"in":"body","name":"body","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"keyword":{"dataType":"string","required":true},"category":{"dataType":"string","required":true},"description":{"dataType":"string","required":true},"title":{"dataType":"string","required":true},"file":{"dataType":"string","required":true}}}, + body: {"in":"body","name":"body","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"keyword":{"dataType":"string"},"category":{"dataType":"string"},"description":{"dataType":"string"},"title":{"dataType":"string"},"file":{"dataType":"string","required":true}}}, cabinetName: {"in":"path","name":"cabinetName","required":true,"dataType":"string"}, drawerName: {"in":"path","name":"drawerName","required":true,"dataType":"string"}, folderName: {"in":"path","name":"folderName","required":true,"dataType":"string"}, diff --git a/Services/server/src/swagger.json b/Services/server/src/swagger.json index 08bfd48..ebdf260 100644 --- a/Services/server/src/swagger.json +++ b/Services/server/src/swagger.json @@ -692,10 +692,6 @@ } }, "required": [ - "keyword", - "category", - "description", - "title", "file", "upload", "updatedBy", @@ -771,10 +767,6 @@ } }, "required": [ - "keyword", - "category", - "description", - "title", "file" ], "type": "object" @@ -811,6 +803,9 @@ } } }, + "204": { + "description": "สำเร็จ" + }, "404": { "description": "ไม่พบตำแหน่งที่ต้องการสร้างแฟ้ม" } @@ -1772,10 +1767,6 @@ } }, "required": [ - "keyword", - "category", - "description", - "title", "file", "upload", "updatedBy", @@ -1859,10 +1850,6 @@ } }, "required": [ - "keyword", - "category", - "description", - "title", "file" ], "type": "object"