import { TCPHandler, Context, Report } from '../class'; export default class Score extends TCPHandler { constructor() { super(); this.endpoint = 'score'; } public async handle(ctx: Context) { const acc = await ctx.client.db.Account.findOne({ username: ctx.data.username }); if (!acc) { return ctx.socket.destroy(); } const pin = await Report.getPIN(acc.userID, ctx.client.config.internalKey); if (pin.status !== 'SUCCESS') { return ctx.socket.destroy(); } const report = await Report.soft(acc.userID, pin.pin[2], ctx.client.config.vendorKey); if (report.status !== 'SUCCESS') { return ctx.socket.destroy(); } if (!report.totalScore) { return ctx.send('N/C'); } if (report.totalScore === 0) { return ctx.send('---'); } return ctx.send(report.totalScore.toString()); } }