refactor(slots): rename validation methods for clarity and consistency in slot service
This commit is contained in:
parent
d8e88d8934
commit
81dfdec7a5
@ -24,7 +24,7 @@ export const ERRORS = {
|
||||
|
||||
export class SlotsService extends BaseService {
|
||||
async createSlot(variables: VariablesOf<typeof GQL.CreateSlotDocument>) {
|
||||
await this.checkCreate(variables);
|
||||
await this.checkBeforeCreate(variables);
|
||||
|
||||
const { customer } = await this._getUser();
|
||||
|
||||
@ -48,7 +48,7 @@ export class SlotsService extends BaseService {
|
||||
}
|
||||
|
||||
async deleteSlot(variables: VariablesOf<typeof GQL.DeleteSlotDocument>) {
|
||||
await this.checkUpdatePermission(variables);
|
||||
await this.checkPermission(variables);
|
||||
|
||||
const { slot } = await this.getSlot({ documentId: variables.documentId });
|
||||
|
||||
@ -158,8 +158,8 @@ export class SlotsService extends BaseService {
|
||||
}
|
||||
|
||||
async updateSlot(variables: VariablesOf<typeof GQL.UpdateSlotDocument>) {
|
||||
await this.checkUpdatePermission(variables);
|
||||
await this.checkUpdateDatetime(variables);
|
||||
await this.checkPermission(variables);
|
||||
await this.checkBeforeUpdateDatetime(variables);
|
||||
|
||||
const { mutate } = await getClientWithToken();
|
||||
|
||||
@ -174,7 +174,7 @@ export class SlotsService extends BaseService {
|
||||
return mutationResult.data;
|
||||
}
|
||||
|
||||
private async checkCreate(variables: VariablesOf<typeof GQL.CreateSlotDocument>) {
|
||||
private async checkBeforeCreate(variables: VariablesOf<typeof GQL.CreateSlotDocument>) {
|
||||
const { datetime_end, datetime_start } = variables.input;
|
||||
|
||||
if (!datetime_start) throw new Error(ERRORS.MISSING_DATETIME_START);
|
||||
@ -216,7 +216,7 @@ export class SlotsService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
private async checkUpdateDatetime(variables: VariablesOf<typeof GQL.UpdateSlotDocument>) {
|
||||
private async checkBeforeUpdateDatetime(variables: VariablesOf<typeof GQL.UpdateSlotDocument>) {
|
||||
const { slot } = await this.getSlot({ documentId: variables.documentId });
|
||||
|
||||
if (!slot) throw new Error(ERRORS.NOT_FOUND_SLOT);
|
||||
@ -269,7 +269,7 @@ export class SlotsService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
private async checkUpdatePermission(
|
||||
private async checkPermission(
|
||||
variables: Pick<VariablesOf<typeof GQL.GetSlotDocument>, 'documentId'>,
|
||||
) {
|
||||
const { customer } = await this._getUser();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user