Skip to content

Commit

Permalink
Update rules API (actualbudget#1987)
Browse files Browse the repository at this point in the history
* Update rules.ts

* notes

* Update packages/loot-core/src/server/accounts/rules.ts

Co-authored-by: Matiss Janis Aboltins <[email protected]>

* Entity update

* fix

---------

Co-authored-by: Matiss Janis Aboltins <[email protected]>
  • Loading branch information
carkom and MatissJanis authored Nov 30, 2023
1 parent aa9dbb9 commit d1217f0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/loot-core/src/server/accounts/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { sortNumbers, getApproxNumberThreshold } from '../../shared/rules';
import { recurConfigToRSchedule } from '../../shared/schedules';
import { fastSetMerge } from '../../shared/util';
import { RuleConditionEntity } from '../../types/models';
import { RuleError } from '../errors';
import { Schedule as RSchedule } from '../util/rschedule';

Expand Down Expand Up @@ -637,16 +638,19 @@ export class RuleIndexer {
}
}

const OP_SCORES = {
const OP_SCORES: Record<RuleConditionEntity['op'], number> = {
is: 10,
isNot: 10,
oneOf: 9,
notOneOf: 9,
isapprox: 5,
isbetween: 5,
gt: 1,
gte: 1,
lt: 1,
lte: 1,
contains: 0,
doesNotContain: 0,
};

function computeScore(rule) {
Expand Down
14 changes: 13 additions & 1 deletion packages/loot-core/src/types/models/rule.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ export interface RuleEntity {

interface RuleConditionEntity {
field: unknown;
op: unknown;
op:
| 'is'
| 'isNot'
| 'oneOf'
| 'notOneOf'
| 'isapprox'
| 'isbetween'
| 'gt'
| 'gte'
| 'lt'
| 'lte'
| 'contains'
| 'doesNotContain';
value: unknown;
options?: unknown;
conditionsOp?: unknown;
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1987.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [carkom]
---

Fix rule ranker in API.

0 comments on commit d1217f0

Please sign in to comment.