修改了bug
This commit is contained in:
@@ -8,6 +8,17 @@ class HandlerHealthProfile {
|
||||
// 白名单:只允许写入 schema 定义的顶层字段(兼容 'profile.name' 等点号路径)
|
||||
static PROFILE_FIELDS = ["userId", "profile", "location", "health"];
|
||||
|
||||
// 单页最大条数,避免 pageSize 传超大值一次拖库
|
||||
static MAX_PAGE_SIZE = 200;
|
||||
|
||||
// 解析分页参数并夹紧上限
|
||||
static parsePaging(query = {}) {
|
||||
const page = Math.max(1, parseInt(query.page) || 1);
|
||||
const rawSize = parseInt(query.pageSize) || 20;
|
||||
const pageSize = Math.min(Math.max(1, rawSize), HandlerHealthProfile.MAX_PAGE_SIZE);
|
||||
return { page, pageSize };
|
||||
}
|
||||
|
||||
static pickFields(body) {
|
||||
const picked = {};
|
||||
for (const key of Object.keys(body || {})) {
|
||||
@@ -23,11 +34,12 @@ class HandlerHealthProfile {
|
||||
|
||||
async getProfiles(ctx) {
|
||||
try {
|
||||
const { page = 1, pageSize = 20, userId, name, mobile, sortBy } = ctx.request.query;
|
||||
const { userId, name, mobile, sortBy } = ctx.request.query;
|
||||
const { page, pageSize } = HandlerHealthProfile.parsePaging(ctx.request.query);
|
||||
|
||||
const result = await DBModel.HealthProfile.findProfiles({
|
||||
page: parseInt(page),
|
||||
pageSize: parseInt(pageSize),
|
||||
page,
|
||||
pageSize,
|
||||
userId,
|
||||
name,
|
||||
mobile,
|
||||
@@ -43,12 +55,13 @@ class HandlerHealthProfile {
|
||||
// 查询"我的"健康档案列表:强制以登录用户身份查询,忽略请求中的 userId
|
||||
async getMyProfiles(ctx) {
|
||||
try {
|
||||
const { page = 1, pageSize = 20, name, mobile, sortBy } = ctx.request.query;
|
||||
const { name, mobile, sortBy } = ctx.request.query;
|
||||
const { page, pageSize } = HandlerHealthProfile.parsePaging(ctx.request.query);
|
||||
const userId = ctx.state.user?._id;
|
||||
|
||||
const result = await DBModel.HealthProfile.findProfiles({
|
||||
page: parseInt(page),
|
||||
pageSize: parseInt(pageSize),
|
||||
page,
|
||||
pageSize,
|
||||
userId,
|
||||
name,
|
||||
mobile,
|
||||
|
||||
Reference in New Issue
Block a user