Final CR backend changes
parent
8d9a47b93e
commit
36f0456750
|
@ -91,7 +91,7 @@ export default class Root extends Route {
|
|||
const embed = new RichEmbed();
|
||||
embed.setTitle(title);
|
||||
embed.setAuthor(`${director.member.username}#${director.member.discriminator}, ${director.user.pn.join(', ')}`, director.member.avatarURL);
|
||||
embed.setDescription(`${id}\n\n_This action is available on the Board Register System Directory. You can make changes or edit it [here](https://board.ins/directory?id=${id})._`);
|
||||
embed.setDescription(`${id}\n\n_This action is available on the Board Register System Directory. You can make changes or edit it [here](https://board.ins/repository)._`);
|
||||
embed.addField('Subject', payload.subject);
|
||||
embed.addField('Body', payload.body);
|
||||
embed.setColor(color);
|
||||
|
@ -107,21 +107,89 @@ export default class Root extends Route {
|
|||
next();
|
||||
});
|
||||
|
||||
this.router.get('/', async (_req, res) => {
|
||||
const eo = await this.server.client.db.ExecutiveOrder.countDocuments();
|
||||
const motion = await this.server.client.db.Motion.countDocuments();
|
||||
const proc = await this.server.client.db.Proclamation.countDocuments();
|
||||
const resolution = await this.server.client.db.Proclamation.countDocuments();
|
||||
this.router.get('/', async (req, res) => {
|
||||
const page = !Number.isNaN(Number(req.query.page)) ? Number(req.query.page) : 0;
|
||||
|
||||
const counts = {
|
||||
eo: await this.server.client.db.ExecutiveOrder.countDocuments(),
|
||||
motion: await this.server.client.db.Motion.countDocuments(),
|
||||
proc: await this.server.client.db.Proclamation.countDocuments(),
|
||||
resolution: await this.server.client.db.Resolution.countDocuments(),
|
||||
};
|
||||
|
||||
const eo = await this.server.client.db.ExecutiveOrder.find().skip(page * 4);
|
||||
const motion = await this.server.client.db.Motion.find().skip(page * 4);
|
||||
const proc = await this.server.client.db.Proclamation.find().skip(page * 4);
|
||||
const resolution = await this.server.client.db.Resolution.find().skip(page * 4);
|
||||
|
||||
const returned: {
|
||||
id: string;
|
||||
author: string;
|
||||
subject: string;
|
||||
type: string;
|
||||
at: number;
|
||||
}[] = [];
|
||||
|
||||
for (const item of eo) {
|
||||
const member = this.guild.members.get(item.issuer);
|
||||
const author = member ? `${member.username}#${member.discriminator}` : 'Deleted User#0000';
|
||||
|
||||
returned.push({
|
||||
id: item.oID,
|
||||
author,
|
||||
subject: item.subject,
|
||||
type: 'Executive Order',
|
||||
at: item.at,
|
||||
});
|
||||
}
|
||||
|
||||
for (const item of motion) {
|
||||
const member = this.guild.members.get(item.issuer);
|
||||
const author = member ? `${member.username}#${member.discriminator}` : 'Deleted User#0000';
|
||||
|
||||
returned.push({
|
||||
id: item.oID,
|
||||
author,
|
||||
subject: item.subject,
|
||||
type: 'Motion',
|
||||
at: item.at,
|
||||
});
|
||||
}
|
||||
|
||||
for (const item of proc) {
|
||||
const member = this.guild.members.get(item.issuer);
|
||||
const author = member ? `${member.username}#${member.discriminator}` : 'Deleted User#0000';
|
||||
|
||||
returned.push({
|
||||
id: item.oID,
|
||||
author,
|
||||
subject: item.subject,
|
||||
type: 'Proclamation',
|
||||
at: item.at,
|
||||
});
|
||||
}
|
||||
|
||||
for (const item of resolution) {
|
||||
const member = this.guild.members.get(item.issuer);
|
||||
const author = member ? `${member.username}#${member.discriminator}` : 'Deleted User#0000';
|
||||
|
||||
returned.push({
|
||||
id: item.oID,
|
||||
author,
|
||||
subject: item.subject,
|
||||
type: 'Resolution',
|
||||
at: item.at,
|
||||
});
|
||||
}
|
||||
|
||||
returned.slice(0, 12);
|
||||
|
||||
const total = counts.eo + counts.motion + counts.proc + counts.resolution;
|
||||
|
||||
res.status(200).json({
|
||||
code: this.constants.codes.SUCCESS,
|
||||
counts: {
|
||||
eo,
|
||||
motion,
|
||||
proc,
|
||||
resolution,
|
||||
total: eo + motion + proc + resolution,
|
||||
},
|
||||
results: returned,
|
||||
total,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -340,7 +408,7 @@ export default class Root extends Route {
|
|||
});
|
||||
}
|
||||
|
||||
if (motion.issuer !== authenticated.member.id && authenticated.member.id !== this.chairman) {
|
||||
if ((motion.issuer !== authenticated.member.id || motion.processed) && authenticated.member.id !== this.chairman) {
|
||||
return res.status(403).json({
|
||||
code: this.constants.codes.UNAUTHORIZED,
|
||||
message: this.constants.codes.UNAUTHORIZED,
|
||||
|
@ -373,7 +441,7 @@ export default class Root extends Route {
|
|||
});
|
||||
}
|
||||
|
||||
if (proc.issuer !== authenticated.member.id && authenticated.member.id !== this.chairman) {
|
||||
if ((proc.issuer !== authenticated.member.id || proc.processed) && authenticated.member.id !== this.chairman) {
|
||||
return res.status(403).json({
|
||||
code: this.constants.codes.UNAUTHORIZED,
|
||||
message: this.constants.codes.UNAUTHORIZED,
|
||||
|
@ -399,6 +467,7 @@ export default class Root extends Route {
|
|||
}
|
||||
|
||||
const issuer = this.guild.members.get(eo.issuer);
|
||||
const director = await this.server.client.db.Staff.findOne({ userID: issuer.id });
|
||||
|
||||
res.status(200).json({
|
||||
code: this.constants.codes.SUCCESS,
|
||||
|
@ -406,6 +475,8 @@ export default class Root extends Route {
|
|||
username: issuer.username,
|
||||
discriminator: issuer.discriminator,
|
||||
avatarURL: issuer.avatarURL,
|
||||
id: issuer.id,
|
||||
pn: director.pn,
|
||||
},
|
||||
subject: eo.subject,
|
||||
body: eo.body,
|
||||
|
@ -425,6 +496,7 @@ export default class Root extends Route {
|
|||
}
|
||||
|
||||
const issuer = this.guild.members.get(motion.issuer);
|
||||
const director = await this.server.client.db.Staff.findOne({ userID: issuer.id });
|
||||
|
||||
res.status(200).json({
|
||||
code: this.constants.codes.SUCCESS,
|
||||
|
@ -432,12 +504,15 @@ export default class Root extends Route {
|
|||
username: issuer.username,
|
||||
discriminator: issuer.discriminator,
|
||||
avatarURL: issuer.avatarURL,
|
||||
id: issuer.id,
|
||||
pn: director.pn,
|
||||
},
|
||||
subject: motion.subject,
|
||||
body: motion.body,
|
||||
issuedAt: motion.at,
|
||||
id: motion.oID,
|
||||
voteResults: motion.results || null,
|
||||
processed: motion.processed,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -452,6 +527,7 @@ export default class Root extends Route {
|
|||
}
|
||||
|
||||
const issuer = this.guild.members.get(proc.issuer);
|
||||
const director = await this.server.client.db.Staff.findOne({ userID: issuer.id });
|
||||
|
||||
res.status(200).json({
|
||||
code: this.constants.codes.SUCCESS,
|
||||
|
@ -459,12 +535,15 @@ export default class Root extends Route {
|
|||
username: issuer.username,
|
||||
discriminator: issuer.discriminator,
|
||||
avatarURL: issuer.avatarURL,
|
||||
id: issuer.id,
|
||||
pn: director.pn,
|
||||
},
|
||||
subject: proc.subject,
|
||||
body: proc.body,
|
||||
issuedAt: proc.at,
|
||||
id: proc.oID,
|
||||
voteResults: proc.results || null,
|
||||
processed: proc.processed,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -479,6 +558,7 @@ export default class Root extends Route {
|
|||
}
|
||||
|
||||
const issuer = this.guild.members.get(resolution.issuer);
|
||||
const director = await this.server.client.db.Staff.findOne({ userID: issuer.id });
|
||||
|
||||
res.status(200).json({
|
||||
code: this.constants.codes.SUCCESS,
|
||||
|
@ -486,6 +566,8 @@ export default class Root extends Route {
|
|||
username: issuer.username,
|
||||
discriminator: issuer.discriminator,
|
||||
avatarURL: issuer.avatarURL,
|
||||
id: issuer.id,
|
||||
pn: director.pn,
|
||||
},
|
||||
subject: resolution.subject,
|
||||
body: resolution.body,
|
||||
|
@ -567,7 +649,7 @@ export default class Root extends Route {
|
|||
});
|
||||
}
|
||||
|
||||
if (motion.issuer !== authenticated.member.id && authenticated.member.id !== this.chairman) {
|
||||
if ((motion.issuer !== authenticated.member.id || motion.processed) && authenticated.member.id !== this.chairman) {
|
||||
return res.status(403).json({
|
||||
code: this.constants.codes.UNAUTHORIZED,
|
||||
message: this.constants.codes.UNAUTHORIZED,
|
||||
|
@ -621,7 +703,7 @@ export default class Root extends Route {
|
|||
});
|
||||
}
|
||||
|
||||
if (proc.issuer !== authenticated.member.id && authenticated.member.id !== this.chairman) {
|
||||
if ((proc.issuer !== authenticated.member.id || proc.processed) && authenticated.member.id !== this.chairman) {
|
||||
return res.status(403).json({
|
||||
code: this.constants.codes.UNAUTHORIZED,
|
||||
message: this.constants.codes.UNAUTHORIZED,
|
||||
|
@ -675,7 +757,7 @@ export default class Root extends Route {
|
|||
});
|
||||
}
|
||||
|
||||
if (resolution.issuer !== authenticated.member.id && authenticated.member.id !== this.chairman) {
|
||||
if (authenticated.member.id !== this.chairman) {
|
||||
return res.status(403).json({
|
||||
code: this.constants.codes.UNAUTHORIZED,
|
||||
message: this.constants.codes.UNAUTHORIZED,
|
||||
|
@ -894,13 +976,14 @@ export default class Root extends Route {
|
|||
},
|
||||
);
|
||||
const resolutionMessage = await this.directorLogs.createMessage({ embed: resolutionEmbed });
|
||||
const resolutionID = genUUID();
|
||||
|
||||
await this.server.client.db.Resolution.create({
|
||||
issuer: motion.issuer,
|
||||
subject: motion.subject,
|
||||
body: motion.body,
|
||||
at: Date.now(),
|
||||
oID: motion.oID,
|
||||
oID: resolutionID,
|
||||
results: {
|
||||
yea,
|
||||
nay,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Emoji, Guild, GuildTextableChannel, Member, Message } from 'eris';
|
||||
import { Emoji, GuildTextableChannel, Member, Message } from 'eris';
|
||||
import { Client, Event } from '../class';
|
||||
|
||||
export default class MessageReactionAdd extends Event {
|
||||
|
|
Loading…
Reference in New Issue