v1/Server/services/server.js
2017-12-16 17:39:53 -06:00

42 lines
721 B
JavaScript

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