Skip to content

Commit 6824575

Browse files
committed
better activityIndex handling
1 parent d6268c1 commit 6824575

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/graphql/resolvers/Activity.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ export default {
88
}
99
const procedure = await ProcedureModel.findOne({ procedureId });
1010
const activityIndex = await ActivityModel.find({ procedure }).count();
11+
const active = await ActivityModel.findOne({
12+
user,
13+
procedure,
14+
});
1115
return {
1216
activityIndex,
17+
active: !!active,
1318
};
1419
},
1520
},
@@ -23,15 +28,15 @@ export default {
2328
if (!procedure) {
2429
throw new Error('Procedure not found');
2530
}
26-
const activity = await ActivityModel.findOne({
31+
let active = await ActivityModel.findOne({
2732
user,
2833
procedure,
2934
});
30-
if (!activity) {
31-
await ActivityModel.create({ user, procedure });
35+
if (!active) {
36+
active = await ActivityModel.create({ user, procedure });
3237
}
3338
const activityIndex = await ActivityModel.find({ procedure }).count();
34-
return { activityIndex };
39+
return { activityIndex, active };
3540
},
3641
},
3742
};

src/graphql/resolvers/Procedure.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,28 @@ export default {
8080
.limit(pageSize - activeVotings.length)
8181
.then(finishedVotings => [...activeVotings, ...finishedVotings]);
8282
},
83+
8384
procedure: async (parent, { id }, { ProcedureModel }) =>
8485
ProcedureModel.findOne({ procedureId: id }),
86+
8587
searchProcedures: (parent, { term }, { ProcedureModel }) =>
8688
ProcedureModel.find(
8789
{ $text: { $search: term }, period: 19 },
8890
{ score: { $meta: 'textScore' } },
8991
).sort({ score: { $meta: 'textScore' } }),
9092
},
93+
94+
Procedure: {
95+
activityIndex: async (procedure, args, { ActivityModel, user }) => {
96+
const activityIndex = await ActivityModel.find({ procedure }).count();
97+
const active = await ActivityModel.findOne({
98+
user,
99+
procedure,
100+
});
101+
return {
102+
activityIndex,
103+
active: !!active,
104+
};
105+
},
106+
},
91107
};

src/graphql/schemas/Activity.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export default `
22
33
type ActivityIndex {
44
activityIndex: Int
5+
active: Boolean
56
}
67
78
type Query {

src/graphql/schemas/Procedure.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Procedure {
1717
voteDate: Date
1818
subjectGroups: [String]
1919
submissionDate: Date
20-
activityIndex: Int
20+
activityIndex: ActivityIndex
2121
importantDocuments: [Document]
2222
}
2323

0 commit comments

Comments
 (0)