fixes to api for reports

pull/29/head
Matthew 2020-09-29 23:44:20 -04:00
parent 16554a0f29
commit 5ae9602f0a
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
5 changed files with 89 additions and 7 deletions

View File

@ -11,17 +11,17 @@ export default class Report extends Route {
public bind() { public bind() {
this.router.post('/hard', async (req, res) => { this.router.post('/hard', async (req, res) => {
try { try {
if (!req.headers.authorization) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.codes.UNAUTHORIZED }); if (!req.headers.authorization) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (!req.body.pin || !req.body.userID || !req.body.reason) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.codes.CLIENT_ERROR }); if (!req.body.pin || !req.body.userID || !req.body.reason) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.messages.CLIENT_ERROR });
if (req.body.reason?.length < 1) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.codes.CLIENT_ERROR }); if (req.body.reason?.length < 1) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.codes.CLIENT_ERROR });
const merchant = await this.server.client.db.Merchant.findOne({ key: req.headers.authorization }).lean().exec(); const merchant = await this.server.client.db.Merchant.findOne({ key: req.headers.authorization }).lean().exec();
if (!merchant) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.codes.UNAUTHORIZED }); if (!merchant) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
const member = await this.server.client.db.Score.findOne({ userID: req.body.userID, 'pin.2': req.body.pin }).lean().exec(); const member = await this.server.client.db.Score.findOne({ userID: req.body.userID, 'pin.2': req.body.pin }).lean().exec();
if (!member) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.codes.UNAUTHORIZED }); if (!member) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (member.locked) return res.status(403).json({ code: this.constants.codes.PERMISSION_DENIED, message: this.constants.codes.PERMISSION_DENIED }); if (member.locked) return res.status(403).json({ code: this.constants.codes.PERMISSION_DENIED, message: this.constants.messages.PERMISSION_DENIED });
let totalScore: number; let totalScore: number;
let activityScore: number; let activityScore: number;
@ -88,5 +88,37 @@ export default class Report extends Route {
return this.handleError(err, res); return this.handleError(err, res);
} }
}); });
this.router.post('/soft', async (req, res) => {
try {
if (!req.headers.authorization) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (!req.body.pin || !req.body.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.messages.CLIENT_ERROR });
const merchant = await this.server.client.db.Merchant.findOne({ key: req.headers.authorization }).lean().exec();
if (!merchant) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
const member = await this.server.client.db.Score.findOne({ userID: req.body.userID, 'pin.2': req.body.pin }).lean().exec();
if (!member) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
let totalScore: number;
if (member.total < 200) totalScore = 0;
else if (member.total > 800) totalScore = 800;
else totalScore = Math.round(member.total);
await this.server.client.db.Merchant.updateOne({ key: req.headers.authorization }, { $addToSet: { pulls: { type: 1, reason: 'N/A', date: new Date() } } });
await this.server.client.db.Score.updateOne({ userID: member.userID }, { $addToSet: { softInquiries: { name: merchant.name, date: new Date() } } });
return res.status(200).json({
code: this.constants.codes.SUCCESS,
message: {
userID: member.userID,
totalScore,
},
});
} catch (err) {
return this.handleError(err, res);
}
});
} }
} }

31
src/class/AutoMod.ts Normal file
View File

@ -0,0 +1,31 @@
/* eslint-disable no-bitwise */
import { Member, Message, User } from 'eris';
import { randomBytes } from 'crypto';
import moment, { unitOfTime } from 'moment';
import { Client, Moderation, RichEmbed } from '.';
import { Moderation as ModerationModel, ModerationInterface } from '../models';
import { moderation as channels } from '../configs/channels.json';
export default class AutoMod extends Moderation {
public client: Client;
public list: Set<string>
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(client: Client) {
super(client);
this.list = new Set();
}
public run(message: Message, member: Member) {
try {
if (member)
}
}
public warn(message: Message, member: Member) {
try {
await message.channel.createMessage(`__**`)
}
}
}

View File

@ -64,6 +64,7 @@ export default class Route {
PERMISSION_DENIED: ['PERMISSION_DENIED', 'You do not have valid credentials to access this resource.'], PERMISSION_DENIED: ['PERMISSION_DENIED', 'You do not have valid credentials to access this resource.'],
NOT_FOUND: ['NOT_FOUND', 'The resource you requested cannot be located.'], NOT_FOUND: ['NOT_FOUND', 'The resource you requested cannot be located.'],
ENDPOINT_NOT_FOUND: ['ENDPOINT_NOT_FOUND', 'The endpoint you requested does not exist or cannot be located.'], ENDPOINT_NOT_FOUND: ['ENDPOINT_NOT_FOUND', 'The endpoint you requested does not exist or cannot be located.'],
CLIENT_ERROR: ['CLIENT_ERROR', 'The information provided to this endpoint via headers, body, query, or parameters are invalid.'],
SERVER_ERROR: ['INTERNAL_ERROR', 'An internal error has occurred, Engineers have been notified.'], SERVER_ERROR: ['INTERNAL_ERROR', 'An internal error has occurred, Engineers have been notified.'],
DEPRECATED: ['ENDPOINT_OR_RESOURCE_DEPRECATED', 'The endpoint or resource you\'re trying to access has been deprecated.'], DEPRECATED: ['ENDPOINT_OR_RESOURCE_DEPRECATED', 'The endpoint or resource you\'re trying to access has been deprecated.'],
MAINTENANCE_OR_UNAVAILABLE: ['SERVICE_UNAVAILABLE', 'The endpoint or resource you\'re trying to access is either in maintenance or is not available.'], MAINTENANCE_OR_UNAVAILABLE: ['SERVICE_UNAVAILABLE', 'The endpoint or resource you\'re trying to access is either in maintenance or is not available.'],

View File

@ -22,8 +22,8 @@ export default class Server {
this.port = port; this.port = port;
this.root = routeRoot; this.root = routeRoot;
this.loadRoutes();
this.init(); this.init();
this.loadRoutes();
} }
get client() { get client() {
@ -50,8 +50,8 @@ export default class Server {
} }
public init() { public init() {
this.app.set('trust proxy', 'loopback');
this.app.use(bodyParser.json()); this.app.use(bodyParser.json());
this.app.set('trust proxy', 'loopback');
this.app.use(helmet({ this.app.use(helmet({
hsts: false, hsts: false,
hidePoweredBy: false, hidePoweredBy: false,

View File

@ -151,4 +151,22 @@ export default class Util {
public encode(arg: string) { public encode(arg: string) {
return arg.split('').map((x) => x.charCodeAt(0) / 400); return arg.split('').map((x) => x.charCodeAt(0) / 400);
} }
public normalize(string) {
const input = [];
// eslint-disable-next-line no-plusplus
for (let i = 0; i < string.length; i++) {
input.push(string.charCodeAt(i) / 1000);
}
return input;
}
public convert_ascii(ascii: []) {
let string = '';
// eslint-disable-next-line no-plusplus
for (let i = 0; i < ascii.length; i++) {
string += String.fromCharCode(ascii[i] * 4000);
}
return string;
}
} }