v2: init -- UI is nuked from orbit, major app restructuring

This commit is contained in:
41666 2019-02-23 18:16:31 -06:00
parent c6f5b55c1c
commit b8da886601
108 changed files with 6717 additions and 17430 deletions

66
services/server.js Normal file
View file

@ -0,0 +1,66 @@
const Service = require('./Service')
class ServerService extends Service {
constructor (ctx) {
super(ctx)
this.Server = ctx.M.Server
this.P = ctx.P
}
async ensure (server) {
let srv
try {
srv = await this.get(server.id)
} catch (e) {
}
if (srv == null) {
return this.create({
id: server.id,
message: '',
categories: {}
})
}
}
create ({ id, message, categories }) {
const srv = this.Server.build({ id, message, categories })
return srv.save()
}
async update (id, newData) {
const srv = await this.get(id, false)
return srv.update(newData)
}
async get (id, plain = true) {
const s = await this.Server.findOne({
where: {
id
}
})
if (!plain) {
return s
}
return s.get({ plain: true })
}
async getAllowedRoles (id) {
const server = await this.get(id)
return Object.values(server.categories).reduce((acc, c) => {
if (c.hidden !== true) {
return acc.concat(c.roles)
}
return acc
}, [])
}
}
module.exports = ServerService