57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
'use server';
|
|
import { getClientWithToken } from '../apollo/client';
|
|
import * as GQL from '../types';
|
|
|
|
export async function createSlot(input: GQL.CreateSlotMutationVariables['input']) {
|
|
const { mutate } = await getClientWithToken();
|
|
|
|
// TODO: check slot does not overlap with others
|
|
|
|
return mutate({
|
|
mutation: GQL.CreateSlotDocument,
|
|
variables: { input },
|
|
}).catch((err) => {
|
|
console.error(JSON.stringify(err, null, 2));
|
|
});
|
|
}
|
|
|
|
export async function getSlots(input: GQL.GetSlotsQueryVariables) {
|
|
const { query } = await getClientWithToken();
|
|
|
|
const response = await query({
|
|
query: GQL.GetSlotsDocument,
|
|
variables: input,
|
|
});
|
|
|
|
return response?.data?.slots;
|
|
}
|
|
|
|
export async function getSlot(input: GQL.GetSlotQueryVariables) {
|
|
const { query } = await getClientWithToken();
|
|
|
|
const response = await query({
|
|
query: GQL.GetSlotDocument,
|
|
variables: input,
|
|
});
|
|
|
|
return response?.data;
|
|
}
|
|
|
|
export async function updateSlot(input: GQL.UpdateSlotMutationVariables) {
|
|
const { mutate } = await getClientWithToken();
|
|
|
|
return mutate({
|
|
mutation: GQL.UpdateSlotDocument,
|
|
variables: input,
|
|
});
|
|
}
|
|
|
|
export async function deleteSlot(input: GQL.DeleteSlotMutationVariables) {
|
|
const { mutate } = await getClientWithToken();
|
|
|
|
return mutate({
|
|
mutation: GQL.DeleteSlotDocument,
|
|
variables: input,
|
|
});
|
|
}
|