chore: prettier on server

This commit is contained in:
Katie Thornhill 2019-11-19 23:02:54 -05:00
parent 3b0d249e41
commit 912b40c383
No known key found for this signature in database
GPG key ID: F76EDC6541A99644
21 changed files with 589 additions and 501 deletions

View file

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