Use defaultValue as a template, fix critical sync issue

This commit is contained in:
Ben Gotow 2016-07-15 19:01:50 -07:00
parent 549ced6128
commit f9f78968b1

View file

@ -5,18 +5,22 @@ module.exports = {
type: Sequelize.TEXT, type: Sequelize.TEXT,
get: function get() { get: function get() {
const val = this.getDataValue(fieldName); const val = this.getDataValue(fieldName);
if (!val) { return defaultValue } if (!val) {
return defaultValue ? Object.assign({}, defaultValue) : null;
}
return JSON.parse(val); return JSON.parse(val);
}, },
set: function set(val) { set: function set(val) {
this.setDataValue(fieldName, JSON.stringify(val)); this.setDataValue(fieldName, JSON.stringify(val));
}, },
}), }),
JSONARRAYType: (fieldName, {defaultValue = []} = {}) => ({ JSONARRAYType: (fieldName) => ({
type: Sequelize.TEXT, type: Sequelize.TEXT,
get: function get() { get: function get() {
const val = this.getDataValue(fieldName); const val = this.getDataValue(fieldName);
if (!val) { return defaultValue } if (!val) {
return [];
}
return JSON.parse(val); return JSON.parse(val);
}, },
set: function set(val) { set: function set(val) {