mirror of
https://github.com/strapi/strapi.git
synced 2025-10-29 17:04:13 +00:00
Apply same date parsing logic to all sql databases on save
This commit is contained in:
parent
60d04d26eb
commit
d1ee6a662e
@ -418,12 +418,10 @@ module.exports = ({ models, target, plugin = false }, ctx) => {
|
|||||||
try {
|
try {
|
||||||
// External function to map key that has been updated with `columnName`
|
// External function to map key that has been updated with `columnName`
|
||||||
const mapper = (params = {}) => {
|
const mapper = (params = {}) => {
|
||||||
if (definition.client === 'mysql' || definition.client === 'sqlite3') {
|
Object.keys(params).map(key => {
|
||||||
Object.keys(params).map(key => {
|
const attr = definition.attributes[key] || {};
|
||||||
const attr = definition.attributes[key] || {};
|
params[key] = castValueFromType(attr.type, params[key], definition);
|
||||||
params[key] = castValueFromType(attr.type, params[key]);
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return _.mapKeys(params, (value, key) => {
|
return _.mapKeys(params, (value, key) => {
|
||||||
const attr = definition.attributes[key] || {};
|
const attr = definition.attributes[key] || {};
|
||||||
@ -869,10 +867,13 @@ module.exports = ({ models, target, plugin = false }, ctx) => {
|
|||||||
return Promise.all(updates);
|
return Promise.all(updates);
|
||||||
};
|
};
|
||||||
|
|
||||||
const castValueFromType = (type, value) => {
|
const castValueFromType = (type, value, definition) => {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'json': {
|
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
|
// TODO: handle real date format 1970-01-01
|
||||||
case 'date':
|
case 'date':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user