Files
danyang-match/miniapp/services/safetyService.js
T

41 lines
1.7 KiB
JavaScript
Raw Normal View History

2026-09-09 22:05:00 +08:00
/**
* 举报与安全服务(API_INVENTORY 行 110-111)
*
* 封装:提交举报 / 我的举报列表。
* 关键不变量(AGENTS.md):
* - 第 8 条:敏感数据默认拒绝——本层不接受身份证号、手机号等敏感字段,
* 举报内容只接收 reason + 证据图片 URL(已上传至 OSS)。
* - 第 4 条:Block 优先级最高——举报不会自动 Block,是否 Block 由用户主动调用
* matchService.block;举报后由运营人工处置。
*/
const api = require('../utils/api');
/**
* 提交举报(REST §81 章 POST /reports)
*
* 请求体字段对齐 REST 规范:targetUserId / reportType / description / evidenceFileIds。
* evidenceFileIds 为已上传至 OSS 的文件 ID 列表(由调用方先上传图片获取 fileId)。
*
* @param {{ targetUserId: string, reportType: import('../types').ReportType, description: string, evidenceFileIds?: string[] }} payload
* @returns {Promise<{ reportId: string, status: 'pending', submittedAt: number }>}
*/
function submitReport(payload) {
// 幂等键:目标用户 + 举报类型 + 当前秒,防止用户多次点击重复提交
const idempotencyKey = `report:${payload.targetUserId}:${payload.reportType}:${Math.floor(Date.now() / 1000)}`;
return api.post('/reports', payload, undefined, idempotencyKey);
}
/**
* 我的举报列表(REST §80 章 GET /me/reports)
* @param {{ cursor?: string, pageSize?: number, status?: string }} params
* @returns {Promise<{ items: Array<import('../types').Report>, nextCursor: string|null }>}
*/
function getMyReports(params = {}) {
return api.get('/me/reports', params);
}
module.exports = {
submitReport,
getMyReports,
};