Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawk.api",
"version": "1.1.26",
"version": "1.1.27",
"main": "index.ts",
"license": "UNLICENSED",
"scripts": {
Expand Down
9 changes: 7 additions & 2 deletions src/models/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,20 @@ export default class ProjectModel extends AbstractModel<ProjectDBScheme> impleme
/**
* Toggles enabled state of the notifications rule
* @param ruleId - rule id to update
* @param status - new isEnabled status of the rule
*/
public async toggleNotificationsRuleEnabledState(ruleId: string): Promise<ProjectNotificationsRuleDBScheme | null> {
public async toggleNotificationsRuleEnabledState(ruleId: string, status?: boolean): Promise<ProjectNotificationsRuleDBScheme | null> {
const rule = this.notifications.find(_rule => _rule._id.toString() === ruleId);

if (!rule) {
return null;
}

rule.isEnabled = !rule.isEnabled;
if (status !== undefined) {
rule.isEnabled = status;
} else {
rule.isEnabled = !rule.isEnabled;
}

const result = await this.collection.findOneAndUpdate(
{
Expand Down
20 changes: 20 additions & 0 deletions src/resolvers/projectNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,25 @@ export default {

return project.toggleNotificationsRuleEnabledState(input.ruleId);
},

/**
* Unsubscribes from notifications by disabling the rule
* @param _obj - parent object
* @param factories - factories for working with models
* @param input - input data for unsubscribing
*/
async unsubscribeFromNotifications(
_obj: undefined,
{ input }: { input: ProjectNotificationsRulePointer },
{ factories }: ResolverContextWithUser
): Promise<ProjectNotificationsRuleDBScheme | null> {
const project = await factories.projectsFactory.findById(input.projectId);

if (!project) {
throw new ApolloError('No project with such id');
}

return project.toggleNotificationsRuleEnabledState(input.ruleId, false);
},
},
};
8 changes: 8 additions & 0 deletions src/typeDefs/projectNotificationsMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,13 @@ export default gql`
"Data for toggling"
input: ProjectNotificationRulePointer
): ProjectNotificationsRule @requireAdmin

"""
Unsubscribes from notifications by disabling the rule
"""
unsubscribeFromNotifications(
"Data for unsubscribing"
input: ProjectNotificationRulePointer!
): ProjectNotificationsRule
}
`;
Loading