mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 18:29:08 +00:00
v2: init -- UI is nuked from orbit, major app restructuring
This commit is contained in:
parent
c6f5b55c1c
commit
b8da886601
108 changed files with 6717 additions and 17430 deletions
66
services/server.js
Normal file
66
services/server.js
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue