feat: add update status flow

This commit is contained in:
Methapon Metanipat 2024-10-10 16:43:09 +07:00
parent 7413b2a8f8
commit 52c97134cb
3 changed files with 35 additions and 9 deletions

View file

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "RequestData" ADD COLUMN "flow" JSONB;

View file

@ -1202,6 +1202,8 @@ model RequestData {
quotation Quotation @relation(fields: [quotationId], references: [id])
quotationId String
flow Json?
requestWork RequestWork[]
}

View file

@ -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<string, any> },
) {
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;
}
}