fixes to api for reports
parent
16554a0f29
commit
5ae9602f0a
|
@ -11,17 +11,17 @@ export default class Report extends Route {
|
|||
public bind() {
|
||||
this.router.post('/hard', async (req, res) => {
|
||||
try {
|
||||
if (!req.headers.authorization) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.codes.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.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.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 });
|
||||
|
||||
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();
|
||||
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 activityScore: number;
|
||||
|
@ -88,5 +88,37 @@ export default class Report extends Route {
|
|||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(`__**`)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -64,6 +64,7 @@ export default class Route {
|
|||
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.'],
|
||||
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.'],
|
||||
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.'],
|
||||
|
|
|
@ -22,8 +22,8 @@ export default class Server {
|
|||
this.port = port;
|
||||
this.root = routeRoot;
|
||||
|
||||
this.loadRoutes();
|
||||
this.init();
|
||||
this.loadRoutes();
|
||||
}
|
||||
|
||||
get client() {
|
||||
|
@ -50,8 +50,8 @@ export default class Server {
|
|||
}
|
||||
|
||||
public init() {
|
||||
this.app.set('trust proxy', 'loopback');
|
||||
this.app.use(bodyParser.json());
|
||||
this.app.set('trust proxy', 'loopback');
|
||||
this.app.use(helmet({
|
||||
hsts: false,
|
||||
hidePoweredBy: false,
|
||||
|
|
|
@ -151,4 +151,22 @@ export default class Util {
|
|||
public encode(arg: string) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue