54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
/**
|
||||
|
|
* 红娘转介服务(Phase 13)
|
|||
|
|
*
|
|||
|
|
* 封装「用户确认转介」的两阶段流程与「我的转介历史」。
|
|||
|
|
*
|
|||
|
|
* 关键不变量(AGENTS.md):
|
|||
|
|
* - 第 5 条:红娘不可替用户操作。转介由红娘发起(运营端),
|
|||
|
|
* **必须由用户本人在小程序确认** 才算生效 —— 本层只提供用户侧的
|
|||
|
|
* 确认与查询,不提供任何"代用户确认"的入口。
|
|||
|
|
* - 转介形成可追踪记录(source=matchmaker_referral + createdByOperatorId + userConfirmedAt)。
|
|||
|
|
*
|
|||
|
|
* 后端端点:
|
|||
|
|
* GET /api/v1/referrals/my-history — 我的转介历史(UserPrincipal)
|
|||
|
|
* POST /api/v1/referrals/{id}/confirm — 用户确认转介
|
|||
|
|
*/
|
|||
|
|
const api = require('../utils/api');
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 我的转介历史(含是否已确认)
|
|||
|
|
* @returns {Promise<Array<{
|
|||
|
|
* type: 'service_station'|'activity',
|
|||
|
|
* id: string,
|
|||
|
|
* status: string,
|
|||
|
|
* createdByOperatorId: string,
|
|||
|
|
* userConfirmedAt: string|null,
|
|||
|
|
* createdAt: string
|
|||
|
|
* }>>}
|
|||
|
|
*/
|
|||
|
|
function getMyReferralHistory() {
|
|||
|
|
return api.get('/referrals/my-history');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 用户确认转介(两阶段流程的第二阶段)
|
|||
|
|
*
|
|||
|
|
* ⚠️ 只有转介的目标用户本人可以确认;他人调用后端会拒绝。
|
|||
|
|
* @param {string} targetId 转介记录 ID(appointmentId 或 registrationId)
|
|||
|
|
* @param {'service_station'|'activity'} targetType
|
|||
|
|
* @returns {Promise<{ id: string, status: string, confirmedAt: string }>}
|
|||
|
|
*/
|
|||
|
|
function confirmReferral(targetId, targetType) {
|
|||
|
|
return api.post(
|
|||
|
|
`/referrals/${encodeURIComponent(targetId)}/confirm`,
|
|||
|
|
{ targetType },
|
|||
|
|
undefined,
|
|||
|
|
`referral-confirm:${targetId}:${targetType}`
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
module.exports = {
|
|||
|
|
getMyReferralHistory,
|
|||
|
|
confirmReferral,
|
|||
|
|
};
|