const getAllGoalsByClientSchema = z.object({
selectedClientId: z.string(),
})
type GetAllGoalsByClientInput = z.infer<typeof getAllGoalsByClientSchema>
export const getAllGoalsByClient: GetAllGoalsByClient<GetAllGoalsByClientInput, Goal[]> = async (rawArgs, context) => {
if (!context.user) {
throw new HttpError(401, 'Only authenticated users are allowed to perform this operation')
}
const { selectedClientId } = ensureArgsSchemaOrThrowHttpError(getAllGoalsByClientSchema, rawArgs)
return context.entities.Goal.findMany({
where: { clientId: selectedClientId },
include: { objectives: true },
})
}
const getAllGoalsByClientSchema = z.object({
selectedClientId: z.string(),
})
type GetAllGoalsByClientInput = z.infer<typeof getAllGoalsByClientSchema>
export const getAllGoalsByClient: GetAllGoalsByClient<GetAllGoalsByClientInput, Goal[]> = async (rawArgs, context) => {
if (!context.user) {
throw new HttpError(401, 'Only authenticated users are allowed to perform this operation')
}
const { selectedClientId } = ensureArgsSchemaOrThrowHttpError(getAllGoalsByClientSchema, rawArgs)
return context.entities.Goal.findMany({
where: { clientId: selectedClientId },
include: { objectives: true },
})
}