specforge-wasp / src /queries.js
designfailure's picture
Server queries: getSpecs, getSpec
ceb3d46 verified
Raw History Blame Contribute Delete
693 Bytes
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;
};