From 626131bf4e2c76a3c6e2189568a73ab233f7a406 Mon Sep 17 00:00:00 2001 From: Hiroyuki Date: Sun, 7 Feb 2021 21:58:26 -0400 Subject: [PATCH] Resolutions --- package.json | 16 ++++++++-------- src/api/board.ins/routes/root.ts | 4 ++-- src/class/Client.ts | 4 +++- src/intervals/motions.ts | 17 +++++++++++++++- src/models/Resolution.ts | 33 ++++++++++++++++++++++++++++++++ src/models/index.ts | 1 + 6 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 src/models/Resolution.ts diff --git a/package.json b/package.json index 26da961..ccbbfe1 100644 --- a/package.json +++ b/package.json @@ -19,14 +19,14 @@ "@types/jsonwebtoken": "^8.5.0", "@types/mathjs": "^6.0.7", "@types/mongoose": "^5.7.19", - "@types/node": "^14.0.1", + "@types/node": "^14.14.25", "@types/nodemailer": "^6.4.0", - "@types/puppeteer": "^5.4.2", + "@types/puppeteer": "^5.4.3", "@types/signale": "^1.4.1", "@types/uuid": "^7.0.3", "@typescript-eslint/eslint-plugin": "^2.33.0", "@typescript-eslint/parser": "^2.33.0", - "eslint": "^7.0.0", + "eslint": "^7.19.0", "eslint-config-airbnb-base": "^14.1.0", "eslint-plugin-import": "^2.20.2", "typescript": "^3.9.2" @@ -35,27 +35,27 @@ "@google-cloud/text-to-speech": "^3.1.2", "ari-client": "^2.2.0", "asterisk-manager": "^0.1.16", - "awesome-phonenumber": "^2.41.0", + "awesome-phonenumber": "^2.45.0", "axios": "^0.19.2", "body-parser": "^1.19.0", "brain.js": "^2.0.0-beta.2", - "bull": "^3.18.1", + "bull": "^3.20.1", "cheerio": "^1.0.0-rc.5", "cron": "^1.8.2", "eris": "^0.13.3", - "eris-pagination": "bsian03/eris-pagination", + "eris-pagination": "github:bsian03/eris-pagination", "express": "^4.17.1", "helmet": "^3.22.0", "jsonwebtoken": "^8.5.1", "mathjs": "^7.6.0", "moment": "^2.25.3", - "mongoose": "^5.9.13", + "mongoose": "^5.11.15", "nodemailer": "^6.4.8", "pluris": "^0.2.5", "puppeteer": "^5.5.0", "sd-notify": "^2.8.0", "signale": "^1.4.0", - "stripe": "^8.120.0", + "stripe": "^8.134.0", "uuid": "^8.0.0", "yaml": "^1.9.2" } diff --git a/src/api/board.ins/routes/root.ts b/src/api/board.ins/routes/root.ts index 6aef088..2199adb 100644 --- a/src/api/board.ins/routes/root.ts +++ b/src/api/board.ins/routes/root.ts @@ -11,7 +11,7 @@ export default class Root extends Route { } public bind() { - this.router.post('/executive-orders/new', async (req, res) => { + this.router.post('/executive-orders', async (req, res) => { if (!req.body.pin) { return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, @@ -72,7 +72,7 @@ export default class Root extends Route { }); }); - this.router.post('/motions/new', async (req, res) => { + this.router.post('/motions', async (req, res) => { if (!req.body.pin) { return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, diff --git a/src/class/Client.ts b/src/class/Client.ts index 12816ac..18c70de 100644 --- a/src/class/Client.ts +++ b/src/class/Client.ts @@ -19,6 +19,7 @@ import { Promo, PromoInterface, Rank, RankInterface, Redirect, RedirectInterface, + Resolution, ResolutionInterface, Score, ScoreInterface, ScoreHistorical, ScoreHistoricalInterface, Staff, StaffInterface, @@ -60,6 +61,7 @@ export default class Client extends eris.Client { Promo: mongoose.Model, Rank: mongoose.Model, Redirect: mongoose.Model, + Resolution: mongoose.Model, Score: mongoose.Model, ScoreHistorical: mongoose.Model, Staff: mongoose.Model, @@ -73,7 +75,7 @@ export default class Client extends eris.Client { this.events = new Collection(); this.intervals = new Collection(); this.queue = new Queue(this); - this.db = { Customer, CustomerPortal, ExecutiveOrder, File, Member, Merchant, Moderation, Motion, NNTrainingData, Note, PagerNumber, Promo, Rank, Redirect, Score, ScoreHistorical, Staff, Stat, local: { muted: new LocalStorage('muted') } }; + this.db = { Customer, CustomerPortal, ExecutiveOrder, File, Member, Merchant, Moderation, Motion, NNTrainingData, Note, PagerNumber, Promo, Rank, Redirect, Resolution, Score, ScoreHistorical, Staff, Stat, local: { muted: new LocalStorage('muted') } }; } public async loadDatabase() { diff --git a/src/intervals/motions.ts b/src/intervals/motions.ts index 6470102..b7de6e9 100644 --- a/src/intervals/motions.ts +++ b/src/intervals/motions.ts @@ -26,19 +26,34 @@ export default (client: Client) => { absent, }, }); + await client.db.Resolution.create({ + issuedBy: motion.issuedBy, + subject: motion.subject, + body: motion.body, + at: motion.at, + oID: motion.oID, + voteResults: { + yea: yea.length, + Nay: nay.length, + present, + absent, + }, + acceptedAt: Number, + }); const directorDiscord = client.users.get(motion.issuedBy); const directorProfile = await client.db.Staff.findOne({ userID: motion.issuedBy }); const embed = new RichEmbed(); embed.setAuthor(`${directorDiscord.username}#${directorDiscord.discriminator}, ${directorProfile.pn.join(', ')}`, directorDiscord.avatarURL); + embed.setTitle('Resolution'); embed.setFooter(`${directorProfile.position} | Library of Code sp-us | Board of Directors`, 'https://static.libraryofcode.org/loccommunityadmin.png'); let colour; if (yea.length > nay.length) colour = '#27b17a'; else if (yea.length === nay.length) colour = '#ffb34d'; else colour = '#ff474a'; embed.setColor(colour); - embed.addField('Motion ID', motion.oID); + embed.setDescription(motion.oID); embed.addField('Result', `- **Yea:** ${yea.length}\n**Nay:** ${nay.length}\n**Present:** ${present}\n**Absent:** ${absent}\n**Total:** ${present + absent}`); embed.setTimestamp(); diff --git a/src/models/Resolution.ts b/src/models/Resolution.ts new file mode 100644 index 0000000..45b3245 --- /dev/null +++ b/src/models/Resolution.ts @@ -0,0 +1,33 @@ +import { Document, model, Schema } from 'mongoose'; + +export interface ResolutionInterface extends Document { + issuedBy: string; + subject: string; + body: string; + at: Date; + oID: string; + voteResults: { + yea: number; + nay: number; + present: number; + absent: number; + }; + acceptedAt: number; +} + +const Resolution = new Schema({ + issuedBy: { type: String, required: true }, + subject: { type: String, required: true }, + body: { type: String, required: true }, + at: { type: Date, required: true }, + oID: { type: String, required: true, unique: true }, + voteResults: { + yea: Number, + Nay: Number, + present: Number, + absent: Number, + }, + acceptedAt: Number, +}); + +export default model('Resolutions', Resolution); diff --git a/src/models/index.ts b/src/models/index.ts index f9dadc0..568c71f 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -12,6 +12,7 @@ export { default as PagerNumber, PagerNumberInterface, PagerNumberRaw } from './ export { default as Promo, PromoInterface } from './Promo'; export { default as Rank, RankInterface } from './Rank'; export { default as Redirect, RedirectInterface, RedirectRaw } from './Redirect'; +export { default as Resolution, ResolutionInterface } from './Resolution'; export { default as Score, ScoreInterface, ScoreInterfaceRaw } from './Score'; export { default as ScoreHistorical, ScoreHistoricalInterface } from './ScoreHistorical'; export { default as Staff, StaffInterface } from './Staff';