feat: delete customer

This commit is contained in:
Methapon2001 2024-04-05 11:02:23 +07:00
parent 239582b472
commit 6e07e0658e

View file

@ -115,4 +115,19 @@ export class CustomerController extends Controller {
),
});
}
@Delete("{customerId}")
async deleteById(@Path() customerId: string) {
const record = await prisma.customer.findFirst({ where: { id: customerId } });
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "data_not_found");
}
if (record.status !== Status.CREATED) {
throw new HttpError(HttpStatus.FORBIDDEN, "Customer is in used.", "data_in_used");
}
return await prisma.customer.delete({ where: { id: customerId } });
}
}