mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 10:19:10 +00:00
chore: prettier on server
This commit is contained in:
parent
3b0d249e41
commit
912b40c383
21 changed files with 589 additions and 501 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue