feat(slots): add error handling for slot deletion when orders are present
This commit is contained in:
parent
6c4e6113f6
commit
ee6ccbef84
@ -7,6 +7,7 @@ import { getMinutes } from '@repo/utils/datetime-format';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
const ERRORS = {
|
||||
HAS_ORDERS: 'Slot has orders',
|
||||
MISSING_DATE: 'Missing date',
|
||||
MISSING_SERVICE: 'Missing service',
|
||||
MISSING_SERVICE_ID: 'Missing service id',
|
||||
@ -39,6 +40,12 @@ export class SlotsService extends BaseService {
|
||||
async deleteSlot(variables: VariablesOf<typeof GQL.DeleteSlotDocument>) {
|
||||
await this.checkPermission(variables);
|
||||
|
||||
const { slot } = await this.getSlot({ documentId: variables.documentId });
|
||||
|
||||
if (slot?.orders?.length) {
|
||||
throw new Error(ERRORS.HAS_ORDERS);
|
||||
}
|
||||
|
||||
const { mutate } = await getClientWithToken();
|
||||
|
||||
const mutationResult = await mutate({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user