mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 18:29:08 +00:00
finish redux feature parity
This commit is contained in:
parent
f5220aa6dc
commit
5510d5a1c4
29 changed files with 220 additions and 100 deletions
42
Server/services/server.js
Normal file
42
Server/services/server.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
const Service = require('./Service')
|
||||
|
||||
class ServerService extends Service {
|
||||
constructor (ctx) {
|
||||
super(ctx)
|
||||
this.Server = ctx.M.Server
|
||||
this.P = ctx.P
|
||||
}
|
||||
|
||||
async ensure (server) {
|
||||
const srv = await this.get(server.id)
|
||||
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()
|
||||
}
|
||||
|
||||
update (id, newData) {
|
||||
const srv = this.get(id)
|
||||
|
||||
return srv.update(newData)
|
||||
}
|
||||
|
||||
get (id) {
|
||||
return this.Server.findOne({
|
||||
where: {
|
||||
id
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ServerService
|
Loading…
Add table
Add a link
Reference in a new issue