Skip to content

Commit 6cca835

Browse files
Merge pull request #498 from codex-team/feat/enable-notifications-for-new-projects
feat(notifications-for-all): Setup email notifications for newly created project
2 parents 21eabde + 9bc0cff commit 6cca835

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hawk.api",
3-
"version": "1.1.24",
3+
"version": "1.1.25",
44
"main": "index.ts",
55
"license": "UNLICENSED",
66
"scripts": {

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: 35 additions & 1 deletion
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');
@@ -55,7 +56,40 @@ module.exports = {
5556
image,
5657
};
5758

58-
const project = await factories.projectsFactory.create(options);
59+
let project = await factories.projectsFactory.create(options);
60+
const userData = await factories.usersFactory.findById(user.id);
61+
62+
try {
63+
await project.createNotificationsRule({
64+
isEnabled: true,
65+
whatToReceive: ReceiveTypes.SEEN_MORE,
66+
including: [],
67+
excluding: [],
68+
threshold: 20,
69+
thresholdPeriod: 3600000,
70+
channels: {
71+
email: {
72+
isEnabled: true,
73+
endpoint: userData.email,
74+
minPeriod: 60,
75+
},
76+
telegram: {
77+
isEnabled: false,
78+
endpoint: '',
79+
minPeriod: 60,
80+
},
81+
slack: {
82+
isEnabled: false,
83+
endpoint: '',
84+
minPeriod: 60,
85+
},
86+
},
87+
});
88+
89+
project = await factories.projectsFactory.findById(project._id);
90+
} catch (err) {
91+
telegram.sendMessage(`❌ Failed to enable default notifications for project ${name}`);
92+
}
5993

6094
/**
6195
* Create collections for storing events and setup indexes

0 commit comments

Comments
 (0)