Better parse dates on import + fix pgsql error
This MR better parses date fields from import inputs and cast them to date instances. This fixes a part of #942 (closed) because it seems postgres does not allow timestamp for datetime columns whereas sqlite converts THEM.
This also makes a test use Date instances instead of timestamps to homogeneize things (we should use either Date instances or ISO strings).
The last commit fixes the remaining part of #942 (closed): the ORM generates a weird SQL (that will fail) without values for bulkInsert when the entities array is empty:
query: INSERT INTO "transaction"("userId", "accountId", "categoryId", "type", "label", "rawLabel", "customLabel", "date", "importDate", "budgetDate", "debitDate", "amount", "createdByUser") VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT) RETURNING "id", "categoryId", "type", "customLabel", "budgetDate", "debitDate", "createdByUser"
query failed: INSERT INTO "transaction"("userId", "accountId", "categoryId", "type", "label", "rawLabel", "customLabel", "date", "importDate", "budgetDate", "debitDate", "amount", "createdByUser") VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT) RETURNING "id", "categoryId", "type", "customLabel", "budgetDate", "debitDate", "createdByUser"
error: { error: null value in column "userId" violates not-null constraint
at Connection.parseE (/home/nicofrand/www/kresus/node_modules/pg/lib/connection.js:604:13)
at Connection.parseMessage (/home/nicofrand/www/kresus/node_modules/pg/lib/connection.js:403:19)
at Socket.<anonymous> (/home/nicofrand/www/kresus/node_modules/pg/lib/connection.js:123:22)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
name: 'error',
length: 262,
severity: 'ERROR',
code: '23502',
detail:
'Failing row contains (199, null, null, null, type.unknown, null, null, null, null, null, null, null, null, f).',
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: 'public',
table: 'transaction',
column: 'userId',
dataType: undefined,
constraint: undefined,
file: 'execMain.c',
line: '1965',
routine: 'ExecConstraints' }