diff --git a/handler/attendant_application.js b/handler/attendant_application.js index c43dc06..fc50104 100644 --- a/handler/attendant_application.js +++ b/handler/attendant_application.js @@ -433,6 +433,64 @@ class HandlerAttendantApplication { } } + /** + * 待审核期间修改基本信息 + * + * 只允许 pending 状态修改姓名/手机号/性别/服务城市/个人简介; + * 证件材料、状态与审核信息不经过本接口,避免绕开审核流程。 + */ + async updateMyApplication(ctx) { + try { + const userId = ctx.state.user?._id; + if (!userId) return ResponseUtil.unauthorized(ctx, "登录已失效"); + + const application = await DBModel.AttendantApplication.findLatestByUser(userId); + if (!application) return ResponseUtil.notFound(ctx, "没有可修改的入驻申请"); + if (application.status !== "pending") { + return ResponseUtil.error( + ctx, + application.status === "approved" + ? "申请已通过审核,资料不可修改" + : "申请已驳回,请修改后重新提交", + null, + 409 + ); + } + + // 复用提交时的校验;材料部分不参与本次更新,只取 applicant + const result = HandlerAttendantApplication.parsePayload(ctx.request.body); + if (result.error) return ResponseUtil.badRequest(ctx, result.error); + + const applicant = result.value.applicant; + // 条件更新兜底并发审核:提交后管理员恰好先审完,这里不会覆盖已通过的申请 + const updated = await DBModel.AttendantApplication.findOneAndUpdate( + { _id: application._id, status: "pending" }, + { + $set: { + "applicant.name": applicant.name, + "applicant.mobile": applicant.mobile, + "applicant.sex": applicant.sex, + "applicant.serviceAreas": applicant.serviceAreas, + "applicant.introduction": applicant.introduction, + "meta.updatetime": Date.now(), + }, + }, + { new: true } + ).exec(); + if (!updated) { + return ResponseUtil.error(ctx, "申请状态已变更,请刷新后重试", null, 409); + } + + return ResponseUtil.success( + ctx, + { application: HandlerAttendantApplication.toReceipt(updated) }, + "个人信息已更新" + ); + } catch (err) { + return ResponseUtil.internalError(ctx, err); + } + } + /** * 证件材料后补 * diff --git a/routes/index.js b/routes/index.js index 6581a1f..cb99d3c 100644 --- a/routes/index.js +++ b/routes/index.js @@ -164,6 +164,8 @@ function registerRoutes(app) { // /mine 必须注册在 /:id 之前,否则会被当成 id router.post("/attendant-application", requireAuth, createLimit, handlerAttendantApplication.createApplication.bind(handlerAttendantApplication)); router.get("/attendant-application/mine", requireAuth, handlerAttendantApplication.getMyApplication.bind(handlerAttendantApplication)); + // 待审核期间修改基本信息:仅本人,且仅 pending 状态生效 + router.put("/attendant-application/mine", requireAuth, updateLimit, handlerAttendantApplication.updateMyApplication.bind(handlerAttendantApplication)); // 证件材料后补:审核通过后仍可补传,必须注册在 /:id 路由之前 router.post("/attendant-application/mine/materials", requireAuth, updateLimit, handlerAttendantApplication.updateMyMaterials.bind(handlerAttendantApplication)); router.get("/attendant-application", requireAuth, requireAdmin, handlerAttendantApplication.getApplications.bind(handlerAttendantApplication));