Skip to content

Commit

Permalink
Improved: Updated RuleGroup.lastModifiedDate whenever rules are added…
Browse files Browse the repository at this point in the history
…, modified or archived (#360).
  • Loading branch information
ravilodhi committed Dec 13, 2024
1 parent 15d3699 commit fbf0519
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/services/RuleService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import api from '@/api';
import logger from '@/logger';
import { hasError } from '@/utils';
import { DateTime } from "luxon";

const fetchRuleGroup = async (payload: any): Promise <any> => {
return api({
Expand Down Expand Up @@ -39,6 +40,25 @@ const createRuleGroup = async (payload: any): Promise <any> => {
return Promise.resolve(ruleGroup);
}

const updateRuleGroup = async (ruleGroupId: string, payload: any): Promise <any> => {
try {
const resp = await api({
url: `ruleGroups/${ruleGroupId}`,
method: "POST",
data: payload
}) as any;

if(!hasError(resp)) {
return Promise.resolve(resp);
} else {
throw resp.data
}
} catch(err: any) {
logger.error(err)
return Promise.reject("Failed to update rule group");
}
}

const createRule = async (payload: any): Promise <any> => {
let rule = {}
try {
Expand Down Expand Up @@ -69,6 +89,7 @@ const updateRule = async (payload: any, ruleId: string): Promise <any> => {
}) as any;

if(!hasError(resp)) {
updateRuleGroup(payload.ruleGroupId, {lastModifiedDate: DateTime.now().toMillis()})
return Promise.resolve(resp)
} else {
throw resp.data
Expand Down Expand Up @@ -126,5 +147,6 @@ export const RuleService = {
fetchRuleScheduleInformation,
runNow,
scheduleRuleGroup,
updateRule
updateRule,
updateRuleGroup
}

0 comments on commit fbf0519

Please sign in to comment.