Parse JSON if value is string

This commit is contained in:
Isaac 2021-05-30 21:14:16 +01:00
parent f7cd3e85e5
commit c6d56afa11
No known key found for this signature in database
GPG Key ID: F6812DBC6719B4E3
6 changed files with 64 additions and 0 deletions

View File

@ -44,10 +44,26 @@ module.exports = ({ config }, sequelize) => {
}, },
opening_questions: { opening_questions: {
allowNull: true, allowNull: true,
get() {
const raw_value = this.getDataValue('opening_questions');
return raw_value
? typeof raw_value === 'string'
? JSON.parse(raw_value)
: raw_value
: null;
},
type: DataTypes.JSON type: DataTypes.JSON
}, },
ping: { ping: {
defaultValue: [], defaultValue: [],
get() {
const raw_value = this.getDataValue('ping');
return raw_value
? typeof raw_value === 'string'
? JSON.parse(raw_value)
: raw_value
: null;
},
type: DataTypes.JSON type: DataTypes.JSON
}, },
require_topic: { require_topic: {
@ -56,6 +72,14 @@ module.exports = ({ config }, sequelize) => {
}, },
roles: { roles: {
allowNull: false, allowNull: false,
get() {
const raw_value = this.getDataValue('roles');
return raw_value
? typeof raw_value === 'string'
? JSON.parse(raw_value)
: raw_value
: null;
},
type: DataTypes.JSON type: DataTypes.JSON
}, },
survey: { survey: {

View File

@ -49,6 +49,14 @@ module.exports = ({ config }, sequelize) => {
}, },
tags: { tags: {
defaultValue: {}, defaultValue: {},
get() {
const raw_value = this.getDataValue('tags');
return raw_value
? typeof raw_value === 'string'
? JSON.parse(raw_value)
: raw_value
: null;
},
type: DataTypes.JSON type: DataTypes.JSON
} }
}, { tableName: DB_TABLE_PREFIX + 'guilds' }); }, { tableName: DB_TABLE_PREFIX + 'guilds' });

View File

@ -4,6 +4,14 @@ module.exports = (client, sequelize) => {
sequelize.define('Panel', { sequelize.define('Panel', {
categories: { categories: {
allowNull: false, allowNull: false,
get() {
const raw_value = this.getDataValue('categories');
return raw_value
? typeof raw_value === 'string'
? JSON.parse(raw_value)
: raw_value
: null;
},
type: DataTypes.JSON type: DataTypes.JSON
}, },
channel: { channel: {

View File

@ -18,6 +18,14 @@ module.exports = (client, sequelize) => {
}, },
questions: { questions: {
allowNull: true, allowNull: true,
get() {
const raw_value = this.getDataValue('questions');
return raw_value
? typeof raw_value === 'string'
? JSON.parse(raw_value)
: raw_value
: null;
},
type: DataTypes.JSON type: DataTypes.JSON
} }
}, { tableName: DB_TABLE_PREFIX + 'surveys' }); }, { tableName: DB_TABLE_PREFIX + 'surveys' });

View File

@ -4,6 +4,14 @@ module.exports = (client, sequelize) => {
sequelize.define('SurveyResponse', { sequelize.define('SurveyResponse', {
answers: { answers: {
allowNull: true, allowNull: true,
get() {
const raw_value = this.getDataValue('answers');
return raw_value
? typeof raw_value === 'string'
? JSON.parse(raw_value)
: raw_value
: null;
},
type: DataTypes.JSON type: DataTypes.JSON
}, },
survey: { survey: {

View File

@ -63,6 +63,14 @@ module.exports = (_client, sequelize) => {
}, },
pinned_messages: { pinned_messages: {
defaultValue: [], defaultValue: [],
get() {
const raw_value = this.getDataValue('pinned_messages');
return raw_value
? typeof raw_value === 'string'
? JSON.parse(raw_value)
: raw_value
: null;
},
type: DataTypes.JSON type: DataTypes.JSON
}, },
topic: { topic: {