Skip to content

Commit 7550599

Browse files
committed
Support unsubscribeFromNotifications
1 parent cd4e426 commit 7550599

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/models/project.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,20 @@ export default class ProjectModel extends AbstractModel<ProjectDBScheme> impleme
426426
/**
427427
* Toggles enabled state of the notifications rule
428428
* @param ruleId - rule id to update
429+
* @param status - new isEnabled status of the rule
429430
*/
430-
public async toggleNotificationsRuleEnabledState(ruleId: string): Promise<ProjectNotificationsRuleDBScheme | null> {
431+
public async toggleNotificationsRuleEnabledState(ruleId: string, status?: boolean): Promise<ProjectNotificationsRuleDBScheme | null> {
431432
const rule = this.notifications.find(_rule => _rule._id.toString() === ruleId);
432433

433434
if (!rule) {
434435
return null;
435436
}
436437

437-
rule.isEnabled = !rule.isEnabled;
438+
if (status !== undefined) {
439+
rule.isEnabled = status;
440+
} else {
441+
rule.isEnabled = !rule.isEnabled;
442+
}
438443

439444
const result = await this.collection.findOneAndUpdate(
440445
{

src/resolvers/projectNotifications.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,19 @@ export default {
242242

243243
return project.toggleNotificationsRuleEnabledState(input.ruleId);
244244
},
245+
246+
async unsubscribeFromNotifications(
247+
_obj: undefined,
248+
{ input }: { input: ProjectNotificationsRulePointer },
249+
{ factories }: ResolverContextWithUser
250+
): Promise<ProjectNotificationsRuleDBScheme | null> {
251+
const project = await factories.projectsFactory.findById(input.projectId);
252+
253+
if (!project) {
254+
throw new ApolloError('No project with such id');
255+
}
256+
257+
return project.toggleNotificationsRuleEnabledState(input.ruleId, false);
258+
},
245259
},
246260
};

src/typeDefs/projectNotificationsMutations.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,13 @@ export default gql`
143143
"Data for toggling"
144144
input: ProjectNotificationRulePointer
145145
): ProjectNotificationsRule @requireAdmin
146+
147+
"""
148+
Unsubscribes from notifications by disabling the rule
149+
"""
150+
unsubscribeFromNotifications(
151+
"Data for unsubscribing"
152+
input: ProjectNotificationRulePointer!
153+
): ProjectNotificationsRule @requireAdmin
146154
}
147155
`;

0 commit comments

Comments
 (0)