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: {
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
},
ping: {
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
},
require_topic: {
@ -56,6 +72,14 @@ module.exports = ({ config }, sequelize) => {
},
roles: {
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
},
survey: {

View File

@ -49,6 +49,14 @@ module.exports = ({ config }, sequelize) => {
},
tags: {
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
}
}, { tableName: DB_TABLE_PREFIX + 'guilds' });

View File

@ -4,6 +4,14 @@ module.exports = (client, sequelize) => {
sequelize.define('Panel', {
categories: {
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
},
channel: {

View File

@ -18,6 +18,14 @@ module.exports = (client, sequelize) => {
},
questions: {
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
}
}, { tableName: DB_TABLE_PREFIX + 'surveys' });

View File

@ -4,6 +4,14 @@ module.exports = (client, sequelize) => {
sequelize.define('SurveyResponse', {
answers: {
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
},
survey: {

View File

@ -63,6 +63,14 @@ module.exports = (_client, sequelize) => {
},
pinned_messages: {
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
},
topic: {