Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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.25",
"version": "1.1.26",
"main": "index.ts",
"license": "UNLICENSED",
"scripts": {
Expand Down
7 changes: 6 additions & 1 deletion src/models/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ export default class ProjectModel extends AbstractModel<ProjectDBScheme> impleme
/**
* Creates new notification rule and add it to start of the array of notifications rules
* @param payload - rule data to save
* @param isAutoAdded - true when rule is created automatically (on project creation or conversion of old projects)
*/
public async createNotificationsRule(payload: CreateProjectNotificationsRulePayload): Promise<ProjectNotificationsRuleDBScheme> {
public async createNotificationsRule(payload: CreateProjectNotificationsRulePayload, isAutoAdded = false): Promise<ProjectNotificationsRuleDBScheme> {
const rule: ProjectNotificationsRuleDBScheme = {
_id: new ObjectId(),
uidAdded: new ObjectId(payload.uidAdded),
Expand All @@ -247,6 +248,10 @@ export default class ProjectModel extends AbstractModel<ProjectDBScheme> impleme
excluding: payload.excluding,
};

if (isAutoAdded) {
rule.autoAdded = '$$NOW';
}

if (rule.whatToReceive === ReceiveTypes.SEEN_MORE) {
rule.threshold = payload.threshold;
rule.thresholdPeriod = payload.thresholdPeriod;
Expand Down
3 changes: 2 additions & 1 deletion src/resolvers/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module.exports = {

try {
await project.createNotificationsRule({
uidAdded: user.id,
isEnabled: true,
whatToReceive: ReceiveTypes.SEEN_MORE,
including: [],
Expand All @@ -84,7 +85,7 @@ module.exports = {
minPeriod: 60,
},
},
});
}, true);

project = await factories.projectsFactory.findById(project._id);
} catch (err) {
Expand Down
Loading