feat: check if user in in used
This commit is contained in:
parent
7f934454a9
commit
8336310e69
1 changed files with 25 additions and 3 deletions
|
|
@ -12,7 +12,7 @@ import {
|
|||
Security,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Prisma, Status } from "@prisma/client";
|
||||
|
||||
import prisma from "../../db";
|
||||
import minio from "../../services/minio";
|
||||
|
|
@ -308,8 +308,30 @@ export class UserController extends Controller {
|
|||
|
||||
@Delete("{userId}")
|
||||
async deleteUser(@Path() userId: string) {
|
||||
const result = await prisma.user.deleteMany({ where: { id: userId } });
|
||||
if (result.count <= 0)
|
||||
const record = await prisma.user.findFirst({
|
||||
include: {
|
||||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
},
|
||||
where: { id: userId },
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "data_not_found");
|
||||
}
|
||||
|
||||
if (record.status === Status.USED) {
|
||||
throw new HttpError(HttpStatus.FORBIDDEN, "User is in used.", "data_in_used");
|
||||
}
|
||||
|
||||
return await prisma.user.delete({
|
||||
include: {
|
||||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
},
|
||||
where: { id: userId },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue