Skip to content

Commit 59c642f

Browse files
author
Cihad Tekin
committed
[alerts] codacy fix
1 parent 685862c commit 59c642f

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

plugins/alerts/api/api.js

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,20 @@ const TRIGGER_BY_EVENT = Object.keys(commonLib.TRIGGERED_BY_EVENT).map(name => (
2929
* Takes the timezone offset into account while calculating the trigger time.
3030
* @param {string} period - "hourly"|"daily"|"monthly"
3131
* @param {number} offset - timezone offset in minutes
32-
* @returns {string|undefined} schedule text
32+
* @returns {string} schedule text
3333
*/
3434
function getScheduleTextExpression(period, offset) {
35-
if (typeof offset !== "number") {
36-
log.e("Offset is required");
37-
return;
38-
}
3935
if (period === "hourly") {
4036
return "every 1 hour on the 59th min";
4137
}
42-
else {
43-
const utcClock = moment("2026-02-01T23:59:00.000Z")
44-
.tz("UTC")
45-
.subtract(offset, "minutes")
46-
.format("HH:mm");
47-
if (period === "daily") {
48-
return "at " + utcClock;
49-
}
50-
else if (period === "monthly") {
51-
return "on the last day of the month at " + utcClock;
52-
}
38+
const utcClock = moment("2026-02-01T23:59:00.000Z")
39+
.tz("UTC")
40+
.subtract(offset, "minutes")
41+
.format("HH:mm");
42+
if (period === "daily") {
43+
return "at " + utcClock;
5344
}
54-
log.e(`No such period \"${period}\"`);
55-
return;
45+
return "on the last day of the month at " + utcClock;
5646
}
5747

5848
(function() {
@@ -81,7 +71,7 @@ function getScheduleTextExpression(period, offset) {
8171
* @param {object} alert - alert record data
8272
*/
8373
async function updateJobForAlert(alert) {
84-
if (alert.enabled) {
74+
if (alert.enabled && Object.keys(commonLib.PERIOD_TO_DATE_COMPONENT_MAP).includes(alert.period)) {
8575
const apps = await commonLib.loadAlertAppsWithTimezoneOffsets(alert);
8676
for (const app of apps) {
8777
const textExpression = getScheduleTextExpression(alert.period, app.offset);
@@ -289,13 +279,13 @@ function getScheduleTextExpression(period, offset) {
289279

290280

291281
/**
292-
* @api {get} /i/alert/delete delete alert by alert ID
293-
* @apiName deleteAlert
294-
* @apiGroup alerts
282+
* @api {get} /i/alert/delete delete alert by alert ID
283+
* @apiName deleteAlert
284+
* @apiGroup alerts
295285
*
296286
* @apiDescription delete alert by id.
297287
* @apiQuery {string} alertID target alert id from db.
298-
* @apiQuery {String} app_id target app id of the alert.
288+
* @apiQuery {String} app_id target app id of the alert.
299289
*
300290
* @apiSuccessExample {json} Success-Response:
301291
* HTTP/1.1 200 OK
@@ -343,13 +333,13 @@ function getScheduleTextExpression(period, offset) {
343333

344334
/**
345335
* @api {post} /i/alert/status change alert status
346-
* @apiName changeAlertStatus
347-
* @apiGroup alerts
336+
* @apiName changeAlertStatus
337+
* @apiGroup alerts
348338
*
349339
* @apiDescription change alerts status by boolean flag.
350340
* @apiQuery {string} JSON string of status object for alerts record want to update.
351341
* for example: {"626270afbf7392a8bfd8c1f3":false, "42dafbf7392a8bfd8c1e1": true}
352-
* @apiQuery {String} app_id target app id of the alert.
342+
* @apiQuery {String} app_id target app id of the alert.
353343
*
354344
* @apiSuccessExample {text} Success-Response:
355345
* HTTP/1.1 200 OK

plugins/alerts/api/parts/common-lib.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @property {boolean} enabled - true|false
1919
* @property {string} compareDescribe - text to show on lists for this alert
2020
* @property {Array<string>} alertValues - audience e.g. for alertBy="email", list of e-mails
21-
* @property {Array<string>} allGroups -
21+
* @property {Array<string>} allGroups -
2222
* @property {string} createdBy - creation time
2323
*/
2424

@@ -209,7 +209,7 @@ async function compileEmail(result) {
209209
* Formats the metric value to ensure it maintains its type.
210210
* If the value is a number, it rounds to 2 decimal places if necessary.
211211
* Otherwise, it returns the value as is.
212-
*
212+
*
213213
* @param {number|string} value - The value to be formatted.
214214
* @returns {number|string} The formatted value, maintaining the original type.
215215
*/

0 commit comments

Comments
 (0)