Final CR backend changes
parent
8d9a47b93e
commit
36f0456750
|
@ -91,7 +91,7 @@ export default class Root extends Route {
|
||||||
const embed = new RichEmbed();
|
const embed = new RichEmbed();
|
||||||
embed.setTitle(title);
|
embed.setTitle(title);
|
||||||
embed.setAuthor(`${director.member.username}#${director.member.discriminator}, ${director.user.pn.join(', ')}`, director.member.avatarURL);
|
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('Subject', payload.subject);
|
||||||
embed.addField('Body', payload.body);
|
embed.addField('Body', payload.body);
|
||||||
embed.setColor(color);
|
embed.setColor(color);
|
||||||
|
@ -107,21 +107,89 @@ export default class Root extends Route {
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.router.get('/', async (_req, res) => {
|
this.router.get('/', async (req, res) => {
|
||||||
const eo = await this.server.client.db.ExecutiveOrder.countDocuments();
|
const page = !Number.isNaN(Number(req.query.page)) ? Number(req.query.page) : 0;
|
||||||
const motion = await this.server.client.db.Motion.countDocuments();
|
|
||||||
const proc = await this.server.client.db.Proclamation.countDocuments();
|
const counts = {
|
||||||
const resolution = await this.server.client.db.Proclamation.countDocuments();
|
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({
|
res.status(200).json({
|
||||||
code: this.constants.codes.SUCCESS,
|
code: this.constants.codes.SUCCESS,
|
||||||
counts: {
|
results: returned,
|
||||||
eo,
|
total,
|
||||||
motion,
|
|
||||||
proc,
|
|
||||||
resolution,
|
|
||||||
total: eo + motion + proc + resolution,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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({
|
return res.status(403).json({
|
||||||
code: this.constants.codes.UNAUTHORIZED,
|
code: this.constants.codes.UNAUTHORIZED,
|
||||||
message: 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({
|
return res.status(403).json({
|
||||||
code: this.constants.codes.UNAUTHORIZED,
|
code: this.constants.codes.UNAUTHORIZED,
|
||||||
message: 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 issuer = this.guild.members.get(eo.issuer);
|
||||||
|
const director = await this.server.client.db.Staff.findOne({ userID: issuer.id });
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
code: this.constants.codes.SUCCESS,
|
code: this.constants.codes.SUCCESS,
|
||||||
|
@ -406,6 +475,8 @@ export default class Root extends Route {
|
||||||
username: issuer.username,
|
username: issuer.username,
|
||||||
discriminator: issuer.discriminator,
|
discriminator: issuer.discriminator,
|
||||||
avatarURL: issuer.avatarURL,
|
avatarURL: issuer.avatarURL,
|
||||||
|
id: issuer.id,
|
||||||
|
pn: director.pn,
|
||||||
},
|
},
|
||||||
subject: eo.subject,
|
subject: eo.subject,
|
||||||
body: eo.body,
|
body: eo.body,
|
||||||
|
@ -425,6 +496,7 @@ export default class Root extends Route {
|
||||||
}
|
}
|
||||||
|
|
||||||
const issuer = this.guild.members.get(motion.issuer);
|
const issuer = this.guild.members.get(motion.issuer);
|
||||||
|
const director = await this.server.client.db.Staff.findOne({ userID: issuer.id });
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
code: this.constants.codes.SUCCESS,
|
code: this.constants.codes.SUCCESS,
|
||||||
|
@ -432,12 +504,15 @@ export default class Root extends Route {
|
||||||
username: issuer.username,
|
username: issuer.username,
|
||||||
discriminator: issuer.discriminator,
|
discriminator: issuer.discriminator,
|
||||||
avatarURL: issuer.avatarURL,
|
avatarURL: issuer.avatarURL,
|
||||||
|
id: issuer.id,
|
||||||
|
pn: director.pn,
|
||||||
},
|
},
|
||||||
subject: motion.subject,
|
subject: motion.subject,
|
||||||
body: motion.body,
|
body: motion.body,
|
||||||
issuedAt: motion.at,
|
issuedAt: motion.at,
|
||||||
id: motion.oID,
|
id: motion.oID,
|
||||||
voteResults: motion.results || null,
|
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 issuer = this.guild.members.get(proc.issuer);
|
||||||
|
const director = await this.server.client.db.Staff.findOne({ userID: issuer.id });
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
code: this.constants.codes.SUCCESS,
|
code: this.constants.codes.SUCCESS,
|
||||||
|
@ -459,12 +535,15 @@ export default class Root extends Route {
|
||||||
username: issuer.username,
|
username: issuer.username,
|
||||||
discriminator: issuer.discriminator,
|
discriminator: issuer.discriminator,
|
||||||
avatarURL: issuer.avatarURL,
|
avatarURL: issuer.avatarURL,
|
||||||
|
id: issuer.id,
|
||||||
|
pn: director.pn,
|
||||||
},
|
},
|
||||||
subject: proc.subject,
|
subject: proc.subject,
|
||||||
body: proc.body,
|
body: proc.body,
|
||||||
issuedAt: proc.at,
|
issuedAt: proc.at,
|
||||||
id: proc.oID,
|
id: proc.oID,
|
||||||
voteResults: proc.results || null,
|
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 issuer = this.guild.members.get(resolution.issuer);
|
||||||
|
const director = await this.server.client.db.Staff.findOne({ userID: issuer.id });
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
code: this.constants.codes.SUCCESS,
|
code: this.constants.codes.SUCCESS,
|
||||||
|
@ -486,6 +566,8 @@ export default class Root extends Route {
|
||||||
username: issuer.username,
|
username: issuer.username,
|
||||||
discriminator: issuer.discriminator,
|
discriminator: issuer.discriminator,
|
||||||
avatarURL: issuer.avatarURL,
|
avatarURL: issuer.avatarURL,
|
||||||
|
id: issuer.id,
|
||||||
|
pn: director.pn,
|
||||||
},
|
},
|
||||||
subject: resolution.subject,
|
subject: resolution.subject,
|
||||||
body: resolution.body,
|
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({
|
return res.status(403).json({
|
||||||
code: this.constants.codes.UNAUTHORIZED,
|
code: this.constants.codes.UNAUTHORIZED,
|
||||||
message: 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({
|
return res.status(403).json({
|
||||||
code: this.constants.codes.UNAUTHORIZED,
|
code: this.constants.codes.UNAUTHORIZED,
|
||||||
message: 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({
|
return res.status(403).json({
|
||||||
code: this.constants.codes.UNAUTHORIZED,
|
code: this.constants.codes.UNAUTHORIZED,
|
||||||
message: 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 resolutionMessage = await this.directorLogs.createMessage({ embed: resolutionEmbed });
|
||||||
|
const resolutionID = genUUID();
|
||||||
|
|
||||||
await this.server.client.db.Resolution.create({
|
await this.server.client.db.Resolution.create({
|
||||||
issuer: motion.issuer,
|
issuer: motion.issuer,
|
||||||
subject: motion.subject,
|
subject: motion.subject,
|
||||||
body: motion.body,
|
body: motion.body,
|
||||||
at: Date.now(),
|
at: Date.now(),
|
||||||
oID: motion.oID,
|
oID: resolutionID,
|
||||||
results: {
|
results: {
|
||||||
yea,
|
yea,
|
||||||
nay,
|
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';
|
import { Client, Event } from '../class';
|
||||||
|
|
||||||
export default class MessageReactionAdd extends Event {
|
export default class MessageReactionAdd extends Event {
|
||||||
|
|
Loading…
Reference in New Issue