* fix(jwt): update import path for isTokenExpired function to remove file extension * packages/graphql: add slot tests * fix(slots): update error handling for customer and slot retrieval, enhance time validation in slot updates * fix(slots): update error messages for missing datetime fields and improve validation logic in slot updates * fix(slots): update error messages and validation logic for slot creation and updates, including handling of datetime fields and master status * refactor(slots): rename checkUpdateIsTimeChanging to checkUpdateDatetime for clarity in slot update validation * test(slots): add comprehensive tests for getAvailableTimeSlots method, including edge cases and error handling * fix(api): standardize error messages for customer and slot retrieval, and improve validation logic in slots service * refactor(slots): rename validation methods for clarity and consistency in slot service * OrdersService: add checkBeforeCreate * add orders.test.js * test(orders): add validation test for missing datetime_end in order creation * feat(orders): implement updateOrder functionality with comprehensive validation tests - Added updateOrder method in OrdersService with checks for permissions, order state, and datetime validation. - Implemented tests for various scenarios including successful updates, permission errors, and validation failures. - Enhanced error handling for overlapping time and invalid state changes. - Updated GraphQL operations to support sorting in GetOrders query. * fix(orders): update datetime validation logic and test cases for order creation and completion - Modified order creation tests to set datetime_start to one hour in the past for past orders. - Updated the OrdersService to use isNowOrAfter for validating order completion against the start time. - Enhanced datetime utility function to accept a unit parameter for more flexible comparisons. * fix(calendar): initialize selected date in ScheduleCalendar component if not set - Added useEffect to set the selected date to the current date if it is not already defined. - Imported useEffect alongside useState for managing component lifecycle. * fix(order-form): initialize selected date in DateSelect component if not set - Added useEffect to set the selected date to the current date if it is not already defined. - Renamed setDate to setSelectedDate for clarity in state management. * refactor(orders): streamline order creation logic and enhance test setup - Removed redundant variable assignments in the createOrder method for cleaner code. - Updated test setup in orders.test.js to use global mocks for user and service retrieval, improving test clarity and maintainability. - Added checks for required fields in order creation to ensure data integrity.
96 lines
2.5 KiB
TypeScript
96 lines
2.5 KiB
TypeScript
import { getClientWithToken } from '../apollo/client';
|
|
import * as GQL from '../types';
|
|
import { BaseService } from './base';
|
|
import { type VariablesOf } from '@graphql-typed-document-node/core';
|
|
|
|
export class CustomersService extends BaseService {
|
|
async addMasters(variables: VariablesOf<typeof GQL.UpdateCustomerDocument>) {
|
|
const newMasterIds = variables.data.masters;
|
|
|
|
const { mutate, query } = await getClientWithToken();
|
|
const getMastersResult = await query({
|
|
query: GQL.GetMastersDocument,
|
|
variables,
|
|
});
|
|
|
|
const existingMasterIds = getMastersResult?.data?.customers
|
|
?.at(0)
|
|
?.masters.map((x) => x?.documentId);
|
|
|
|
const newMastersIds = [...new Set([...(existingMasterIds || []), ...(newMasterIds || [])])];
|
|
|
|
const mutationResult = await mutate({
|
|
mutation: GQL.UpdateCustomerDocument,
|
|
variables: {
|
|
data: { masters: newMastersIds },
|
|
documentId: variables.documentId,
|
|
},
|
|
});
|
|
|
|
const error = mutationResult.errors?.at(0);
|
|
if (error) throw new Error(error.message);
|
|
|
|
return mutationResult.data;
|
|
}
|
|
|
|
async getClients(variables?: VariablesOf<typeof GQL.GetClientsDocument>) {
|
|
const { query } = await getClientWithToken();
|
|
|
|
const result = await query({
|
|
query: GQL.GetClientsDocument,
|
|
variables,
|
|
});
|
|
|
|
const customer = result.data.customers.at(0);
|
|
|
|
return customer;
|
|
}
|
|
|
|
async getCustomer(variables: VariablesOf<typeof GQL.GetCustomerDocument>) {
|
|
const { query } = await getClientWithToken();
|
|
|
|
const result = await query({
|
|
query: GQL.GetCustomerDocument,
|
|
variables,
|
|
});
|
|
|
|
const customer = result.data.customers.at(0);
|
|
|
|
return { customer };
|
|
}
|
|
|
|
async getMasters(variables?: VariablesOf<typeof GQL.GetMastersDocument>) {
|
|
const { query } = await getClientWithToken();
|
|
|
|
const result = await query({
|
|
query: GQL.GetMastersDocument,
|
|
variables,
|
|
});
|
|
|
|
const customer = result.data.customers.at(0);
|
|
|
|
return customer;
|
|
}
|
|
|
|
async updateCustomer(
|
|
variables: Omit<VariablesOf<typeof GQL.UpdateCustomerDocument>, 'documentId'>,
|
|
) {
|
|
const { customer } = await this._getUser();
|
|
|
|
const { mutate } = await getClientWithToken();
|
|
|
|
const mutationResult = await mutate({
|
|
mutation: GQL.UpdateCustomerDocument,
|
|
variables: {
|
|
data: variables.data,
|
|
documentId: customer.documentId,
|
|
},
|
|
});
|
|
|
|
const error = mutationResult.errors?.at(0);
|
|
if (error) throw new Error(error.message);
|
|
|
|
return mutationResult.data;
|
|
}
|
|
}
|