Motion and EO endpoints

merge-requests/17/head
Hiroyuki 2021-02-21 23:47:41 -04:00
parent cf0a386520
commit 7591ba8f20
No known key found for this signature in database
GPG Key ID: C15AC26538975A24
2 changed files with 85 additions and 8 deletions

View File

@ -39,7 +39,8 @@
"no-param-reassign": "off",
"no-underscore-dangle": "off",
"keyword-spacing": "off",
"no-multiple-empty-lines": "off"
"no-multiple-empty-lines": "off",
"consistent-return": "off"
},
"ignorePatterns": "**/*.js"
}

View File

@ -11,7 +11,7 @@ export default class Root extends Route {
}
public bind() {
this.router.post('/executive-orders', async (req, res) => {
this.router.post('/eo', async (req, res) => {
if (!req.body.pin) {
return res.status(401).json({
code: this.constants.codes.UNAUTHORIZED,
@ -59,13 +59,13 @@ export default class Root extends Route {
const channel = <TextChannel>this.server.client.getChannel('807444198969835550');
await channel.createMessage({ embed });
return res.status(200).json({
res.status(200).json({
code: this.constants.codes.SUCCESS,
message: `Created new Executive Order with ID ${executiveOrder.oID} by ${staffDiscord.username}#${staffDiscord.discriminator}, ${staffInformation.pn.join(', ')}.`,
});
});
this.router.post('/motions', async (req, res) => {
this.router.post('/motion', async (req, res) => {
if (!req.body.pin) {
return res.status(401).json({
code: this.constants.codes.UNAUTHORIZED,
@ -119,13 +119,89 @@ export default class Root extends Route {
processed: false,
});
return res.status(200).json({
res.status(200).json({
code: this.constants.codes.SUCCESS,
message: `Created new Motion with ID ${motion.oID} by ${staffDiscord.username}#${staffDiscord.discriminator}, ${staffInformation.pn.join(', ')}.`,
});
});
this.router.get('/motions', async (_req, res) => {
this.router.delete('/eo/:id', async (req, res) => {
if (!req.params.id) return res.status(400).send(this.constants.messages.CLIENT_ERROR);
if (!(await this.server.client.db.ExecutiveOrder.exists({ oID: req.params.id }))) return res.status(404).send(this.constants.messages.NOT_FOUND);
await this.server.client.db.ExecutiveOrder.deleteOne({ oID: req.params.id });
res.status(200).send({ message: `Executive Order with ID ${req.params.id} deleted.` });
});
this.router.delete('/motion/:id', async (req, res) => {
if (!req.params.id) return res.status(400).send(this.constants.messages.CLIENT_ERROR);
if (!(await this.server.client.db.Motion.exists({ oID: req.params.id }))) return res.status(404).send(this.constants.messages.NOT_FOUND);
await this.server.client.db.Motion.deleteOne({ oID: req.params.id });
res.status(200).send({ message: `Motion with ID ${req.params.id} deleted.` });
});
this.router.get('/eo/:id', async (req, res) => {
if (!req.params.id) return res.status(400).send(this.constants.messages.CLIENT_ERROR);
if (!(await this.server.client.db.ExecutiveOrder.exists({ oID: req.params.id }))) return res.status(404).send(this.constants.messages.NOT_FOUND);
const executiveOrder = await this.server.client.db.ExecutiveOrder.findOne({ oID: req.params.id });
res.status(200).send({
issuedBy: executiveOrder.issuedBy,
id: executiveOrder.oID,
subject: executiveOrder.subject,
body: executiveOrder.body,
at: new Date(executiveOrder.at),
});
});
this.router.get('/motion/:id', async (req, res) => {
if (!req.params.id) return res.status(400).send(this.constants.messages.CLIENT_ERROR);
if (!(await this.server.client.db.Motion.exists({ oID: req.params.id }))) return res.status(404).send(this.constants.messages.NOT_FOUND);
const motion = await this.server.client.db.Motion.findOne({ oID: req.params.id });
res.status(200).send({
issuedBy: motion.issuedBy,
id: motion.oID,
subject: motion.subject,
body: motion.body,
at: new Date(motion.at),
});
});
this.router.patch('/eo/:id', async (req, res) => {
if (!req.params.id) return res.status(400).send(this.constants.messages.CLIENT_ERROR);
if (!(await this.server.client.db.ExecutiveOrder.exists({ oID: req.params.id }))) return res.status(404).send(this.constants.messages.NOT_FOUND);
if (!req.body.subject && !req.body.body) return res.status(400).send(this.constants.messages.CLIENT_ERROR);
const executiveOrder = await this.server.client.db.ExecutiveOrder.findOne({ oID: req.params.id });
await executiveOrder.updateOne({
subject: req.body.subject || executiveOrder.subject,
body: req.body.body || executiveOrder.body,
});
res.status(200).send({ message: `Updated Executive Order with ID ${executiveOrder.oID}.` });
});
this.router.patch('/motion/:id', async (req, res) => {
if (!req.params.id) return res.status(400).send(this.constants.messages.CLIENT_ERROR);
if (!(await this.server.client.db.Motion.exists({ oID: req.params.id }))) return res.status(404).send(this.constants.messages.NOT_FOUND);
if (!req.body.subject && !req.body.body) return res.status(400).send(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).send({ message: `Updated Motion with ID ${motion.oID}.` });
});
this.router.get('/motion', async (_req, res) => {
const motions = await this.server.client.db.Motion.find().lean();
res.status(200).send({
@ -133,7 +209,7 @@ export default class Root extends Route {
});
});
this.router.get('/resolutions', async (_req, res) => {
this.router.get('/resolution', async (_req, res) => {
const resolutions = await this.server.client.db.Resolution.find().lean();
res.status(200).send({
@ -141,7 +217,7 @@ export default class Root extends Route {
});
});
this.router.get('/executive-orders', async (_req, res) => {
this.router.get('/eo', async (_req, res) => {
const executiveOrders = await this.server.client.db.ExecutiveOrder.find().lean();
res.status(200).send({