mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 14:44:31 +00:00
Do not parse date types
This commit is contained in:
parent
dd072c40c3
commit
f55e1f704b
@ -64,8 +64,9 @@ module.exports = async ({
|
||||
case 'text':
|
||||
return table.text(name, 'longtext');
|
||||
case 'json':
|
||||
// return client === 'pg' ? 'jsonb' : 'longtext';
|
||||
return table.jsonb(name);
|
||||
return definition.client === 'pg'
|
||||
? table.jsonb(name)
|
||||
: table.text(name, 'longtext');
|
||||
case 'enumeration':
|
||||
return table.enu(name, attribute.enum || []);
|
||||
case 'string':
|
||||
|
||||
@ -57,22 +57,6 @@ const formatters = {
|
||||
return value.toString();
|
||||
},
|
||||
},
|
||||
mysql: {
|
||||
boolean: value => {
|
||||
if (typeof value === 'boolean') {
|
||||
return value;
|
||||
}
|
||||
|
||||
const strVal = value.toString();
|
||||
if (strVal === '1') {
|
||||
return true;
|
||||
} else if (strVal === '0') {
|
||||
return false;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
@ -78,7 +78,10 @@ const createComponentJoinTables = async ({ definition, ORM }) => {
|
||||
.notNullable();
|
||||
table.string('component_type').notNullable();
|
||||
table.integer('component_id').notNullable();
|
||||
table.integer(joinColumn).notNullable();
|
||||
table
|
||||
.integer(joinColumn)
|
||||
.unsigned()
|
||||
.notNullable();
|
||||
|
||||
table
|
||||
.foreign(joinColumn)
|
||||
|
||||
@ -615,7 +615,7 @@ module.exports = ({ models, target, plugin = false }, ctx) => {
|
||||
});
|
||||
|
||||
this.on('saving', (instance, attrs) => {
|
||||
instance.attributes = mapper(attrs);
|
||||
instance.attributes = _.assign(instance.attributes, mapper(attrs));
|
||||
|
||||
return _.isFunction(target[model.toLowerCase()]['beforeSave'])
|
||||
? target[model.toLowerCase()]['beforeSave']
|
||||
@ -632,7 +632,7 @@ module.exports = ({ models, target, plugin = false }, ctx) => {
|
||||
|
||||
function formatOutput(instance) {
|
||||
if (Array.isArray(instance.models)) {
|
||||
instance.models.map(formatEntry);
|
||||
instance.models.forEach(entry => formatEntry(entry));
|
||||
} else {
|
||||
formatEntry(instance);
|
||||
}
|
||||
|
||||
@ -8,6 +8,8 @@ const timeRegex = new RegExp(
|
||||
);
|
||||
|
||||
const parseTime = value => {
|
||||
if (dates.isDate(value)) return dates.format(value, 'HH:mm:ss.SSS');
|
||||
|
||||
if (typeof value !== 'string') {
|
||||
throw new Error(`Expected a string, got a ${typeof value}`);
|
||||
}
|
||||
@ -24,6 +26,7 @@ const parseTime = value => {
|
||||
};
|
||||
|
||||
const parseDate = value => {
|
||||
if (dates.isDate(value)) return dates.format(value, 'yyyy-MM-dd');
|
||||
try {
|
||||
let date = dates.parseISO(value);
|
||||
|
||||
@ -36,6 +39,7 @@ const parseDate = value => {
|
||||
};
|
||||
|
||||
const parseDateTimeOrTimestamp = value => {
|
||||
if (dates.isDate(value)) return value;
|
||||
try {
|
||||
const date = dates.parseISO(value);
|
||||
if (dates.isValid(date)) return date;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user