1+ /** @typedef {import("mongodb").ObjectId } ObjectId */
2+
13/**
24 * Alert document object
35 * @typedef {Object } Alert
3032
3133/**
3234 * Paired app&alert and the metrics
33- * @typedef {Object } MatchedResult
34- * @property {App } app - matched app object
35- * @property {Alert } alert - matched alert object
36- * @property {Date } date - alert trigger date
37- * @property {number } metricValue - metric value that matched the alert condition
38- * @property {number } metricValueBefore - value that compared with metricValue
35+ * @typedef {Object } MatchedResult
36+ * @property {App } app - matched app object
37+ * @property {Alert } alert - matched alert object
38+ * @property {Date } date - alert trigger date
39+ * @property {number= } metricValue - metric value that matched the alert condition
40+ * @property {number= } metricValueBefore - value that compared with metricValue
41+ * @property {any= } extra - extra parameters to pass to e-mail builder
42+ */
43+
44+ /**
45+ * Individual components of a date. modified version of the moment.prototype.toObject()
46+ * @typedef {Object } DateComponents
47+ * @property {number } years
48+ * @property {number } months
49+ * @property {number } days
50+ * @property {number } hours
3951 */
4052
4153const common = require ( '../../../../api/utils/common.js' ) ;
@@ -85,14 +97,11 @@ module.exports = {
8597 * Returns a date's components based on timezone.
8698 * @param {Date } date - date to get its components
8799 * @param {string } timezone - timezone string
88- * @returns {object } - { years, months, days, hours }
100+ * @returns {DateComponents } - { years, months, days, hours }
89101 */
90102function getDateComponents ( date , timezone ) {
91- const dateComponents = moment ( date ) . tz ( timezone ) . toObject ( ) ;
92- dateComponents . months += 1 ; // months are zero indexed
93- dateComponents . days = dateComponents . date ;
94- delete dateComponents . date ;
95- return dateComponents ;
103+ const { years, months, date : days , hours } = moment ( date ) . tz ( timezone ) . toObject ( ) ;
104+ return { years, months : months + 1 , hours, days } ;
96105}
97106
98107/**
@@ -126,6 +135,7 @@ async function determineAudience(alert) {
126135 }
127136 return getUserEmailsBasedOnGroups ( alert . allGroups ) ;
128137 }
138+ return [ ] ;
129139}
130140/**
131141 * Retrieves user emails based on group IDs.
@@ -150,7 +160,7 @@ function getUserEmailsBasedOnGroups(groupIds) {
150160 members . forEach ( ( member ) => {
151161 memberEmails . push ( member . email ) ;
152162 } ) ;
153- resolve ( ) ;
163+ resolve ( true ) ;
154164 }
155165 } ) ;
156166 } ) ;
@@ -166,7 +176,7 @@ function getUserEmailsBasedOnGroups(groupIds) {
166176 * @returns {Promise<string> } - compiled e-mail string
167177 */
168178async function compileEmail ( result ) {
169- const { alert, app, metricValue, metricValueBefore } = result ;
179+ const { alert, app, metricValue, metricValueBefore, extra } = result ;
170180 const host = await new Promise ( ( res , rej ) => mail . lookup ( ( err , _host ) => err ? rej ( err ) : res ( _host ) ) ) ;
171181 const metrics = [ ] ;
172182 if ( metricValue ) {
@@ -179,14 +189,16 @@ async function compileEmail(result) {
179189 title : `Countly Alert` ,
180190 alertName : alert . alertName ,
181191 alertDataType : alert . alertDataType ,
192+ alertDataSubType : alert . alertDataSubType ,
182193 subTitle : `Uh oh! It seems there's been some activity related to ` + alert . alertDataSubType + ` in the ` ,
183194 host,
184195 compareDescribe : alert . compareDescribe ,
185196 apps : [ {
186197 id : app . _id . toString ( ) ,
187198 name : app . name ,
188199 data : metrics
189- } ]
200+ } ] ,
201+ extra,
190202 } ) ;
191203}
192204
@@ -215,7 +227,7 @@ async function trigger(result, log) {
215227 email ,
216228 subject ,
217229 emailBody ,
218- err => err ? rej ( err ) : res ( )
230+ err => err ? rej ( err ) : res ( true )
219231 )
220232 ) ;
221233 // increase counter by date and email
0 commit comments