75 lines
2.7 KiB
JavaScript
75 lines
2.7 KiB
JavaScript
const Controller = require('../core/base_controller');
|
|
|
|
const fileName = "Topic";
|
|
|
|
class TopicController extends Controller {
|
|
// 学生抽取/读取题目
|
|
async topic() {
|
|
const { ctx } = this;
|
|
try {
|
|
let rdmcode = await this.checkUid(ctx);
|
|
if (!rdmcode) {
|
|
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
|
return;
|
|
}
|
|
const uid = JSON.parse(rdmcode).uid;
|
|
const bind = await ctx.service.check.checkUser(uid);
|
|
if (!bind) {
|
|
this.setResponse(ctx, 333, '未绑定北斗卡', "none");
|
|
return;
|
|
}
|
|
const { answerId } = ctx.request.body;
|
|
const result = await ctx.service.topic.topic(uid, answerId);
|
|
if (bind == "error" || result == "error") {
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
return;
|
|
}
|
|
if (result.code == 200) {
|
|
const data = {
|
|
examination: result.examination,
|
|
shortMsg: result.shortMsg,
|
|
};
|
|
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
|
} else {
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
|
}
|
|
} catch (error) {
|
|
const blockName = fileName + "--" + "topic";
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
}
|
|
}
|
|
|
|
// 系统读取单选题
|
|
async radio() {
|
|
const { ctx } = this;
|
|
try {
|
|
let rdmcode = await this.checkUid(ctx);
|
|
if (!rdmcode) {
|
|
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
|
return;
|
|
}
|
|
const { radioArr } = ctx.request.body;
|
|
const result = await ctx.service.topic.radio(radioArr);
|
|
if (result == "error") {
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
return;
|
|
}
|
|
if (result) {
|
|
const data = {
|
|
radioTopic: result,
|
|
}
|
|
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
|
} else {
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
|
}
|
|
} catch (error) {
|
|
const blockName = fileName + "--" + "radio";
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = TopicController;
|