designfailure commited on
Commit
ceb3d46
·
verified ·
1 Parent(s): 5e1a091

Server queries: getSpecs, getSpec

Browse files
Files changed (1) hide show
  1. src/queries.js +26 -0
src/queries.js ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { HttpError } from "wasp/server";
2
+
3
+ export const getSpecs = async (_args, context) => {
4
+ if (!context.user) {
5
+ throw new HttpError(401);
6
+ }
7
+ return context.entities.Spec.findMany({
8
+ where: { userId: context.user.id },
9
+ orderBy: { updatedAt: "desc" },
10
+ include: { sections: { orderBy: { order: "asc" } } },
11
+ });
12
+ };
13
+
14
+ export const getSpec = async ({ id }, context) => {
15
+ if (!context.user) {
16
+ throw new HttpError(401);
17
+ }
18
+ const spec = await context.entities.Spec.findFirst({
19
+ where: { id, userId: context.user.id },
20
+ include: { sections: { orderBy: { order: "asc" } } },
21
+ });
22
+ if (!spec) {
23
+ throw new HttpError(404, "Spec not found");
24
+ }
25
+ return spec;
26
+ };