Skip to content

Commit 229edac

Browse files
committed
add notify a procedure
1 parent 5921b41 commit 229edac

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

src/graphql/resolvers/Notification.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export default {
1515

1616
Mutation: {
1717
addToken: async (parent, { token, os }, { user }) => {
18+
if (!user) {
19+
throw new Error('no Auth');
20+
}
1821
if (!user.pushTokens.some(t => t.token === token)) {
1922
user.pushTokens.push({ token, os });
2023
user.save();
@@ -31,6 +34,9 @@ export default {
3134
},
3235
{ user },
3336
) => {
37+
if (!user) {
38+
throw new Error('no Auth');
39+
}
3440
user.notificationSettings = {
3541
...user.notificationSettings,
3642
..._.omitBy(
@@ -45,20 +51,27 @@ export default {
4551
_.isNil,
4652
),
4753
};
48-
console.log(_.omitBy(
49-
{
50-
enabled,
51-
disableUntil,
52-
procedures,
53-
tags,
54-
newVote,
55-
newPreperation,
56-
},
57-
_.isNil,
58-
));
59-
console.log(user);
6054
await user.save();
6155
return user.notificationSettings;
6256
},
57+
58+
toggleNotification: async (parent, { procedureId }, { user, ProcedureModel }) => {
59+
if (!user) {
60+
throw new Error('no Auth');
61+
}
62+
const procedure = await ProcedureModel.findOne({ procedureId });
63+
64+
const index = user.notificationSettings.procedures.indexOf(procedure._id);
65+
let notify;
66+
if (index > -1) {
67+
notify = false;
68+
user.notificationSettings.procedures.splice(index, 1);
69+
} else {
70+
notify = true;
71+
user.notificationSettings.procedures.push(procedure._id);
72+
}
73+
await user.save();
74+
return { ...procedure.toObject(), notify };
75+
},
6376
},
6477
};

src/graphql/resolvers/Procedure.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@ export default {
123123
.then(finishedVotings => [...activeVotings, ...finishedVotings]);
124124
},
125125

126-
procedure: async (parent, { id }, { ProcedureModel }) =>
127-
ProcedureModel.findOne({ procedureId: id }),
126+
procedure: async (parent, { id }, { user, ProcedureModel }) => {
127+
const procedure = await ProcedureModel.findOne({ procedureId: id });
128+
return {
129+
...procedure.toObject(),
130+
notify: !!(user && user.notificationSettings.procedures.indexOf(procedure._id) > -1),
131+
};
132+
},
128133

129134
searchProcedures: (parent, { term }, { ProcedureModel }) =>
130135
ProcedureModel.find(

src/graphql/schemas/Notification.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default `
1919
2020
type Mutation {
2121
addToken(token: String!, os: String!): TokenResult
22+
2223
updateNotificationSettings(
2324
enabled: Boolean,
2425
newVote: Boolean,
@@ -27,6 +28,8 @@ export default `
2728
procedures: [String],
2829
tags: [String]
2930
): NotificationSettings
31+
32+
toggleNotification(procedureId: String!): Procedure
3033
}
3134
3235
`;

src/graphql/schemas/Procedure.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ type Procedure {
1919
submissionDate: Date
2020
activityIndex: ActivityIndex
2121
importantDocuments: [Document]
22-
voteResults: VoteResult
22+
voteResults: VoteResult,
23+
notify: Boolean
2324
}
2425
2526
type Query {

0 commit comments

Comments
 (0)