|
|
|
@ -1,834 +0,0 @@
|
|
|
|
|
import { TextChannel } from 'eris';
|
|
|
|
|
import { v4 as genUUID } from 'uuid';
|
|
|
|
|
import { Request, Response } from 'express';
|
|
|
|
|
import { RichEmbed, Route, Server } from '../../../class';
|
|
|
|
|
|
|
|
|
|
export default class Root extends Route {
|
|
|
|
|
constructor(server: Server) {
|
|
|
|
|
super(server);
|
|
|
|
|
this.conf = {
|
|
|
|
|
path: '/',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bind() {
|
|
|
|
|
this.router.post('/eo', async (req, res) => {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
return res.status(401).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const users = await this.server.client.db.Score.find();
|
|
|
|
|
const director = users.filter((user) => user.pin.join('-') === req.headers.authorization)[0];
|
|
|
|
|
const staffGuild = this.server.client.guilds.get(this.server.client.config.guildID) || await this.server.client.getRESTGuild(this.server.client.config.guildID);
|
|
|
|
|
|
|
|
|
|
if (!director || !staffGuild.members.get(director.userID)?.roles?.includes('662163685439045632')) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof req.body.subject !== 'string' || typeof req.body.body !== 'string' || req.body.subject.length > 1024 || req.body.body.length > 1024) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const eoID = genUUID();
|
|
|
|
|
|
|
|
|
|
const directorDiscord = this.server.client.users.get(director.userID) || await this.server.client.getRESTUser(director.userID);
|
|
|
|
|
const directorInformation = await this.server.client.db.Staff.findOne({ userID: director.userID });
|
|
|
|
|
|
|
|
|
|
const embed = new RichEmbed();
|
|
|
|
|
embed.setTitle('Executive Order');
|
|
|
|
|
embed.setAuthor(`${directorDiscord.username}#${directorDiscord.discriminator}, ${directorInformation.pn.join(', ')}`, directorDiscord.avatarURL);
|
|
|
|
|
embed.setColor('#dd3acd');
|
|
|
|
|
embed.addField('Subject', req.body.subject);
|
|
|
|
|
embed.addField('Body', req.body.body);
|
|
|
|
|
embed.setDescription(eoID);
|
|
|
|
|
embed.setTimestamp(new Date());
|
|
|
|
|
|
|
|
|
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
|
|
|
|
const msg = await channel.createMessage({ embed });
|
|
|
|
|
|
|
|
|
|
const executiveOrder = await this.server.client.db.ExecutiveOrder.create({
|
|
|
|
|
issuer: director.userID,
|
|
|
|
|
subject: req.body.subject,
|
|
|
|
|
body: req.body.body,
|
|
|
|
|
at: Date.now(),
|
|
|
|
|
oID: eoID,
|
|
|
|
|
msg: msg.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
res.status(200).json({
|
|
|
|
|
code: this.constants.codes.SUCCESS,
|
|
|
|
|
message: `Created new Executive Order with ID ${executiveOrder.oID} by ${directorDiscord.username}#${directorDiscord.discriminator}, ${directorInformation.pn.join(', ')}.`,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.post('/motion', async (req, res) => {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
return res.status(401).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const users = await this.server.client.db.Score.find();
|
|
|
|
|
const director = users.filter((user) => user.pin.join('-') === req.headers.authorization)[0];
|
|
|
|
|
const staffGuild = this.server.client.guilds.get(this.server.client.config.guildID) || await this.server.client.getRESTGuild(this.server.client.config.guildID);
|
|
|
|
|
|
|
|
|
|
if (!director || !staffGuild.members.get(director.userID)?.roles?.includes('662163685439045632')) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof req.body.subject !== 'string' || typeof req.body.body !== 'string' || req.body.subject.length > 1024 || req.body.body.length > 1024) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const motionID = genUUID();
|
|
|
|
|
|
|
|
|
|
const directorDiscord = this.server.client.users.get(director.userID) || await this.server.client.getRESTUser(director.userID);
|
|
|
|
|
const directorInformation = await this.server.client.db.Staff.findOne({ userID: director.userID });
|
|
|
|
|
|
|
|
|
|
const embed = new RichEmbed();
|
|
|
|
|
embed.setTitle('Motion');
|
|
|
|
|
embed.setAuthor(`${directorDiscord.username}#${directorDiscord.discriminator}, ${directorInformation.pn.join(', ')}`, directorDiscord.avatarURL);
|
|
|
|
|
embed.setColor('#dd3acd');
|
|
|
|
|
embed.addField('Subject', req.body.subject);
|
|
|
|
|
embed.addField('Body', req.body.body);
|
|
|
|
|
embed.setDescription(motionID);
|
|
|
|
|
embed.setTimestamp(new Date());
|
|
|
|
|
|
|
|
|
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
|
|
|
|
const msg = await channel.createMessage({ embed });
|
|
|
|
|
|
|
|
|
|
const motion = await this.server.client.db.Motion.create({
|
|
|
|
|
issuer: director.userID,
|
|
|
|
|
subject: req.body.subject,
|
|
|
|
|
body: req.body.body,
|
|
|
|
|
at: Date.now(),
|
|
|
|
|
oID: motionID,
|
|
|
|
|
msg: msg.id,
|
|
|
|
|
processed: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
res.status(200).json({
|
|
|
|
|
code: this.constants.codes.SUCCESS,
|
|
|
|
|
message: `Created new Motion with ID ${motion.oID} by ${directorDiscord.username}#${directorDiscord.discriminator}, ${directorInformation.pn.join(', ')}.`,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.post('/proc', async (req: Request, res: Response) => {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
return res.status(401).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const users = await this.server.client.db.Score.find();
|
|
|
|
|
const director = users.filter((user) => user.pin.join('-') === req.headers.authorization)[0];
|
|
|
|
|
const staffGuild = this.server.client.guilds.get(this.server.client.config.guildID) || await this.server.client.getRESTGuild(this.server.client.config.guildID);
|
|
|
|
|
|
|
|
|
|
if (!director || !staffGuild.members.get(director.userID)?.roles?.includes('662163685439045632')) {
|
|
|
|
|
return res.status(401).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof req.body.subject !== 'string' || typeof req.body.body !== 'string' || req.body.subject.length > 1024 || req.body.body.length > 1024) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const proclamationID = genUUID();
|
|
|
|
|
|
|
|
|
|
const directorDiscord = this.server.client.users.get(director.userID) || await this.server.client.getRESTUser(director.userID);
|
|
|
|
|
const directorInformation = await this.server.client.db.Staff.findOne({ userID: director.userID });
|
|
|
|
|
|
|
|
|
|
const embed = new RichEmbed();
|
|
|
|
|
embed.setTitle('Proclamation');
|
|
|
|
|
embed.setAuthor(`${directorDiscord.username}#${directorDiscord.discriminator}, ${directorInformation.pn.join(', ')}`, directorDiscord.avatarURL);
|
|
|
|
|
embed.setColor('#66e1ff');
|
|
|
|
|
embed.addField('Subject', req.body.subject);
|
|
|
|
|
embed.addField('Body', req.body.body);
|
|
|
|
|
embed.setDescription(proclamationID);
|
|
|
|
|
embed.setTimestamp(new Date());
|
|
|
|
|
|
|
|
|
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
|
|
|
|
const procMessage = await channel.createMessage({ embed });
|
|
|
|
|
await procMessage.addReaction('modSuccess:578750988907970567');
|
|
|
|
|
await procMessage.addReaction('modError:578750737920688128');
|
|
|
|
|
await procMessage.addReaction('🙋');
|
|
|
|
|
|
|
|
|
|
const proclamation = await this.server.client.db.Proclamation.create({
|
|
|
|
|
issuer: director.userID,
|
|
|
|
|
subject: req.body.subject,
|
|
|
|
|
body: req.body.body,
|
|
|
|
|
at: Date.now(),
|
|
|
|
|
oID: proclamationID,
|
|
|
|
|
processed: false,
|
|
|
|
|
msg: procMessage.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
res.status(200).json({
|
|
|
|
|
code: this.constants.codes.SUCCESS,
|
|
|
|
|
message: `Created new Proclamation with ID ${proclamation.oID} by ${directorDiscord.username}#${directorDiscord.discriminator}, ${directorInformation.pn.join(', ')}.`,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.delete('/eo/:id', async (req, res) => {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
return res.status(401).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const users = await this.server.client.db.Score.find();
|
|
|
|
|
const director = users.filter((user) => user.pin.join('-') === req.headers.authorization)[0];
|
|
|
|
|
const staffGuild = this.server.client.guilds.get(this.server.client.config.guildID) || await this.server.client.getRESTGuild(this.server.client.config.guildID);
|
|
|
|
|
|
|
|
|
|
if (!director || !staffGuild.members.get(director.userID)?.roles?.includes('662163685439045632')) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!req.params.id) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(await this.server.client.db.ExecutiveOrder.exists({ oID: req.params.id }))) {
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
code: this.constants.codes.NOT_FOUND,
|
|
|
|
|
message: this.constants.messages.NOT_FOUND,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const executiveOrder = await this.server.client.db.ExecutiveOrder.findOne({ oID: req.params.id });
|
|
|
|
|
|
|
|
|
|
if (!['278620217221971968', executiveOrder.issuer].includes(director.userID)) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await executiveOrder.delete();
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ message: `Executive Order with ID ${req.params.id} deleted.` });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.delete('/motion/:id', async (req, res) => {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
return res.status(401).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const users = await this.server.client.db.Score.find();
|
|
|
|
|
const director = users.filter((user) => user.pin.join('-') === req.headers.authorization)[0];
|
|
|
|
|
const staffGuild = this.server.client.guilds.get(this.server.client.config.guildID) || await this.server.client.getRESTGuild(this.server.client.config.guildID);
|
|
|
|
|
|
|
|
|
|
if (!director || !staffGuild.members.get(director.userID)?.roles?.includes('662163685439045632')) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!req.params.id) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(await this.server.client.db.Motion.exists({ oID: req.params.id }))) {
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
code: this.constants.codes.NOT_FOUND,
|
|
|
|
|
message: this.constants.messages.NOT_FOUND,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const motion = await this.server.client.db.Motion.findOne({ oID: req.params.id });
|
|
|
|
|
|
|
|
|
|
if (!['278620217221971968', motion.issuer].includes(director.userID)) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await motion.delete();
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ message: `Motion with ID ${req.params.id} deleted.` });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.delete('/proc/:id', async (req, res) => {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
return res.status(401).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const users = await this.server.client.db.Score.find();
|
|
|
|
|
const director = users.filter((user) => user.pin.join('-') === req.headers.authorization)[0];
|
|
|
|
|
const staffGuild = this.server.client.guilds.get(this.server.client.config.guildID) || await this.server.client.getRESTGuild(this.server.client.config.guildID);
|
|
|
|
|
|
|
|
|
|
if (!director || !staffGuild.members.get(director.userID)?.roles?.includes('662163685439045632')) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!req.params.id) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!(await this.server.client.db.Proclamation.exists({ oID: req.params.id }))) {
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
code: this.constants.codes.NOT_FOUND,
|
|
|
|
|
message: this.constants.messages.NOT_FOUND,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const proclamation = await this.server.client.db.Proclamation.findOne({ oID: req.params.id });
|
|
|
|
|
|
|
|
|
|
if (!['278620217221971968', proclamation.issuer].includes(director.userID)) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await proclamation.delete();
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ message: `Proclamation with ID ${req.params.id} deleted.` });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.get('/eo/:id', async (req, res) => {
|
|
|
|
|
if (!req.params.id) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!(await this.server.client.db.ExecutiveOrder.exists({ oID: req.params.id }))) {
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
code: this.constants.codes.NOT_FOUND,
|
|
|
|
|
message: this.constants.messages.NOT_FOUND,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const executiveOrder = await this.server.client.db.ExecutiveOrder.findOne({ oID: req.params.id }).lean();
|
|
|
|
|
|
|
|
|
|
res.status(200).json(executiveOrder);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.get('/motion/:id', async (req, res) => {
|
|
|
|
|
if (!req.params.id) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!(await this.server.client.db.Motion.exists({ oID: req.params.id }))) {
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
code: this.constants.codes.NOT_FOUND,
|
|
|
|
|
message: this.constants.messages.NOT_FOUND,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const motion = await this.server.client.db.Motion.findOne({ oID: req.params.id }).lean();
|
|
|
|
|
|
|
|
|
|
res.status(200).json(motion);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.get('/proc/:id', async (req: Request, res: Response) => {
|
|
|
|
|
if (!req.params.id) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!(await this.server.client.db.Proclamation.exists({ oID: req.params.id }))) {
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
code: this.constants.codes.NOT_FOUND,
|
|
|
|
|
message: this.constants.messages.NOT_FOUND,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const proclamation = await this.server.client.db.Proclamation.findOne({ oID: req.params.id }).lean();
|
|
|
|
|
|
|
|
|
|
res.status(200).json(proclamation);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.get('/resolution/:id', async (req, res) => {
|
|
|
|
|
if (!req.params.id) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!(await this.server.client.db.Resolution.exists({ oID: req.params.id }))) {
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
code: this.constants.codes.NOT_FOUND,
|
|
|
|
|
message: this.constants.messages.NOT_FOUND,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const resolution = await this.server.client.db.Resolution.findOne({ oID: req.params.id }).lean();
|
|
|
|
|
|
|
|
|
|
res.status(200).json(resolution);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.patch('/eo/:id', async (req, res) => {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
return res.status(401).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const users = await this.server.client.db.Score.find();
|
|
|
|
|
const director = users.filter((user) => user.pin.join('-') === req.headers.authorization)[0];
|
|
|
|
|
const staffGuild = this.server.client.guilds.get(this.server.client.config.guildID) || await this.server.client.getRESTGuild(this.server.client.config.guildID);
|
|
|
|
|
const directorDiscord = staffGuild.members.get(director.userID);
|
|
|
|
|
|
|
|
|
|
if (!director || !directorDiscord?.roles?.includes('662163685439045632')) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!req.params.id) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!(await this.server.client.db.ExecutiveOrder.exists({ oID: req.params.id }))) {
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
code: this.constants.codes.NOT_FOUND,
|
|
|
|
|
message: this.constants.messages.NOT_FOUND,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (typeof req.body.subject !== 'string' || typeof req.body.body !== 'string' || req.body.subject.length > 1024 || req.body.body.length > 1024) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const executiveOrder = await this.server.client.db.ExecutiveOrder.findOne({ oID: req.params.id });
|
|
|
|
|
|
|
|
|
|
if (!['278620217221971968', executiveOrder.issuer].includes(director.userID)) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await executiveOrder.updateOne({
|
|
|
|
|
subject: req.body.subject || executiveOrder.subject,
|
|
|
|
|
body: req.body.body || executiveOrder.body,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (executiveOrder.subject !== req.body.subject || executiveOrder.body !== req.body.body) {
|
|
|
|
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
|
|
|
|
const eoMessage = await channel.getMessage(executiveOrder.msg);
|
|
|
|
|
|
|
|
|
|
const embed = new RichEmbed();
|
|
|
|
|
embed.setTitle('Executive Order');
|
|
|
|
|
embed.author = eoMessage.embeds[0].author;
|
|
|
|
|
embed.setColor('#66e1ff');
|
|
|
|
|
embed.addField('Subject', req.body.subject || executiveOrder.subject);
|
|
|
|
|
embed.addField('Body', req.body.body || executiveOrder.body);
|
|
|
|
|
embed.setDescription(req.params.id);
|
|
|
|
|
embed.setTimestamp(new Date());
|
|
|
|
|
|
|
|
|
|
await eoMessage.edit({ embed });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ message: `Updated Executive Order with ID ${executiveOrder.oID}.` });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.patch('/motion/:id', async (req, res) => {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
return res.status(401).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const users = await this.server.client.db.Score.find();
|
|
|
|
|
const director = users.filter((user) => user.pin.join('-') === req.headers.authorization)[0];
|
|
|
|
|
const staffGuild = this.server.client.guilds.get(this.server.client.config.guildID) || await this.server.client.getRESTGuild(this.server.client.config.guildID);
|
|
|
|
|
const directorDiscord = staffGuild.members.get(director.userID);
|
|
|
|
|
|
|
|
|
|
if (!director || !directorDiscord?.roles?.includes('662163685439045632')) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!req.params.id) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!(await this.server.client.db.Motion.exists({ oID: req.params.id }))) {
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
code: this.constants.codes.NOT_FOUND,
|
|
|
|
|
message: this.constants.messages.NOT_FOUND,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (typeof req.body.subject !== 'string' || typeof req.body.body !== 'string' || req.body.subject.length > 1024 || req.body.body.length > 1024) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const motion = await this.server.client.db.Motion.findOne({ oID: req.params.id });
|
|
|
|
|
|
|
|
|
|
if (!['278620217221971968', motion.issuer].includes(director.userID)) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await motion.updateOne({
|
|
|
|
|
subject: req.body.subject || motion.subject,
|
|
|
|
|
body: req.body.body || motion.body,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (motion.subject !== req.body.subject || motion.body !== req.body.body) {
|
|
|
|
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
|
|
|
|
const motionMessage = await channel.getMessage(motion.msg);
|
|
|
|
|
|
|
|
|
|
const embed = new RichEmbed();
|
|
|
|
|
embed.setTitle('Motion');
|
|
|
|
|
embed.author = motionMessage.embeds[0].author;
|
|
|
|
|
embed.setColor('#66e1ff');
|
|
|
|
|
embed.addField('Subject', req.body.subject || motion.subject);
|
|
|
|
|
embed.addField('Body', req.body.body || motion.body);
|
|
|
|
|
embed.setDescription(req.params.id);
|
|
|
|
|
embed.setTimestamp(new Date());
|
|
|
|
|
|
|
|
|
|
await motionMessage.edit({ embed });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ message: `Updated Motion with ID ${motion.oID}.` });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.patch('/proc/:id', async (req, res) => {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
return res.status(401).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const users = await this.server.client.db.Score.find();
|
|
|
|
|
const director = users.filter((user) => user.pin.join('-') === req.headers.authorization)[0];
|
|
|
|
|
const staffGuild = this.server.client.guilds.get(this.server.client.config.guildID) || await this.server.client.getRESTGuild(this.server.client.config.guildID);
|
|
|
|
|
const directorDiscord = staffGuild.members.get(director.userID);
|
|
|
|
|
|
|
|
|
|
if (!director || !directorDiscord?.roles?.includes('662163685439045632')) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!req.params.id) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!(await this.server.client.db.Proclamation.exists({ oID: req.params.id }))) {
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
code: this.constants.codes.NOT_FOUND,
|
|
|
|
|
message: this.constants.messages.NOT_FOUND,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (typeof req.body.subject !== 'string' || typeof req.body.body !== 'string' || req.body.subject.length > 1024 || req.body.body.length > 1024) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const proclamation = await this.server.client.db.Proclamation.findOne({ oID: req.params.id });
|
|
|
|
|
|
|
|
|
|
if (!['278620217221971968', proclamation.issuer].includes(director.userID)) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await proclamation.updateOne({
|
|
|
|
|
subject: req.body.subject || proclamation.subject,
|
|
|
|
|
body: req.body.body || proclamation.body,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (proclamation.subject !== req.body.subject || proclamation.body !== req.body.body) {
|
|
|
|
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
|
|
|
|
const procMessage = await channel.getMessage(proclamation.msg);
|
|
|
|
|
|
|
|
|
|
const embed = new RichEmbed();
|
|
|
|
|
embed.setTitle('Proclamation');
|
|
|
|
|
embed.author = procMessage.embeds[0].author;
|
|
|
|
|
embed.setColor('#66e1ff');
|
|
|
|
|
embed.addField('Subject', req.body.subject || proclamation.subject);
|
|
|
|
|
embed.addField('Body', req.body.body || proclamation.body);
|
|
|
|
|
embed.setDescription(req.params.id);
|
|
|
|
|
embed.setTimestamp(new Date());
|
|
|
|
|
|
|
|
|
|
await procMessage.edit({ embed });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ message: `Updated Proclamation with ID ${proclamation.oID}.` });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.patch('/resolution/:id', async (req, res) => {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
return res.status(401).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const users = await this.server.client.db.Score.find();
|
|
|
|
|
const director = users.filter((user) => user.pin.join('-') === req.headers.authorization)[0];
|
|
|
|
|
const staffGuild = this.server.client.guilds.get(this.server.client.config.guildID) || await this.server.client.getRESTGuild(this.server.client.config.guildID);
|
|
|
|
|
const directorDiscord = staffGuild.members.get(director.userID);
|
|
|
|
|
|
|
|
|
|
if (!director || !directorDiscord?.roles?.includes('662163685439045632')) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!req.params.id) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!(await this.server.client.db.Resolution.exists({ oID: req.params.id }))) {
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
code: this.constants.codes.NOT_FOUND,
|
|
|
|
|
message: this.constants.messages.NOT_FOUND,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (typeof req.body.subject !== 'string' || typeof req.body.body !== 'string' || req.body.subject.length > 1024 || req.body.body.length > 1024) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const resolution = await this.server.client.db.Resolution.findOne({ oID: req.params.id });
|
|
|
|
|
|
|
|
|
|
if (!['278620217221971968', resolution.issuer].includes(director.userID)) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await resolution.updateOne({
|
|
|
|
|
subject: req.body.subject || resolution.subject,
|
|
|
|
|
body: req.body.body || resolution.body,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (resolution.subject !== req.body.subject || resolution.body !== req.body.body) {
|
|
|
|
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
|
|
|
|
const resMessage = await channel.getMessage(resolution.msg);
|
|
|
|
|
|
|
|
|
|
const embed = new RichEmbed();
|
|
|
|
|
embed.setTitle('Resolution');
|
|
|
|
|
embed.author = resMessage.embeds[0].author;
|
|
|
|
|
embed.setColor('#75b0ff');
|
|
|
|
|
embed.addField('Subject', req.body.subject || resolution.subject);
|
|
|
|
|
embed.addField('Body', req.body.body || resolution.body);
|
|
|
|
|
embed.setDescription(req.params.id);
|
|
|
|
|
embed.setTimestamp(new Date());
|
|
|
|
|
|
|
|
|
|
await resMessage.edit({
|
|
|
|
|
content: `<@!${resolution.issuer}>`,
|
|
|
|
|
embed,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ message: `Updated Resolution with ID ${resolution.oID}.` });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.get('/eo', async (_req, res) => {
|
|
|
|
|
const executiveOrders = await this.server.client.db.ExecutiveOrder.find().lean();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.status(200).json(executiveOrders);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.get('/motion', async (_req, res) => {
|
|
|
|
|
const motions = await this.server.client.db.Motion.find().lean();
|
|
|
|
|
|
|
|
|
|
res.status(200).json(motions);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.get('/proc', async (_req: Request, res: Response) => {
|
|
|
|
|
const proclamations = await this.server.client.db.Proclamation.find().lean();
|
|
|
|
|
|
|
|
|
|
res.status(200).send({ proclamations });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.get('/resolution', async (_req, res) => {
|
|
|
|
|
const resolutions = await this.server.client.db.Resolution.find().lean();
|
|
|
|
|
|
|
|
|
|
res.status(200).json(resolutions);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.router.patch('/motion/confirm/:id', async (req, res) => {
|
|
|
|
|
if (!req.headers.authorization) {
|
|
|
|
|
return res.status(401).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const users = await this.server.client.db.Score.find();
|
|
|
|
|
const director = users.filter((user) => user.pin.join('-') === req.headers.authorization)[0];
|
|
|
|
|
const staffGuild = this.server.client.guilds.get(this.server.client.config.guildID) || await this.server.client.getRESTGuild(this.server.client.config.guildID);
|
|
|
|
|
const directorDiscord = staffGuild.members.get(director.userID);
|
|
|
|
|
|
|
|
|
|
if (!director || !directorDiscord?.roles?.includes('662163685439045632')) {
|
|
|
|
|
return res.status(403).json({
|
|
|
|
|
code: this.constants.codes.UNAUTHORIZED,
|
|
|
|
|
message: this.constants.messages.UNAUTHORIZED,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!req.params.id) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!(await this.server.client.db.Motion.exists({ oID: req.params.id, processed: false }))) {
|
|
|
|
|
return res.status(404).json({
|
|
|
|
|
code: this.constants.codes.NOT_FOUND,
|
|
|
|
|
message: this.constants.messages.NOT_FOUND,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const yea = Number(req.body.yea);
|
|
|
|
|
const nay = Number(req.body.nay);
|
|
|
|
|
const present = Number(req.body.present);
|
|
|
|
|
const absent = Number(req.body.absent);
|
|
|
|
|
|
|
|
|
|
if (Number.isNaN(yea) || Number.isNaN(nay) || Number.isNaN(present) || Number.isNaN(absent)) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
code: this.constants.codes.CLIENT_ERROR,
|
|
|
|
|
message: this.constants.messages.CLIENT_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const motion = await this.server.client.db.Motion.findOne({ oID: req.params.id });
|
|
|
|
|
await motion.updateOne({
|
|
|
|
|
processed: true,
|
|
|
|
|
results: {
|
|
|
|
|
yea,
|
|
|
|
|
nay,
|
|
|
|
|
present,
|
|
|
|
|
absent,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const directorStaffProfile = await this.server.client.db.Staff.findOne({ userID: directorDiscord.id });
|
|
|
|
|
|
|
|
|
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
|
|
|
|
|
|
|
|
|
const embed = new RichEmbed();
|
|
|
|
|
embed.setTitle('Motion Confirmed');
|
|
|
|
|
embed.setAuthor(`${directorDiscord.username}#${directorDiscord.discriminator}, ${directorStaffProfile.pn.join(', ')}`, directorDiscord.avatarURL);
|
|
|
|
|
embed.setColor('#27b17a');
|
|
|
|
|
embed.addField('Subject', motion.subject);
|
|
|
|
|
embed.addField('Body', motion.body);
|
|
|
|
|
embed.addField('Results', `Yea: ${yea}\nNay: ${nay}\nPresent: ${present}\nAbsent: ${absent}`);
|
|
|
|
|
embed.setDescription(motion.oID);
|
|
|
|
|
embed.setTimestamp(new Date());
|
|
|
|
|
|
|
|
|
|
await channel.createMessage({ embed });
|
|
|
|
|
|
|
|
|
|
const excludingYea = nay + present + absent;
|
|
|
|
|
if (yea > excludingYea) {
|
|
|
|
|
const resolutionEmbed = new RichEmbed();
|
|
|
|
|
resolutionEmbed.setTitle('Resolution');
|
|
|
|
|
resolutionEmbed.setAuthor(`${directorDiscord.username}#${directorDiscord.discriminator}, ${directorStaffProfile.pn.join(', ')}`, directorDiscord.avatarURL);
|
|
|
|
|
resolutionEmbed.setColor('#75b0ff');
|
|
|
|
|
resolutionEmbed.addField('Subject', motion.subject);
|
|
|
|
|
resolutionEmbed.addField('Body', motion.body);
|
|
|
|
|
resolutionEmbed.addField('Director', `<@!${motion.issuer}>`);
|
|
|
|
|
resolutionEmbed.setDescription(motion.oID);
|
|
|
|
|
resolutionEmbed.setTimestamp(new Date());
|
|
|
|
|
|
|
|
|
|
const resMsg = await channel.createMessage({
|
|
|
|
|
content: `<@!${motion.issuer}>`,
|
|
|
|
|
embed: resolutionEmbed,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await this.server.client.db.Resolution.create({
|
|
|
|
|
issuer: motion.issuer,
|
|
|
|
|
subject: motion.subject,
|
|
|
|
|
body: motion.body,
|
|
|
|
|
at: Date.now(),
|
|
|
|
|
oID: motion.oID,
|
|
|
|
|
results: {
|
|
|
|
|
yea,
|
|
|
|
|
nay,
|
|
|
|
|
present,
|
|
|
|
|
absent,
|
|
|
|
|
},
|
|
|
|
|
msg: resMsg.id,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ message: `Confirmed results of motion with ID ${motion.oID}.` });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|