Settings resource; oauth2 app authorization model; UI cleanup

This commit is contained in:
garrettmills
2020-05-17 21:13:38 -05:00
parent d558f21375
commit 2b2e7d2ebe
19 changed files with 393 additions and 2 deletions

View File

@@ -0,0 +1,56 @@
const { Model } = require('flitter-orm')
class SettingModel extends Model {
static get services() {
return [...super.services, 'utility']
}
static get schema() {
return {
key: String,
value: String,
history: [String],
}
}
static async guarantee(key, value = '') {
if ( !(await this.findOne({ key })) ) {
const new_inst = new this({ key })
new_inst.set(value)
await new_inst.save()
}
}
static async get(key) {
const inst = await this.findOne({ key })
return inst.get()
}
static async set(key, value) {
const inst = await this.findOne({ key })
inst.set(value)
await inst.save()
}
get() {
return JSON.parse(this.value)
}
set(value) {
if ( Array.isArray(this.history) )
this.history.push(this.value)
this.value = JSON.stringify(value)
}
async to_api() {
return {
id: this.key,
key: this.key,
value: this.get(),
history: this.history || [],
}
}
}
module.exports = exports = SettingModel