chengjie недель назад: 2
Родитель
Сommit
8587c0791c
2 измененных файлов с 10 добавлено и 4 удалено
  1. 9 4
      src/api/mps/mpsSchoolController.js
  2. 1 0
      src/app.js

+ 9 - 4
src/api/mps/mpsSchoolController.js

@@ -6,6 +6,11 @@ import commonModel from '../../model/commonModel.js';
6 6
 import mps, { ArrYear, getDistrict } from '../../model/mps.js';
7 7
 import _ from 'lodash';
8 8
 
9
+function toNumberParam(value, fallback = 0) {
10
+    const number = Number(value);
11
+    return Number.isFinite(number) ? number : fallback;
12
+}
13
+
9 14
 /**
10 15
  * 得到所有区
11 16
  */
@@ -570,7 +575,7 @@ export async function GetMPSSchoolWeb(ctx) {
570 575
 //得到用户收藏学校
571 576
 export async function GetMPSSchoolCollect(ctx) {
572 577
     const param = {
573
-        UserID: ctx.query.UserID || 0,
578
+        UserID: toNumberParam(ctx.query.UserID),
574 579
     };
575 580
     
576 581
     const result = {};
@@ -602,9 +607,9 @@ export async function GetMPSSchoolCollect(ctx) {
602 607
 //更新收藏学校
603 608
 export async function UpdateMPSSchoolCollect(ctx) {
604 609
     const param = {
605
-        UserID: ctx.query.UserID || 0,
606
-        SchoolID: ctx.query.SchoolID || 0,
607
-        IsCollect: ctx.query.IsCollect || 0,
610
+        UserID: toNumberParam(ctx.query.UserID),
611
+        SchoolID: toNumberParam(ctx.query.SchoolID),
612
+        IsCollect: toNumberParam(ctx.query.IsCollect),
608 613
     };
609 614
     let sql = "delete from MPS_UserCollect where UserID=" + param.UserID + " and SchoolID=" + param.SchoolID;
610 615
     await commonModel.RunSql({}, sql);

+ 1 - 0
src/app.js

@@ -94,6 +94,7 @@ app.use(internalRouter.allowedMethods());
94 94
 
95 95
 //中间件
96 96
 app.use(decryptUrlMiddle());
97
+app.use(queryParamSanitizer());
97 98
 
98 99
 // 注册路由
99 100
 app.use(commonRouter.routes());