Skip to content

[migrations] Fix account import date detection when no operations with importDate

I'll add a test but this fixes this:

    [2] [2019-06-07T09:20:51.077] [INFO] models/migrations - Ensure "importDate" field is present in accounts.
    [2] [2019-06-07T09:20:51.105] [INFO] models/migrations -        manualaccount-randomid has no importDate.
    [2] (node:1716) UnhandledPromiseRejectionWarning: RangeError: Invalid time value
    [2]     at Date.toISOString (<anonymous>)
    [2]     at clone (/home/user/kresus/app/node_modules/pouchdb/lib/index.js:70:19)
    [2]     at clone (/home/user/kresus/app/node_modules/pouchdb/lib/index.js:85:19)
    [2]     at clone (/home/user/kresus/app/node_modules/pouchdb/lib/index.js:62:22)
    [2]     at PouchDB.<anonymous> (/home/user/kresus/app/node_modules/pouchdb/lib/index.js:112:12)
    [2]     at PouchDB.put (/home/user/kresus/app/node_modules/argsarray/index.js:14:18)
    [2]     at /home/user/kresus/app/node_modules/cozydb/lib/pouchmodel.js:119:40
    [2]     at /home/user/kresus/app/node_modules/pouchdb/lib/index.js:140:9
    [2]     at process._tickCallback (internal/process/next_tick.js:68:7)
    [2] (node:1716) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

when none of the operations imported have a importDate field (but do have a date field):

{
    "data": {
        "accesses": [
            {
                "vendorId": "manual",
                "login": "whatever-manual-acc--does-not-care",
                "customLabel": "Optional custom label",
                "id": 0
            }
        ],
        "accounts": [
            {
                "id": 0,
                "vendorId": "manual",
                "accessId": 0,
                "vendorAccountId": "manualaccount-randomid",
                "type": "account-type.checking",
                "initialBalance": 0,
                "label": "Compte Courant",
                "iban": "FR4830066645148131544778523",
                "currency": "EUR"
            }
        ],
        "categories": [
            {
                "label": "Groceries",
                "color": "#1b9d68",
                "id": 0
            },
            {
                "label": "Books",
                "color": "#b562bf",
                "id": 1
            },
            {
                "label": "Taxes",
                "color": "#ff0000",
                "id": 2
            },
            {
                "label": "Misc",
                "color": "#00ff00",
                "id": 3
            }
        ],
        "operations": [
            {
                "accountId": 0,
                "categoryId": 0,
                "type": "type.card",
                "label": "Wholemart",
                "rawLabel": "card 07/07/2019 wholemart",
                "customLabel": "Food",
                "date": "2019-07-07T00:00:00.000Z",
                "amount": -83.8
            },
            {
                "accountId": 0,
                "categoryId": 0,
                "type": "type.card",
                "label": "Wholemart",
                "rawLabel": "card 09/07/2019 wholemart",
                "customLabel": "Food & stuff",
                "date": "2019-07-09T00:00:00.000Z",
                "amount": -60.8
            },
            {
                "accountId": 0,
                "categoryId": 1,
                "type": "type.card",
                "label": "amazon payments",
                "rawLabel": "carte 19/07/2019 amazon payments",
                "customLabel": "1984 - George Orwell",
                "date": "2019-07-19T00:00:00.000Z",
                "amount": -20
            },
            {
                "accountId": 0,
                "type": "type.transfer",
                "label": "SEPA m. john doe 123457689 rent",
                "rawLabel": "transfer to m. john doe 123457689 rent",
                "date": "2019-07-27T00:00:00.000Z",
                "amount": -500
            },
            {
                "accountId": 0,
                "categoryId": 2,
                "type": "type.order",
                "label": "taxes public department: fr123abc456",
                "rawLabel": "direct debit sepa taxes public department: fr123abc456",
                "date": "2019-08-17T00:00:00.000Z",
                "amount": -150
            },
            {
                "accountId": 0,
                "categoryId": 3,
                "type": "type.withdrawal",
                "label": "ATM my pretty town center",
                "rawLabel": "debit ATM 18/08/2019 ATM my pretty town center",
                "date": "2019-08-19T00:00:00.000Z",
                "amount": -20
            },
            {
                "accountId": 0,
                "type": "type.bankfee",
                "rawLabel": "commission on non euro buy 0.65eur",
                "date": "2019-08-22T00:00:00.000Z",
                "amount": -0.65
            }
        ]
    }
}
Edited by Nicolas Frandeboeuf

Merge request reports

Loading