feat: throw error when used institution
This commit is contained in:
parent
e9a345fc24
commit
fdd48fb670
1 changed files with 7 additions and 1 deletions
|
|
@ -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 },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue