From d1ee6a662ed833b6b09bb9906b82ecb6b71a9f2d Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Thu, 8 Aug 2019 12:03:57 +0200 Subject: [PATCH] Apply same date parsing logic to all sql databases on save --- .../strapi-hook-bookshelf/lib/mount-models.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/strapi-hook-bookshelf/lib/mount-models.js b/packages/strapi-hook-bookshelf/lib/mount-models.js index d37beb560b..45fc0a5dc2 100644 --- a/packages/strapi-hook-bookshelf/lib/mount-models.js +++ b/packages/strapi-hook-bookshelf/lib/mount-models.js @@ -418,12 +418,10 @@ module.exports = ({ models, target, plugin = false }, ctx) => { try { // External function to map key that has been updated with `columnName` const mapper = (params = {}) => { - if (definition.client === 'mysql' || definition.client === 'sqlite3') { - Object.keys(params).map(key => { - const attr = definition.attributes[key] || {}; - params[key] = castValueFromType(attr.type, params[key]); - }); - } + Object.keys(params).map(key => { + const attr = definition.attributes[key] || {}; + params[key] = castValueFromType(attr.type, params[key], definition); + }); return _.mapKeys(params, (value, key) => { const attr = definition.attributes[key] || {}; @@ -869,10 +867,13 @@ module.exports = ({ models, target, plugin = false }, ctx) => { return Promise.all(updates); }; -const castValueFromType = (type, value) => { +const castValueFromType = (type, value, definition) => { switch (type) { case 'json': { - return JSON.stringify(value); + if (definition.client === 'mysql' || definition.client === 'sqlite3') { + return JSON.stringify(value); + } + return value; } // TODO: handle real date format 1970-01-01 case 'date':