Skip to content

Commit fbeee82

Browse files
committed
add notification settings
1 parent 7e27a52 commit fbeee82

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

src/graphql/resolvers/Notification.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
/* eslint no-underscore-dangle: ["error", { "allow": ["_id"] }] */
2+
/* eslint no-param-reassign: 0 */
3+
4+
import _ from 'lodash';
25

36
export default {
4-
Query: {},
7+
Query: {
8+
notificationSettings: async (parent, args, { user }) => {
9+
if (!user) {
10+
throw new Error('no Auth');
11+
}
12+
return user.notificationSettings;
13+
},
14+
},
515

616
Mutation: {
717
addToken: async (parent, { token, os }, { user }) => {
@@ -13,5 +23,29 @@ export default {
1323
succeeded: true,
1424
};
1525
},
26+
27+
updateNotificationSettings: async (
28+
parent,
29+
{
30+
disableAll, disableUntil, procedures, tags,
31+
},
32+
{ user },
33+
) => {
34+
user.notificationSettings = {
35+
...user.notificationSettings,
36+
..._.omitBy(
37+
{
38+
disableAll,
39+
disableUntil,
40+
procedures,
41+
tags,
42+
},
43+
_.isNil,
44+
),
45+
};
46+
console.log(user);
47+
await user.save();
48+
return user.notificationSettings;
49+
},
1650
},
1751
};

src/graphql/schemas/Notification.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ export default `
44
succeeded: Boolean
55
}
66
7+
type NotificationSettings {
8+
disableAll: Boolean
9+
disableUntil: Date
10+
procedures: [String]
11+
tags: [String]
12+
}
13+
14+
type Query {
15+
notificationSettings: NotificationSettings
16+
}
17+
718
type Mutation {
819
addToken(token: String!, os: String!): TokenResult
20+
updateNotificationSettings(disableAll: String, disableUntil: Date, procedures: [String], tags: [String]): NotificationSettings
921
}
1022
1123
`;

src/models/User.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ const UserSchema = new Schema(
1313
],
1414
notificationSettings: {
1515
disableAll: { type: Boolean, default: false },
16-
disableTime: { type: Number, default: 0 },
16+
disableUntil: { type: Date },
1717
procedures: [{ type: Schema.Types.ObjectId, ref: 'Procedure' }],
1818
tags: [],
19-
terms: [],
2019
},
2120
},
2221
{ timestamps: true },

0 commit comments

Comments
 (0)