station.js 1.5 KB

1
  1. "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const egg_1=require("egg"),validate_1=require("../utils/validate"),normalize_1=require("../utils/normalize"),responseCode_1=require("../utils/responseCode"),moment=require("moment");class StationController extends egg_1.Controller{async handleUpload(){const{ctx:m,service:a}=this;if(validate_1.validate(m,{stationId:{type:"string",required:!0,allowEmpty:!1,trim:!0,min:8,max:8},date:{type:"date",required:!0},excellent:{type:"number",required:!0,min:0},good:{type:"number",required:!0,min:0},ordinary:{type:"number",required:!0,min:0},bad:{type:"number",required:!0,min:0},abandoned:{type:"number",required:!0,min:0}})){const{stationId:b,date:c,excellent:d,good:e,ordinary:f,bad:g,abandoned:h}=m.request.body,i={excellent:d,good:e,ordinary:f,bad:g,abandoned:h},[j,k]=await Promise.all([a.station.isIdExisted(b),a.station.isStationEnable(b)]);if(j&&k){const d=await a.evaluation.selectSpecific(b,c),e=Array.isArray(d)&&0<d.length?await a.evaluation.update(b,c,i):await a.evaluation.add(b,c,i);e?(m.response.body=normalize_1.NMLResponse(responseCode_1.ResponseCode.OK),a.station.updateTime(b,moment().format("YYYY-MM-DD HH:mm:ss")),m.logger.info(`${m.ip} uploads: ${JSON.stringify(i)}`)):m.response.body=normalize_1.NMLResponse(responseCode_1.ResponseCode.UNKNOWN,null,"uncaught error occured when update.")}else m.response.body=normalize_1.NMLResponse(responseCode_1.ResponseCode.STATION_ILEGAL,null,"\u6CB9\u7AD9\u7F16\u7801\u4E0D\u6B63\u786E")}}}exports.default=StationController;