Skip to content

Commit c27afb2

Browse files
committed
Enable notifications for new projects
1 parent 21eabde commit c27afb2

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/models/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { v4 as uuid } from 'uuid';
99
*/
1010
export enum ReceiveTypes {
1111
/**
12-
* All notifications
12+
* Notify if more than n error occurrences in the given period
1313
*/
1414
SEEN_MORE = 'SEEN_MORE',
1515

src/resolvers/project.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ReceiveTypes } from '@hawk.so/types';
12
import * as telegram from '../utils/telegram';
23
const mongo = require('../mongo');
34
const { ApolloError, UserInputError } = require('apollo-server-express');
@@ -56,6 +57,33 @@ module.exports = {
5657
};
5758

5859
const project = await factories.projectsFactory.create(options);
60+
const userData = await factories.usersFactory.findById(user.id);
61+
62+
await project.createNotificationsRule({
63+
isEnabled: true,
64+
whatToReceive: ReceiveTypes.SEEN_MORE,
65+
including: [],
66+
excluding: [],
67+
threshold: 20,
68+
thresholdPeriod: 3600000,
69+
channels: {
70+
email: {
71+
isEnabled: true,
72+
endpoint: userData.email,
73+
minPeriod: 60,
74+
},
75+
telegram: {
76+
isEnabled: false,
77+
endpoint: '',
78+
minPeriod: 60,
79+
},
80+
slack: {
81+
isEnabled: false,
82+
endpoint: '',
83+
minPeriod: 60,
84+
},
85+
},
86+
});
5987

6088
/**
6189
* Create collections for storing events and setup indexes

0 commit comments

Comments
 (0)