工作相关:作业无法提交问题排查

记录一次比较难定位的后端问题
更新于: 2022-01-18 08:14:04
从 get 接口看出问题的原因

查所有作业 units

SELECT * FROM homework_units WHERE homework_id = 123123 AND `type` = 0;

查所有的 finish_rate 在数据表中数据 

select * from homework_unit_results where homework_result_id="123123";

临时修复脚本

npm i parse-curl clipboardy@2 node-fetch@2 @jswork/next @jswork/next-hashlize
const parseCurl = require("parse-curl");
const clipboardy = require("clipboardy");
const nx = require("@jswork/next");
const fetch = require("node-fetch");
require("@jswork/next-hashlize");
const curlStr = clipboardy.readSync();
const { url, ...data } = parseCurl(curlStr);
data.headers = data.header;

(async function () {
  const hmData = await fetch(url, data).then((r) => r.json());
  const extend_units_id = nx.get(hmData, "data.id");
  const { homework_id } = nx.hashlize(url);
  const ids = nx.get(hmData, "meta.finished_exercise_ids");
  const newUrl = `https://student-api.alo7.com/api/v1/extend_units/${extend_units_id}/exercise_results`;
  const newData = {
    id: extend_units_id,
    results: ids.map((id) => ({ eid: id })),
    homework_id,
  };

  await fetch(newUrl, {
    ...data,
    method: "POST",
    body: JSON.stringify(newData),
  });
})();

参考