Add additionalData field to ColumnDef
This commit is contained in:
parent
46f60a671a
commit
f03b4efb7e
@ -75,7 +75,10 @@ class FormDatabase extends Controller {
|
||||
if ( !db ) return res.status(404).message('Database not found with that ID.').api({})
|
||||
// if ( !db.accessible_by(req.user) ) return req.security.deny()
|
||||
|
||||
const columns = await ColumnDef.find({ DatabaseId: db.UUID })
|
||||
const columns = (await ColumnDef.find({ DatabaseId: db.UUID })).map(x => {
|
||||
x.additionalData = x.data()
|
||||
return x
|
||||
})
|
||||
return res.api(columns)
|
||||
}
|
||||
|
||||
@ -107,6 +110,7 @@ class FormDatabase extends Controller {
|
||||
assoc_columns[col.UUID].field = col.field
|
||||
assoc_columns[col.UUID].DatabaseId = db.UUID
|
||||
assoc_columns[col.UUID].Type = col.Type
|
||||
assoc_columns[col.UUID].additionalData = JSON.stringify(col.additionalData)
|
||||
await assoc_columns[col.UUID].save()
|
||||
update_columns.push(assoc_columns[col.UUID])
|
||||
} else {
|
||||
@ -115,6 +119,7 @@ class FormDatabase extends Controller {
|
||||
field: col.field,
|
||||
DatabaseId: db.UUID,
|
||||
Type: col.Type,
|
||||
additionalData: JSON.stringify(col.additionalData),
|
||||
})
|
||||
|
||||
await new_col.save()
|
||||
|
@ -15,10 +15,24 @@ class ColumnDef extends Model {
|
||||
DatabaseId: String,
|
||||
UUID: { type: String, default: () => uuid() },
|
||||
Type: { type: String, default: 'text' }, // text, number for now
|
||||
additionalData: { type: String, default: '{}' }
|
||||
}
|
||||
}
|
||||
|
||||
// Static and instance methods can go here
|
||||
data_get(key) {
|
||||
return JSON.parse(this.additionalData ? this.additionalData : '{}')[key]
|
||||
}
|
||||
|
||||
data_set(key, value) {
|
||||
const json = JSON.parse(this.additionalData ? this.additionalData : '{}')
|
||||
json[key] = value
|
||||
this.additionalData = JSON.stringify(json)
|
||||
}
|
||||
|
||||
data() {
|
||||
return JSON.parse(this.additionalData ? this.additionalData : '{}')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ColumnDef
|
||||
|
Loading…
Reference in New Issue
Block a user