File size: 693 Bytes
ceb3d46 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import { HttpError } from "wasp/server";
export const getSpecs = async (_args, context) => {
if (!context.user) {
throw new HttpError(401);
}
return context.entities.Spec.findMany({
where: { userId: context.user.id },
orderBy: { updatedAt: "desc" },
include: { sections: { orderBy: { order: "asc" } } },
});
};
export const getSpec = async ({ id }, context) => {
if (!context.user) {
throw new HttpError(401);
}
const spec = await context.entities.Spec.findFirst({
where: { id, userId: context.user.id },
include: { sections: { orderBy: { order: "asc" } } },
});
if (!spec) {
throw new HttpError(404, "Spec not found");
}
return spec;
}; |