cloudservices/src/cscli/score.ts

24 lines
820 B
TypeScript
Raw Normal View History

2021-04-19 23:43:02 -04:00
import { Handler, Context, Report } from '../class';
2020-12-18 18:27:23 -05:00
2021-04-19 23:43:02 -04:00
export default class Score extends Handler {
2020-12-18 18:27:23 -05:00
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());
}
}