feat: throw error when used institution

This commit is contained in:
Methapon2001 2025-02-10 09:54:22 +07:00
parent e9a345fc24
commit fdd48fb670

View file

@ -16,7 +16,7 @@ import {
Tags,
} from "tsoa";
import prisma from "../db";
import { notFoundError } from "../utils/error";
import { isUsedError, notFoundError } from "../utils/error";
import { queryOrNot } from "../utils/relation";
import { RequestWithUser } from "../interfaces/user";
import { deleteFile, fileLocation, getFile, getPresigned, listFile, setFile } from "../utils/minio";
@ -155,9 +155,15 @@ export class InstitutionController extends Controller {
return await prisma.$transaction(async (tx) => {
const record = await tx.institution.findFirst({
where: { id: institutionId },
include: {
taskOrder: {
take: 1,
},
},
});
if (!record) throw notFoundError("Institution");
if (record.taskOrder.length > 0) throw isUsedError("Institution");
return await tx.institution.delete({
where: { id: institutionId },