57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
'use server';
|
|
// eslint-disable-next-line sonarjs/no-internal-api-use
|
|
import type * as ApolloTypes from '../../../packages/graphql/node_modules/@apollo/client/core';
|
|
import { getProfile } from './profile';
|
|
import { formatDate, formatTime } from '@/utils/date';
|
|
import * as api from '@repo/graphql/api';
|
|
import type * as GQL from '@repo/graphql/types';
|
|
|
|
type AddSlotInput = Omit<GQL.CreateSlotMutationVariables['input'], 'master'>;
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
type FixTypescriptCringe = ApolloTypes.FetchResult;
|
|
|
|
export async function addSlot(input: AddSlotInput) {
|
|
const customer = await getProfile();
|
|
|
|
return api.createSlot({
|
|
...input,
|
|
date: formatDate(input.date).db(),
|
|
master: customer?.documentId,
|
|
time_end: formatTime(input.time_end).db(),
|
|
time_start: formatTime(input.time_start).db(),
|
|
});
|
|
}
|
|
|
|
export async function getSlots(input: GQL.GetSlotsQueryVariables) {
|
|
const customer = await getProfile();
|
|
|
|
return api.getSlots({
|
|
filters: {
|
|
master: {
|
|
documentId: {
|
|
eq: customer.documentId,
|
|
},
|
|
},
|
|
...input.filters,
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function updateSlot(input: GQL.UpdateSlotMutationVariables) {
|
|
await getProfile();
|
|
|
|
return api.updateSlot({
|
|
...input,
|
|
data: {
|
|
...input.data,
|
|
date: input.data?.date ? formatDate(input.data.date).db() : undefined,
|
|
time_end: input.data?.time_end ? formatTime(input.data.time_end).db() : undefined,
|
|
time_start: input.data?.time_start ? formatTime(input.data.time_start).db() : undefined,
|
|
},
|
|
});
|
|
}
|
|
|
|
export const getSlot = api.getSlot;
|
|
export const deleteSlot = api.deleteSlot;
|