stuff
parent
152a4c3c3b
commit
4530b1b3ec
|
@ -37,32 +37,35 @@ export default class Root extends Route {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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({
|
const executiveOrder = await this.server.client.db.ExecutiveOrder.create({
|
||||||
issuer: director.userID,
|
issuer: director.userID,
|
||||||
subject: req.body.subject,
|
subject: req.body.subject,
|
||||||
body: req.body.body,
|
body: req.body.body,
|
||||||
at: new Date(),
|
at: new Date(),
|
||||||
oID: genUUID(),
|
oID: eoID,
|
||||||
|
msg: msg.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const staffDiscord = this.server.client.users.get(director.userID) || await this.server.client.getRESTUser(director.userID);
|
|
||||||
const staffInformation = await this.server.client.db.Staff.findOne({ userID: director.userID });
|
|
||||||
|
|
||||||
const embed = new RichEmbed();
|
|
||||||
embed.setTitle('Executive Order');
|
|
||||||
embed.setAuthor(`${staffDiscord.username}#${staffDiscord.discriminator}, ${staffInformation.pn.join(', ')}`, staffDiscord.avatarURL);
|
|
||||||
embed.setColor('#dd3acd');
|
|
||||||
embed.addField('Subject', req.body.subject);
|
|
||||||
embed.addField('Body', req.body.body);
|
|
||||||
embed.setDescription(executiveOrder.oID);
|
|
||||||
embed.setTimestamp(new Date());
|
|
||||||
|
|
||||||
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
|
||||||
await channel.createMessage({ embed });
|
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
code: this.constants.codes.SUCCESS,
|
code: this.constants.codes.SUCCESS,
|
||||||
message: `Created new Executive Order with ID ${executiveOrder.oID} by ${staffDiscord.username}#${staffDiscord.discriminator}, ${staffInformation.pn.join(', ')}.`,
|
message: `Created new Executive Order with ID ${executiveOrder.oID} by ${directorDiscord.username}#${directorDiscord.discriminator}, ${directorInformation.pn.join(', ')}.`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -93,12 +96,12 @@ export default class Root extends Route {
|
||||||
|
|
||||||
const motionID = genUUID();
|
const motionID = genUUID();
|
||||||
|
|
||||||
const staffDiscord = this.server.client.users.get(director.userID) || await this.server.client.getRESTUser(director.userID);
|
const directorDiscord = this.server.client.users.get(director.userID) || await this.server.client.getRESTUser(director.userID);
|
||||||
const staffInformation = await this.server.client.db.Staff.findOne({ userID: director.userID });
|
const directorInformation = await this.server.client.db.Staff.findOne({ userID: director.userID });
|
||||||
|
|
||||||
const embed = new RichEmbed();
|
const embed = new RichEmbed();
|
||||||
embed.setTitle('Motion');
|
embed.setTitle('Motion');
|
||||||
embed.setAuthor(`${staffDiscord.username}#${staffDiscord.discriminator}, ${staffInformation.pn.join(', ')}`, staffDiscord.avatarURL);
|
embed.setAuthor(`${directorDiscord.username}#${directorDiscord.discriminator}, ${directorInformation.pn.join(', ')}`, directorDiscord.avatarURL);
|
||||||
embed.setColor('#66e1ff');
|
embed.setColor('#66e1ff');
|
||||||
embed.addField('Subject', req.body.subject);
|
embed.addField('Subject', req.body.subject);
|
||||||
embed.addField('Body', req.body.body);
|
embed.addField('Body', req.body.body);
|
||||||
|
@ -106,7 +109,7 @@ export default class Root extends Route {
|
||||||
embed.setTimestamp(new Date());
|
embed.setTimestamp(new Date());
|
||||||
|
|
||||||
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
||||||
await channel.createMessage({ embed });
|
const msg = await channel.createMessage({ embed });
|
||||||
|
|
||||||
const motion = await this.server.client.db.Motion.create({
|
const motion = await this.server.client.db.Motion.create({
|
||||||
issuer: director.userID,
|
issuer: director.userID,
|
||||||
|
@ -115,11 +118,12 @@ export default class Root extends Route {
|
||||||
at: new Date(),
|
at: new Date(),
|
||||||
oID: motionID,
|
oID: motionID,
|
||||||
processed: false,
|
processed: false,
|
||||||
|
msg: msg.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
code: this.constants.codes.SUCCESS,
|
code: this.constants.codes.SUCCESS,
|
||||||
message: `Created new Motion with ID ${motion.oID} by ${staffDiscord.username}#${staffDiscord.discriminator}, ${staffInformation.pn.join(', ')}.`,
|
message: `Created new Motion with ID ${motion.oID} by ${directorDiscord.username}#${directorDiscord.discriminator}, ${directorInformation.pn.join(', ')}.`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -157,12 +161,12 @@ export default class Root extends Route {
|
||||||
|
|
||||||
const proclamationID = genUUID();
|
const proclamationID = genUUID();
|
||||||
|
|
||||||
const staffDiscord = this.server.client.users.get(director.userID) || await this.server.client.getRESTUser(director.userID);
|
const directorDiscord = this.server.client.users.get(director.userID) || await this.server.client.getRESTUser(director.userID);
|
||||||
const staffInformation = await this.server.client.db.Staff.findOne({ userID: director.userID });
|
const directorInformation = await this.server.client.db.Staff.findOne({ userID: director.userID });
|
||||||
|
|
||||||
const embed = new RichEmbed();
|
const embed = new RichEmbed();
|
||||||
embed.setTitle('Proclamation');
|
embed.setTitle('Proclamation');
|
||||||
embed.setAuthor(`${staffDiscord.username}#${staffDiscord.discriminator}, ${staffInformation.pn.join(', ')}`, staffDiscord.avatarURL);
|
embed.setAuthor(`${directorDiscord.username}#${directorDiscord.discriminator}, ${directorInformation.pn.join(', ')}`, directorDiscord.avatarURL);
|
||||||
embed.setColor('#66e1ff');
|
embed.setColor('#66e1ff');
|
||||||
embed.addField('Subject', req.body.subject);
|
embed.addField('Subject', req.body.subject);
|
||||||
embed.addField('Body', req.body.body);
|
embed.addField('Body', req.body.body);
|
||||||
|
@ -187,7 +191,7 @@ export default class Root extends Route {
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
code: this.constants.codes.SUCCESS,
|
code: this.constants.codes.SUCCESS,
|
||||||
message: `Created new Proclamation with ID ${proc.oID} by ${staffDiscord.username}#${staffDiscord.discriminator}, ${staffInformation.pn.join(', ')}.`,
|
message: `Created new Proclamation with ID ${proc.oID} by ${directorDiscord.username}#${directorDiscord.discriminator}, ${directorInformation.pn.join(', ')}.`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -201,8 +205,9 @@ export default class Root extends Route {
|
||||||
|
|
||||||
const director = await this.server.client.db.Score.findOne({ pin: req.body.pin });
|
const director = await this.server.client.db.Score.findOne({ pin: req.body.pin });
|
||||||
const staffGuild = this.server.client.guilds.get('446067825673633794') || await this.server.client.getRESTGuild('446067825673633794');
|
const staffGuild = this.server.client.guilds.get('446067825673633794') || await this.server.client.getRESTGuild('446067825673633794');
|
||||||
|
const directorDiscord = staffGuild.members.get(director.userID);
|
||||||
|
|
||||||
if (!director || !staffGuild.members.get(director.userID)?.roles?.includes('662163685439045632')) {
|
if (!director || !directorDiscord?.roles?.includes('662163685439045632')) {
|
||||||
return res.status(403).json({
|
return res.status(403).json({
|
||||||
code: this.constants.codes.UNAUTHORIZED,
|
code: this.constants.codes.UNAUTHORIZED,
|
||||||
message: this.constants.messages.UNAUTHORIZED,
|
message: this.constants.messages.UNAUTHORIZED,
|
||||||
|
@ -218,18 +223,20 @@ export default class Root extends Route {
|
||||||
|
|
||||||
const resolutionID = genUUID();
|
const resolutionID = genUUID();
|
||||||
|
|
||||||
const staffDiscord = 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 staffInformation = await this.server.client.db.Staff.findOne({ userID: director.userID });
|
|
||||||
|
|
||||||
const embed = new RichEmbed();
|
const embed = new RichEmbed();
|
||||||
embed.setTitle('Resolution');
|
embed.setTitle('Resolution');
|
||||||
embed.setAuthor(`${staffDiscord.username}#${staffDiscord.discriminator}, ${staffInformation.pn.join(', ')}`, staffDiscord.avatarURL);
|
embed.setAuthor(`${directorDiscord.username}#${directorDiscord.discriminator}, ${directorInformation.pn.join(', ')}`, directorDiscord.avatarURL);
|
||||||
embed.setColor('#29be74');
|
embed.setColor('#29be74');
|
||||||
embed.addField('Subject', req.body.subject);
|
embed.addField('Subject', req.body.subject);
|
||||||
embed.addField('Body', req.body.body);
|
embed.addField('Body', req.body.body);
|
||||||
embed.setDescription(resolutionID);
|
embed.setDescription(resolutionID);
|
||||||
embed.setTimestamp(new Date());
|
embed.setTimestamp(new Date());
|
||||||
|
|
||||||
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
||||||
|
const msg = await channel.createMessage({ embed });
|
||||||
|
|
||||||
const resolution = await this.server.client.db.Resolution.create({
|
const resolution = await this.server.client.db.Resolution.create({
|
||||||
issuer: director.userID,
|
issuer: director.userID,
|
||||||
subject: req.body.subject,
|
subject: req.body.subject,
|
||||||
|
@ -237,11 +244,12 @@ export default class Root extends Route {
|
||||||
at: new Date(),
|
at: new Date(),
|
||||||
oID: resolutionID,
|
oID: resolutionID,
|
||||||
processed: false,
|
processed: false,
|
||||||
|
msg: msg.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
code: this.constants.codes.SUCCESS,
|
code: this.constants.codes.SUCCESS,
|
||||||
message: `Created new Resolution with ID ${resolution.oID} by ${staffDiscord.username}#${staffDiscord.discriminator}, ${staffInformation.pn.join(', ')}.`,
|
message: `Created new Resolution with ID ${resolution.oID} by ${directorDiscord.username}#${directorDiscord.discriminator}, ${directorInformation.pn.join(', ')}.`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -485,8 +493,9 @@ export default class Root extends Route {
|
||||||
|
|
||||||
const director = await this.server.client.db.Score.findOne({ pin: req.body.pin });
|
const director = await this.server.client.db.Score.findOne({ pin: req.body.pin });
|
||||||
const staffGuild = this.server.client.guilds.get('446067825673633794') || await this.server.client.getRESTGuild('446067825673633794');
|
const staffGuild = this.server.client.guilds.get('446067825673633794') || await this.server.client.getRESTGuild('446067825673633794');
|
||||||
|
const directorDiscord = staffGuild.members.get(director.userID);
|
||||||
|
|
||||||
if (!director || !staffGuild.members.get(director.userID)?.roles?.includes('662163685439045632')) {
|
if (!director || !directorDiscord?.roles?.includes('662163685439045632')) {
|
||||||
return res.status(403).json({
|
return res.status(403).json({
|
||||||
code: this.constants.codes.UNAUTHORIZED,
|
code: this.constants.codes.UNAUTHORIZED,
|
||||||
message: this.constants.messages.UNAUTHORIZED,
|
message: this.constants.messages.UNAUTHORIZED,
|
||||||
|
@ -518,6 +527,23 @@ export default class Root extends Route {
|
||||||
body: req.body.body || proclamation.body,
|
body: req.body.body || proclamation.body,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (proclamation.subject !== req.body.subject || proclamation.body !== req.body.body) {
|
||||||
|
const directorStaffProfile = await this.server.client.db.Staff.findOne({ userID: directorDiscord.id });
|
||||||
|
|
||||||
|
const embed = new RichEmbed();
|
||||||
|
embed.setTitle('Proclamation');
|
||||||
|
embed.setAuthor(`${directorDiscord.username}#${directorDiscord.discriminator}, ${directorStaffProfile.pn.join(', ')}`, directorDiscord.avatarURL);
|
||||||
|
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());
|
||||||
|
|
||||||
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
||||||
|
const procMessage = await channel.getMessage(proclamation.msg);
|
||||||
|
await procMessage.edit({ embed });
|
||||||
|
}
|
||||||
|
|
||||||
res.status(200).json({ message: `Updated Proclamation with ID ${proclamation.oID}.` });
|
res.status(200).json({ message: `Updated Proclamation with ID ${proclamation.oID}.` });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -531,8 +557,9 @@ export default class Root extends Route {
|
||||||
|
|
||||||
const director = await this.server.client.db.Score.findOne({ pin: req.body.pin });
|
const director = await this.server.client.db.Score.findOne({ pin: req.body.pin });
|
||||||
const staffGuild = this.server.client.guilds.get('446067825673633794') || await this.server.client.getRESTGuild('446067825673633794');
|
const staffGuild = this.server.client.guilds.get('446067825673633794') || await this.server.client.getRESTGuild('446067825673633794');
|
||||||
|
const directorDiscord = staffGuild.members.get(director.userID);
|
||||||
|
|
||||||
if (!director || !staffGuild.members.get(director.userID)?.roles?.includes('662163685439045632')) {
|
if (!director || !directorDiscord?.roles?.includes('662163685439045632')) {
|
||||||
return res.status(403).json({
|
return res.status(403).json({
|
||||||
code: this.constants.codes.UNAUTHORIZED,
|
code: this.constants.codes.UNAUTHORIZED,
|
||||||
message: this.constants.messages.UNAUTHORIZED,
|
message: this.constants.messages.UNAUTHORIZED,
|
||||||
|
@ -564,6 +591,23 @@ export default class Root extends Route {
|
||||||
body: req.body.body || executiveOrder.body,
|
body: req.body.body || executiveOrder.body,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (executiveOrder.subject !== req.body.subject || executiveOrder.body !== req.body.body) {
|
||||||
|
const directorStaffProfile = await this.server.client.db.Staff.findOne({ userID: directorDiscord.id });
|
||||||
|
|
||||||
|
const embed = new RichEmbed();
|
||||||
|
embed.setTitle('Executive Order');
|
||||||
|
embed.setAuthor(`${directorDiscord.username}#${directorDiscord.discriminator}, ${directorStaffProfile.pn.join(', ')}`, directorDiscord.avatarURL);
|
||||||
|
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());
|
||||||
|
|
||||||
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
||||||
|
const eoMessage = await channel.getMessage(executiveOrder.msg);
|
||||||
|
await eoMessage.edit({ embed });
|
||||||
|
}
|
||||||
|
|
||||||
res.status(200).json({ message: `Updated Executive Order with ID ${executiveOrder.oID}.` });
|
res.status(200).json({ message: `Updated Executive Order with ID ${executiveOrder.oID}.` });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -577,8 +621,9 @@ export default class Root extends Route {
|
||||||
|
|
||||||
const director = await this.server.client.db.Score.findOne({ pin: req.body.pin });
|
const director = await this.server.client.db.Score.findOne({ pin: req.body.pin });
|
||||||
const staffGuild = this.server.client.guilds.get('446067825673633794') || await this.server.client.getRESTGuild('446067825673633794');
|
const staffGuild = this.server.client.guilds.get('446067825673633794') || await this.server.client.getRESTGuild('446067825673633794');
|
||||||
|
const directorDiscord = staffGuild.members.get(director.userID);
|
||||||
|
|
||||||
if (!director || !staffGuild.members.get(director.userID)?.roles?.includes('662163685439045632')) {
|
if (!director || !directorDiscord?.roles?.includes('662163685439045632')) {
|
||||||
return res.status(403).json({
|
return res.status(403).json({
|
||||||
code: this.constants.codes.UNAUTHORIZED,
|
code: this.constants.codes.UNAUTHORIZED,
|
||||||
message: this.constants.messages.UNAUTHORIZED,
|
message: this.constants.messages.UNAUTHORIZED,
|
||||||
|
@ -610,6 +655,23 @@ export default class Root extends Route {
|
||||||
body: req.body.body || motion.body,
|
body: req.body.body || motion.body,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (motion.subject !== req.body.subject || motion.body !== req.body.body) {
|
||||||
|
const directorStaffProfile = await this.server.client.db.Staff.findOne({ userID: directorDiscord.id });
|
||||||
|
|
||||||
|
const embed = new RichEmbed();
|
||||||
|
embed.setTitle('Motion');
|
||||||
|
embed.setAuthor(`${directorDiscord.username}#${directorDiscord.discriminator}, ${directorStaffProfile.pn.join(', ')}`, directorDiscord.avatarURL);
|
||||||
|
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());
|
||||||
|
|
||||||
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
||||||
|
const motionMessage = await channel.getMessage(motion.msg);
|
||||||
|
await motionMessage.edit({ embed });
|
||||||
|
}
|
||||||
|
|
||||||
res.status(200).json({ message: `Updated Motion with ID ${motion.oID}.` });
|
res.status(200).json({ message: `Updated Motion with ID ${motion.oID}.` });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -623,8 +685,9 @@ export default class Root extends Route {
|
||||||
|
|
||||||
const director = await this.server.client.db.Score.findOne({ pin: req.body.pin });
|
const director = await this.server.client.db.Score.findOne({ pin: req.body.pin });
|
||||||
const staffGuild = this.server.client.guilds.get('446067825673633794') || await this.server.client.getRESTGuild('446067825673633794');
|
const staffGuild = this.server.client.guilds.get('446067825673633794') || await this.server.client.getRESTGuild('446067825673633794');
|
||||||
|
const directorDiscord = staffGuild.members.get(director.userID);
|
||||||
|
|
||||||
if (!director || !staffGuild.members.get(director.userID)?.roles?.includes('662163685439045632')) {
|
if (!director || !directorDiscord?.roles?.includes('662163685439045632')) {
|
||||||
return res.status(403).json({
|
return res.status(403).json({
|
||||||
code: this.constants.codes.UNAUTHORIZED,
|
code: this.constants.codes.UNAUTHORIZED,
|
||||||
message: this.constants.messages.UNAUTHORIZED,
|
message: this.constants.messages.UNAUTHORIZED,
|
||||||
|
@ -656,6 +719,23 @@ export default class Root extends Route {
|
||||||
body: req.body.body || resolution.body,
|
body: req.body.body || resolution.body,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (resolution.subject !== req.body.subject || resolution.body !== req.body.body) {
|
||||||
|
const directorStaffProfile = await this.server.client.db.Staff.findOne({ userID: directorDiscord.id });
|
||||||
|
|
||||||
|
const embed = new RichEmbed();
|
||||||
|
embed.setTitle('Executive Order');
|
||||||
|
embed.setAuthor(`${directorDiscord.username}#${directorDiscord.discriminator}, ${directorStaffProfile.pn.join(', ')}`, directorDiscord.avatarURL);
|
||||||
|
embed.setColor('#66e1ff');
|
||||||
|
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());
|
||||||
|
|
||||||
|
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
|
||||||
|
const resMessage = await channel.getMessage(resolution.msg);
|
||||||
|
await resMessage.edit({ embed });
|
||||||
|
}
|
||||||
|
|
||||||
res.status(200).json({ message: `Updated Resolution with ID ${resolution.oID}.` });
|
res.status(200).json({ message: `Updated Resolution with ID ${resolution.oID}.` });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -678,99 +758,6 @@ export default class Root extends Route {
|
||||||
res.status(200).send({ proclamations });
|
res.status(200).send({ proclamations });
|
||||||
});
|
});
|
||||||
|
|
||||||
this.router.patch('/motion/:id', async (req, res) => {
|
|
||||||
if (!req.body.pin) {
|
|
||||||
return res.status(401).json({
|
|
||||||
code: this.constants.codes.UNAUTHORIZED,
|
|
||||||
message: this.constants.messages.UNAUTHORIZED,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const director = await this.server.client.db.Score.findOne({ pin: req.body.pin });
|
|
||||||
const staffGuild = this.server.client.guilds.get('446067825673633794') || await this.server.client.getRESTGuild('446067825673633794');
|
|
||||||
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (!req.body.subject && !req.body.body) {
|
|
||||||
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({
|
|
||||||
subject: req.body.subject || motion.subject,
|
|
||||||
body: req.body.body || motion.body,
|
|
||||||
});
|
|
||||||
|
|
||||||
res.status(200).json({ message: `Updated Motion with ID ${motion.oID}.` });
|
|
||||||
});
|
|
||||||
|
|
||||||
this.router.patch('/resolution/:id', async (req, res) => {
|
|
||||||
if (!req.body.pin) {
|
|
||||||
return res.status(401).json({
|
|
||||||
code: this.constants.codes.UNAUTHORIZED,
|
|
||||||
message: this.constants.messages.UNAUTHORIZED,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const director = await this.server.client.db.Score.findOne({ pin: req.body.pin });
|
|
||||||
const staffGuild = this.server.client.guilds.get('446067825673633794') || await this.server.client.getRESTGuild('446067825673633794');
|
|
||||||
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (!req.body.subject && !req.body.body) {
|
|
||||||
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 });
|
|
||||||
await resolution.updateOne({
|
|
||||||
subject: req.body.subject || resolution.subject,
|
|
||||||
body: req.body.body || resolution.body,
|
|
||||||
});
|
|
||||||
|
|
||||||
res.status(200).json({ message: `Updated Resolution with ID ${resolution.oID}.` });
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
this.router.get('/eo', async (_req, res) => {
|
this.router.get('/eo', async (_req, res) => {
|
||||||
const executiveOrders = await this.server.client.db.ExecutiveOrder.find().lean();
|
const executiveOrders = await this.server.client.db.ExecutiveOrder.find().lean();
|
||||||
|
|
||||||
|
@ -795,5 +782,73 @@ export default class Root extends Route {
|
||||||
|
|
||||||
res.status(200).json({ resolutions });
|
res.status(200).json({ resolutions });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.router.patch('/motion/confirm', async (req, res) => {
|
||||||
|
if (!req.body.pin) {
|
||||||
|
return res.status(401).json({
|
||||||
|
code: this.constants.codes.UNAUTHORIZED,
|
||||||
|
message: this.constants.messages.UNAUTHORIZED,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const director = await this.server.client.db.Score.findOne({ pin: req.body.pin });
|
||||||
|
const staffGuild = this.server.client.guilds.get('446067825673633794') || await this.server.client.getRESTGuild('446067825673633794');
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (Number.isNaN(Number(req.body.yea)) || Number.isNaN(Number(req.body.nay)) || Number.isNaN(Number(req.body.present)) || Number.isNaN(Number(req.body.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: Number(req.body.yea),
|
||||||
|
nay: Number(req.body.nay),
|
||||||
|
present: Number(req.body.present),
|
||||||
|
absent: Number(req.body.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', req.body.subject);
|
||||||
|
embed.addField('Body', req.body.body);
|
||||||
|
embed.setDescription(motion.oID);
|
||||||
|
embed.setFooter(motion.oID, directorDiscord.avatarURL);
|
||||||
|
embed.setTimestamp(new Date());
|
||||||
|
|
||||||
|
await channel.createMessage({ embed });
|
||||||
|
|
||||||
|
res.status(200).json({ message: `Confirmed results of motion with ID ${motion.oID}.` });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ export interface ExecutiveOrderInterface extends Document {
|
||||||
body: string;
|
body: string;
|
||||||
at: Date;
|
at: Date;
|
||||||
oID: string;
|
oID: string;
|
||||||
|
msg: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ExecutiveOrder = new Schema({
|
const ExecutiveOrder = new Schema({
|
||||||
|
@ -14,6 +15,7 @@ const ExecutiveOrder = new Schema({
|
||||||
body: { type: String, required: true },
|
body: { type: String, required: true },
|
||||||
at: { type: Date, required: true },
|
at: { type: Date, required: true },
|
||||||
oID: { type: String, required: true, unique: true },
|
oID: { type: String, required: true, unique: true },
|
||||||
|
msg: { type: String, required: true, unique: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
export default model<ExecutiveOrderInterface>('ExecutiveOrders', ExecutiveOrder);
|
export default model<ExecutiveOrderInterface>('ExecutiveOrders', ExecutiveOrder);
|
||||||
|
|
|
@ -13,6 +13,7 @@ export interface MotionInterface extends Document {
|
||||||
absent: number;
|
absent: number;
|
||||||
};
|
};
|
||||||
processed: boolean;
|
processed: boolean;
|
||||||
|
msg: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Motion = new Schema({
|
const Motion = new Schema({
|
||||||
|
@ -28,6 +29,7 @@ const Motion = new Schema({
|
||||||
absent: Number,
|
absent: Number,
|
||||||
},
|
},
|
||||||
processed: Boolean,
|
processed: Boolean,
|
||||||
|
msg: { required: true, unique: true, type: String },
|
||||||
});
|
});
|
||||||
|
|
||||||
export default model<MotionInterface>('Motions', Motion);
|
export default model<MotionInterface>('Motions', Motion);
|
||||||
|
|
|
@ -13,6 +13,7 @@ export interface ResolutionInterface extends Document {
|
||||||
absent: number;
|
absent: number;
|
||||||
};
|
};
|
||||||
acceptedAt: number;
|
acceptedAt: number;
|
||||||
|
msg: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Resolution = new Schema({
|
const Resolution = new Schema({
|
||||||
|
@ -28,6 +29,7 @@ const Resolution = new Schema({
|
||||||
absent: Number,
|
absent: Number,
|
||||||
},
|
},
|
||||||
acceptedAt: Number,
|
acceptedAt: Number,
|
||||||
|
msg: { required: true, unique: true, type: String },
|
||||||
});
|
});
|
||||||
|
|
||||||
export default model<ResolutionInterface>('Resolutions', Resolution);
|
export default model<ResolutionInterface>('Resolutions', Resolution);
|
||||||
|
|
Loading…
Reference in New Issue