cloudservices/src/cscli/score.ts

24 lines
826 B
TypeScript
Raw Normal View History

2020-12-18 19:24:08 -05:00
import { TCPHandler, Context, Report } from '../class';
2020-12-18 18:27:23 -05:00
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());
}
}