feat: institution status
This commit is contained in:
parent
fdd48fb670
commit
cfc531d312
3 changed files with 25 additions and 3 deletions
|
|
@ -986,6 +986,9 @@ model Institution {
|
|||
subDistrict SubDistrict @relation(fields: [subDistrictId], references: [id], onDelete: Cascade)
|
||||
subDistrictId String
|
||||
|
||||
status Status @default(CREATED)
|
||||
statusOrder Int @default(0)
|
||||
|
||||
selectedImage String?
|
||||
|
||||
taskOrder TaskOrder[]
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import { RequestWithUser } from "../interfaces/user";
|
|||
import { deleteFile, fileLocation, getFile, getPresigned, listFile, setFile } from "../utils/minio";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import { Status } from "../generated/kysely/types";
|
||||
|
||||
type InstitutionPayload = {
|
||||
name: string;
|
||||
|
|
@ -115,7 +116,12 @@ export class InstitutionController extends Controller {
|
|||
@Post()
|
||||
@Security("keycloak")
|
||||
@OperationId("createInstitution")
|
||||
async createInstitution(@Body() body: InstitutionPayload) {
|
||||
async createInstitution(
|
||||
@Body()
|
||||
body: InstitutionPayload & {
|
||||
status?: Status;
|
||||
},
|
||||
) {
|
||||
return await prisma.$transaction(async (tx) => {
|
||||
const last = await tx.runningNo.upsert({
|
||||
where: {
|
||||
|
|
@ -141,7 +147,13 @@ export class InstitutionController extends Controller {
|
|||
@Put("{institutionId}")
|
||||
@Security("keycloak")
|
||||
@OperationId("updateInstitution")
|
||||
async updateInstitution(@Path() institutionId: string, @Body() body: InstitutionPayload) {
|
||||
async updateInstitution(
|
||||
@Path() institutionId: string,
|
||||
@Body()
|
||||
body: InstitutionPayload & {
|
||||
status?: "ACTIVE" | "INACTIVE";
|
||||
},
|
||||
) {
|
||||
return await prisma.institution.update({
|
||||
where: { id: institutionId },
|
||||
data: body,
|
||||
|
|
@ -163,7 +175,9 @@ export class InstitutionController extends Controller {
|
|||
});
|
||||
|
||||
if (!record) throw notFoundError("Institution");
|
||||
if (record.taskOrder.length > 0) throw isUsedError("Institution");
|
||||
if (record.status !== "CREATED" || record.taskOrder.length > 0) {
|
||||
throw isUsedError("Institution");
|
||||
}
|
||||
|
||||
return await tx.institution.delete({
|
||||
where: { id: institutionId },
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import {
|
|||
QuotationStatus,
|
||||
RequestDataStatus,
|
||||
RequestWorkStatus,
|
||||
Status,
|
||||
TaskOrderStatus,
|
||||
TaskStatus,
|
||||
UserTaskStatus,
|
||||
|
|
@ -295,6 +296,10 @@ export class TaskController extends Controller {
|
|||
"requestWorkMustReady",
|
||||
);
|
||||
}
|
||||
await tx.institution.updateMany({
|
||||
where: { id: body.institutionId, status: Status.CREATED },
|
||||
data: { status: Status.ACTIVE },
|
||||
});
|
||||
|
||||
const work = await tx.requestWorkStepStatus.findMany({
|
||||
include: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue