A local-first personal finance app
API: add docs for the rules API (#356)
Robert Dyercece84e9bc01
diff --git a/docs/api/reference.md b/docs/api/reference.mdindex b855c41f5c..9e483af2c1 100644--- a/docs/api/reference.md+++ b/docs/api/reference.md@@ -51,6 +51,17 @@ This is the documentation of all available API methods. The API has not been rel"deletePayee"]} />+<APIList title="Rules" sections={[+"ConditionOrAction",+"Rule",+"Payee rule",+"getRules",+"getPayeeRules",+"createRule",+"updateRule",+"deleteRule"+]} />+<APIList title="Misc" sections={["runBankSync"]} />@@ -431,6 +442,75 @@ Update fields of a payee. `fields` can specify any field described in [`Payee`](Delete a payee.+## Rules++#### ConditionOrAction++<StructType fields={objects.condition} />++#### Rule++<StructType fields={objects.rule} />++#### Payee rule++<StructType fields={objects.payeeRule} />++#### Methods++#### `getRules`++<Method name="getRules" args={[]} returns="Promise<Rule[]>" />++Get all rules.++#### `getPayeeRules`++<Method name="getPayeeRules" args={[{ name: 'payeeId', type: "id" }]} returns="Promise<PayeeRule[]>" />++Get all payees rules for `payeeId`.++#### `createRule`++<Method name="createRule" args={[{ name: 'rule', type: 'Rule' }]} returns="Promise<Rule>" />++Create a rule. Returns the new rule, including the `id`.++#### `updateRule`++<Method name="updateRule" args={[{ name: 'id', type: 'id' }, { name: 'fields', type: 'object' }]} returns="Promise<Rule>" />++Update fields of a rule. `fields` can specify any field described in [`Rule`](#rule). Returns the updated rule.++#### `deleteRule`++<Method name="deleteRule" args={[{ name: 'id', type: 'id' }]} returns="Promise<null>" />++Delete a rule.++#### Examples++```js+{+ stage: 'pre',+ conditionsOp: 'and',+ conditions: [+ {+ field: 'payee',+ op: 'is',+ value: 'test-payee',+ },+ ],+ actions: [+ {+ op: 'set',+ field: 'category',+ value: 'fc3825fd-b982-4b72-b768-5b30844cf832',+ },+ ],+}+```+## Misc#### Methodsdiff --git a/docs/api/types.js b/docs/api/types.jsindex 4260642a4c..1396c9ead6 100644--- a/docs/api/types.js+++ b/docs/api/types.js@@ -202,24 +202,61 @@ export let objects = {},],+ condition: [+ { name: 'field', type: 'string', required: true },+ { name: 'op', type: 'string', required: true },+ { name: 'value', type: 'string', required: true },+ ],++ rule: [+ { name: 'id', type: types.id },+ {+ name: 'stage',+ type: 'string',+ required: true,+ description: (+ <span>+ Must be one of <code>pre</code>, <code>default</code>, or <code>post</code>.+ </span>+ ),+ },+ {+ name: 'conditionsOp',+ type: 'string',+ description: (+ <span>+ Must be one of <code>and</code> or <code>or</code>.+ </span>+ ),+ },+ { name: 'conditions', type: 'ConditionOrAction[]' },+ { name: 'actions', type: 'ConditionOrAction[]' },+ ],+payeeRule: [{ name: 'id', type: types.id },{ name: 'payee_id', type: types.id, required: true },{- name: 'type',- type: 'string',- required: true,- description: (- <span>- Must be one of <code>equals</code> or <code>contains</code>- </span>- ),+ name: 'stage',+ type: 'string',+ required: true,+ description: (+ <span>+ Must be one of <code>pre</code>, <code>default</code>, or <code>post</code>.+ </span>+ ),},{- name: 'value',- type: 'string',- description: 'Value to match imported payee names on',+ name: 'conditionsOp',+ type: 'string',+ description: (+ <span>+ Must be one of <code>and</code> or <code>or</code>.+ </span>+ ),},+ { name: 'conditions', type: 'ConditionOrAction[]' },+ { name: 'actions', type: 'ConditionOrAction[]' },],};