增加健康档案api

This commit is contained in:
lik
2026-08-27 21:54:51 +08:00
parent 1f10eb3c92
commit 644f4bc7cb
4 changed files with 255 additions and 0 deletions
+96
View File
@@ -0,0 +1,96 @@
import { DBModel } from "../models/index.js";
import ResponseUtil from "../utils/responseUtil.js";
class HandlerHealthProfile {
constructor() {
}
async getProfiles(ctx) {
try {
const { page = 1, pageSize = 20, userId, name, mobile, sortBy } = ctx.request.query;
const result = await DBModel.HealthProfile.findProfiles({
page: parseInt(page),
pageSize: parseInt(pageSize),
userId,
name,
mobile,
sortBy,
});
return ResponseUtil.success(ctx, result, "查询成功");
} catch (err) {
return ResponseUtil.internalError(ctx, err.message);
}
}
async getProfileById(ctx) {
try {
const { id } = ctx.params;
if (!id) {
return ResponseUtil.badRequest(ctx, "缺少档案ID");
}
const profile = await DBModel.HealthProfile.findProfileById(id);
if (!profile) {
return ResponseUtil.notFound(ctx, "健康档案不存在");
}
return ResponseUtil.success(ctx, { profile }, "查询成功");
} catch (err) {
return ResponseUtil.internalError(ctx, err.message);
}
}
async createProfile(ctx) {
try {
const body = ctx.request.body;
const newProfile = await DBModel.HealthProfile.createProfile(body);
return ResponseUtil.success(ctx, { profile: newProfile }, "创建成功");
} catch (err) {
return ResponseUtil.internalError(ctx, err.message);
}
}
async updateProfile(ctx) {
try {
const { id } = ctx.params;
const update = ctx.request.body;
if (!id) {
return ResponseUtil.badRequest(ctx, "缺少档案ID");
}
const updatedProfile = await DBModel.HealthProfile.updateProfileById(id, update);
if (!updatedProfile) {
return ResponseUtil.notFound(ctx, "健康档案不存在");
}
return ResponseUtil.success(ctx, { profile: updatedProfile }, "更新成功");
} catch (err) {
return ResponseUtil.internalError(ctx, err.message);
}
}
async deleteProfile(ctx) {
try {
const { id } = ctx.params;
if (!id) {
return ResponseUtil.badRequest(ctx, "缺少档案ID");
}
const deletedProfile = await DBModel.HealthProfile.deleteProfileById(id);
if (!deletedProfile) {
return ResponseUtil.notFound(ctx, "健康档案不存在");
}
return ResponseUtil.success(ctx, { profile: deletedProfile }, "删除成功");
} catch (err) {
return ResponseUtil.internalError(ctx, err.message);
}
}
}
export { HandlerHealthProfile };