From 52c97134cbf61188d5a62c18d77b991aef83419f Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Thu, 10 Oct 2024 16:43:09 +0700 Subject: [PATCH] feat: add update status flow --- .../migration.sql | 2 + prisma/schema.prisma | 2 + src/controllers/06-request-list-controller.ts | 40 ++++++++++++++----- 3 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 prisma/migrations/20241010094304_add_flow_information_dyn/migration.sql diff --git a/prisma/migrations/20241010094304_add_flow_information_dyn/migration.sql b/prisma/migrations/20241010094304_add_flow_information_dyn/migration.sql new file mode 100644 index 0000000..499e354 --- /dev/null +++ b/prisma/migrations/20241010094304_add_flow_information_dyn/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "RequestData" ADD COLUMN "flow" JSONB; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 4cda7d2..4173445 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1202,6 +1202,8 @@ model RequestData { quotation Quotation @relation(fields: [quotationId], references: [id]) quotationId String + flow Json? + requestWork RequestWork[] } diff --git a/src/controllers/06-request-list-controller.ts b/src/controllers/06-request-list-controller.ts index 56091a0..f4e9ba9 100644 --- a/src/controllers/06-request-list-controller.ts +++ b/src/controllers/06-request-list-controller.ts @@ -1,7 +1,19 @@ -import { Controller, Delete, Get, Path, Put, Query, Request, Route, Security, Tags } from "tsoa"; +import { + Body, + Controller, + Delete, + Get, + Path, + Put, + Query, + Request, + Route, + Security, + Tags, +} from "tsoa"; import { RequestWithUser } from "../interfaces/user"; import prisma from "../db"; -import { Prisma } from "@prisma/client"; +import { Prisma, RequestWorkStatus } from "@prisma/client"; import { createPermCheck, createPermCondition } from "../services/permission"; // User in company can see. @@ -80,14 +92,24 @@ export class RequestListController extends Controller { /** @todo */ @Put("{requestId}") - async updateRequestById(@Request() req: RequestWithUser, @Path() requestId: string) { - return {}; - } + async updateRequestById( + @Request() req: RequestWithUser, + @Path() requestId: string, + @Body() payload: { status: RequestWorkStatus; attributes: Record }, + ) { + const record = await prisma.requestWork.update({ + where: { id: requestId }, + data: { + workStatus: payload.status, + request: { + update: { + flow: payload.attributes, + }, + }, + }, + }); - /** @todo */ - @Delete("{requestId}") - async deleteRequestById(@Request() req: RequestWithUser, @Path() requestId: string) { - return {}; + return record; } }