File tree Expand file tree Collapse file tree 4 files changed +36
-3
lines changed
Expand file tree Collapse file tree 4 files changed +36
-3
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " hawk.api" ,
3- "version" : " 1.1.26 " ,
3+ "version" : " 1.1.27 " ,
44 "main" : " index.ts" ,
55 "license" : " UNLICENSED" ,
66 "scripts" : {
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff line change @@ -242,5 +242,25 @@ export default {
242242
243243 return project . toggleNotificationsRuleEnabledState ( input . ruleId ) ;
244244 } ,
245+
246+ /**
247+ * Unsubscribes from notifications by disabling the rule
248+ * @param _obj - parent object
249+ * @param factories - factories for working with models
250+ * @param input - input data for unsubscribing
251+ */
252+ async unsubscribeFromNotifications (
253+ _obj : undefined ,
254+ { input } : { input : ProjectNotificationsRulePointer } ,
255+ { factories } : ResolverContextWithUser
256+ ) : Promise < ProjectNotificationsRuleDBScheme | null > {
257+ const project = await factories . projectsFactory . findById ( input . projectId ) ;
258+
259+ if ( ! project ) {
260+ throw new ApolloError ( 'No project with such id' ) ;
261+ }
262+
263+ return project . toggleNotificationsRuleEnabledState ( input . ruleId , false ) ;
264+ } ,
245265 } ,
246266} ;
Original file line number Diff line number Diff 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
146154 }
147155` ;
You can’t perform that action at this time.
0 commit comments