403 lines
22 KiB
JavaScript
403 lines
22 KiB
JavaScript
import { createRequestError } from './request-client.js'
|
|
import {
|
|
normalizeNormalDisableResponseStatus,
|
|
normalizeOptionalCurrencyAmount,
|
|
normalizeOptionalNonnegativeInteger,
|
|
normalizeOptionalNumericId,
|
|
normalizeResponseText
|
|
} from './response-normalizers.js'
|
|
import {
|
|
assertPlainPayload,
|
|
normalizeOptionalNormalDisableStatus,
|
|
normalizeOptionalCurrencyNumber,
|
|
normalizeOptionalOssIdList,
|
|
normalizeOptionalSafeInteger,
|
|
normalizeOptionalText,
|
|
normalizeOssIdString,
|
|
normalizeResourcePathId
|
|
} from './request-normalizers.js'
|
|
import {
|
|
normalizeBusinessFileAccessRows,
|
|
normalizeContentProtectionCapabilities,
|
|
normalizeResourceCapabilities
|
|
} from './business-file-contract.js'
|
|
import { normalizeBusinessOptionProjection } from './business-dictionary-contract.js'
|
|
|
|
const freezeOptions = (options) =>
|
|
Object.freeze(options.map((option) => Object.freeze(option)))
|
|
|
|
export const MERIT_TYPE_OPTIONS = freezeOptions([
|
|
{ value: 'donation', label: '捐赠' },
|
|
{ value: 'repair', label: '修祠' },
|
|
{ value: 'public', label: '公益' },
|
|
{ value: 'other', label: '其他' }
|
|
])
|
|
|
|
export const LIFE_EVENT_TYPE_OPTIONS = freezeOptions([
|
|
{ value: 'BIRTH', label: '出生' },
|
|
{ value: 'EDUCATION', label: '求学' },
|
|
{ value: 'CAREER', label: '事业' },
|
|
{ value: 'MARRIAGE', label: '婚姻' },
|
|
{ value: 'MIGRATION', label: '迁居' },
|
|
{ value: 'HONOR', label: '荣誉' },
|
|
{ value: 'MAJOR_ACHIEVEMENT', label: '重要成就' },
|
|
{ value: 'DEATH', label: '逝世' },
|
|
{ value: 'OTHER', label: '其他' }
|
|
])
|
|
|
|
export const LIFE_EVENT_DATE_PRECISION_OPTIONS = freezeOptions([
|
|
{ value: 'YEAR', label: '只填年份' },
|
|
{ value: 'MONTH', label: '填到月份' },
|
|
{ value: 'DAY', label: '填到日期' }
|
|
])
|
|
|
|
export const MEMO_TYPE = Object.freeze({
|
|
GENERAL: 'general',
|
|
BENEFACTOR: 'benefactor'
|
|
})
|
|
|
|
const memoTypes = new Set(Object.values(MEMO_TYPE))
|
|
|
|
export const normalizeAppGrowthRecord = (value, expectedGenealogyId, expectedRecordId = '') => {
|
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
throw createRequestError('成长记录响应无效', 'GROWTH_RECORD_RESPONSE_INVALID')
|
|
}
|
|
const id = normalizeOptionalNumericId(value.recordId, '成长记录标识', 'GROWTH_RECORD_RESPONSE_INVALID')
|
|
const genealogyId = normalizeOptionalNumericId(value.genealogyId, '成长记录家谱标识', 'GROWTH_RECORD_RESPONSE_INVALID')
|
|
if (!id || genealogyId !== expectedGenealogyId || (expectedRecordId && id !== expectedRecordId)) {
|
|
throw createRequestError('成长记录响应缺少稳定归属字段', 'GROWTH_RECORD_RESPONSE_INVALID')
|
|
}
|
|
const recordType = normalizeBusinessOptionProjection(
|
|
value.recordType,
|
|
value.recordTypeLabel,
|
|
value.recordTypeOptionState,
|
|
'成长记录类型',
|
|
'GROWTH_RECORD_RESPONSE_INVALID'
|
|
)
|
|
return {
|
|
id,
|
|
genealogyId,
|
|
lineagePersonId: normalizeOptionalNumericId(value.lineagePersonId, '成长记录人物标识', 'GROWTH_RECORD_RESPONSE_INVALID'),
|
|
personName: normalizeResponseText(value.lineagePersonName, 'lineagePersonName') || '未关联人物',
|
|
type: recordType.value,
|
|
typeLabel: recordType.label,
|
|
typeOptionState: recordType.state,
|
|
title: normalizeResponseText(value.recordTitle, 'recordTitle') || '未命名记录',
|
|
content: normalizeResponseText(value.recordContent, 'recordContent'),
|
|
recordDate: normalizeResponseText(value.recordDate, 'recordDate'),
|
|
remindTime: normalizeResponseText(value.remindTime, 'remindTime'),
|
|
date: normalizeResponseText(value.recordDate, 'recordDate') || normalizeResponseText(value.remindTime, 'remindTime'),
|
|
createTime: normalizeResponseText(value.createTime, 'createTime'),
|
|
mediaFiles: normalizeBusinessFileAccessRows(value.mediaFiles, '成长记录媒体', 'GROWTH_RECORD_RESPONSE_INVALID'),
|
|
sortOrder: normalizeOptionalNonnegativeInteger(value.sortOrder, '成长记录排序值', 'GROWTH_RECORD_RESPONSE_INVALID'),
|
|
status: normalizeNormalDisableResponseStatus(value.status, '成长记录状态', 'GROWTH_RECORD_RESPONSE_INVALID'),
|
|
...normalizeContentProtectionCapabilities(value, '成长记录', 'GROWTH_RECORD_RESPONSE_INVALID'),
|
|
...normalizeResourceCapabilities(value, '成长记录', 'GROWTH_RECORD_RESPONSE_INVALID')
|
|
}
|
|
}
|
|
|
|
export const normalizeAppGrowthRecords = (value, expectedGenealogyId) => {
|
|
if (!Array.isArray(value)) throw createRequestError('成长记录响应不是列表', 'GROWTH_RECORD_RESPONSE_INVALID')
|
|
const records = value.map((item) => normalizeAppGrowthRecord(item, expectedGenealogyId))
|
|
if (new Set(records.map((item) => item.id)).size !== records.length) {
|
|
throw createRequestError('成长记录响应包含重复标识', 'GROWTH_RECORD_RESPONSE_INVALID')
|
|
}
|
|
return records
|
|
}
|
|
|
|
const lifeEventTypes = new Set(LIFE_EVENT_TYPE_OPTIONS.map(({ value }) => value))
|
|
const lifeEventDatePrecisions = new Set(
|
|
LIFE_EVENT_DATE_PRECISION_OPTIONS.map(({ value }) => value)
|
|
)
|
|
|
|
const normalizeLifeEventDate = (value, label, code) => {
|
|
const normalized = normalizeResponseText(value, label)
|
|
if (!/^\d{4}-\d{2}-\d{2}$/.test(normalized)) {
|
|
throw createRequestError(`${label}无效`, code)
|
|
}
|
|
const [year, month, day] = normalized.split('-').map(Number)
|
|
const parsed = new Date(Date.UTC(year, month - 1, day))
|
|
if (parsed.getUTCFullYear() !== year || parsed.getUTCMonth() !== month - 1 || parsed.getUTCDate() !== day) {
|
|
throw createRequestError(`${label}无效`, code)
|
|
}
|
|
return normalized
|
|
}
|
|
|
|
export const normalizeAppLifeEvent = (value, expectedGenealogyId, expectedLineagePersonId, expectedEventId = '') => {
|
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
throw createRequestError('人生大事响应无效', 'LIFE_EVENT_RESPONSE_INVALID')
|
|
}
|
|
const id = normalizeOptionalNumericId(value.eventId, '人生大事标识', 'LIFE_EVENT_RESPONSE_INVALID')
|
|
const genealogyId = normalizeOptionalNumericId(value.genealogyId, '人生大事家谱标识', 'LIFE_EVENT_RESPONSE_INVALID')
|
|
const lineagePersonId = normalizeOptionalNumericId(value.lineagePersonId, '人生大事人物标识', 'LIFE_EVENT_RESPONSE_INVALID')
|
|
if (
|
|
!id ||
|
|
genealogyId !== expectedGenealogyId ||
|
|
lineagePersonId !== expectedLineagePersonId ||
|
|
(expectedEventId && id !== expectedEventId)
|
|
) {
|
|
throw createRequestError('人生大事响应缺少稳定归属字段', 'LIFE_EVENT_RESPONSE_INVALID')
|
|
}
|
|
const type = normalizeResponseText(value.eventType, 'eventType')
|
|
const datePrecision = normalizeResponseText(value.datePrecision, 'datePrecision')
|
|
const title = normalizeResponseText(value.eventTitle, 'eventTitle')
|
|
if (!lifeEventTypes.has(type) || !lifeEventDatePrecisions.has(datePrecision) || !title) {
|
|
throw createRequestError('人生大事响应缺少有效必填字段', 'LIFE_EVENT_RESPONSE_INVALID')
|
|
}
|
|
return {
|
|
id,
|
|
genealogyId,
|
|
lineagePersonId,
|
|
type,
|
|
title,
|
|
content: normalizeResponseText(value.eventContent, 'eventContent'),
|
|
date: normalizeLifeEventDate(value.eventDate, 'eventDate', 'LIFE_EVENT_RESPONSE_INVALID'),
|
|
datePrecision,
|
|
place: normalizeResponseText(value.eventPlace, 'eventPlace'),
|
|
sourceDescription: normalizeResponseText(value.sourceDescription, 'sourceDescription'),
|
|
mediaFiles: normalizeBusinessFileAccessRows(value.mediaFiles, '人生大事媒体', 'LIFE_EVENT_RESPONSE_INVALID'),
|
|
...normalizeResourceCapabilities(value, '人生大事', 'LIFE_EVENT_RESPONSE_INVALID')
|
|
}
|
|
}
|
|
|
|
export const normalizeAppLifeEvents = (value, expectedGenealogyId, expectedLineagePersonId) => {
|
|
if (!Array.isArray(value)) throw createRequestError('人生大事响应不是列表', 'LIFE_EVENT_RESPONSE_INVALID')
|
|
const events = value.map((item) => normalizeAppLifeEvent(item, expectedGenealogyId, expectedLineagePersonId))
|
|
if (new Set(events.map((item) => item.id)).size !== events.length) {
|
|
throw createRequestError('人生大事响应包含重复标识', 'LIFE_EVENT_RESPONSE_INVALID')
|
|
}
|
|
return events
|
|
}
|
|
|
|
export const normalizeAppRelativeRecord = (value, expectedGenealogyId, expectedRelativeId = '') => {
|
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
throw createRequestError('亲友往来响应无效', 'RELATIVE_RECORD_RESPONSE_INVALID')
|
|
}
|
|
const id = normalizeOptionalNumericId(value.relativeId, '亲友记录标识', 'RELATIVE_RECORD_RESPONSE_INVALID')
|
|
const genealogyId = normalizeOptionalNumericId(value.genealogyId, '亲友记录家谱标识', 'RELATIVE_RECORD_RESPONSE_INVALID')
|
|
if (!id || genealogyId !== expectedGenealogyId || (expectedRelativeId && id !== expectedRelativeId)) {
|
|
throw createRequestError('亲友往来响应缺少稳定归属字段', 'RELATIVE_RECORD_RESPONSE_INVALID')
|
|
}
|
|
return {
|
|
id,
|
|
genealogyId,
|
|
name: normalizeResponseText(value.relativeName, 'relativeName') || '未命名亲友',
|
|
relation: normalizeResponseText(value.relationName, 'relationName'),
|
|
event: normalizeResponseText(value.eventName, 'eventName'),
|
|
time: normalizeResponseText(value.eventTime, 'eventTime'),
|
|
eventTime: normalizeResponseText(value.eventTime, 'eventTime'),
|
|
createTime: normalizeResponseText(value.createTime, 'createTime'),
|
|
amount: normalizeOptionalCurrencyAmount(value.giftAmount, '亲友礼金金额', 'RELATIVE_RECORD_RESPONSE_INVALID'),
|
|
content: normalizeResponseText(value.recordContent, 'recordContent'),
|
|
mediaFiles: normalizeBusinessFileAccessRows(value.mediaFiles, '亲友往来媒体', 'RELATIVE_RECORD_RESPONSE_INVALID'),
|
|
sortOrder: normalizeOptionalNonnegativeInteger(value.sortOrder, '亲友往来排序值', 'RELATIVE_RECORD_RESPONSE_INVALID'),
|
|
status: normalizeNormalDisableResponseStatus(value.status, '亲友往来状态', 'RELATIVE_RECORD_RESPONSE_INVALID'),
|
|
...normalizeResourceCapabilities(value, '亲友往来', 'RELATIVE_RECORD_RESPONSE_INVALID')
|
|
}
|
|
}
|
|
|
|
export const normalizeAppRelativeRecords = (value, expectedGenealogyId) => {
|
|
if (!Array.isArray(value)) throw createRequestError('亲友往来响应不是列表', 'RELATIVE_RECORD_RESPONSE_INVALID')
|
|
const records = value.map((item) => normalizeAppRelativeRecord(item, expectedGenealogyId))
|
|
if (new Set(records.map((item) => item.id)).size !== records.length) {
|
|
throw createRequestError('亲友往来响应包含重复标识', 'RELATIVE_RECORD_RESPONSE_INVALID')
|
|
}
|
|
return records
|
|
}
|
|
|
|
export const normalizeAppMemo = (value, expectedGenealogyId, expectedMemoId = '') => {
|
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
throw createRequestError('备忘录响应无效', 'MEMO_RESPONSE_INVALID')
|
|
}
|
|
const id = normalizeOptionalNumericId(value.memoId, '备忘标识', 'MEMO_RESPONSE_INVALID')
|
|
const genealogyId = normalizeOptionalNumericId(value.genealogyId, '备忘家谱标识', 'MEMO_RESPONSE_INVALID')
|
|
if (!id || genealogyId !== expectedGenealogyId || (expectedMemoId && id !== expectedMemoId)) {
|
|
throw createRequestError('备忘录响应缺少稳定归属字段', 'MEMO_RESPONSE_INVALID')
|
|
}
|
|
const memoType = normalizeResponseText(value.memoType, 'memoType')
|
|
if (!memoTypes.has(memoType)) {
|
|
throw createRequestError('备忘录响应类型无效', 'MEMO_RESPONSE_INVALID')
|
|
}
|
|
return {
|
|
id,
|
|
genealogyId,
|
|
memoType,
|
|
title: normalizeResponseText(value.memoTitle, 'memoTitle') || '未命名备忘',
|
|
remindTime: normalizeResponseText(value.remindTime, 'remindTime'),
|
|
content: normalizeResponseText(value.memoContent, 'memoContent'),
|
|
completed: normalizeResponseText(value.completed, 'completed'),
|
|
createTime: normalizeResponseText(value.createTime, 'createTime'),
|
|
mediaFiles: normalizeBusinessFileAccessRows(value.mediaFiles, '备忘媒体', 'MEMO_RESPONSE_INVALID'),
|
|
sortOrder: normalizeOptionalNonnegativeInteger(value.sortOrder, '备忘排序值', 'MEMO_RESPONSE_INVALID'),
|
|
status: normalizeNormalDisableResponseStatus(value.status, '备忘状态', 'MEMO_RESPONSE_INVALID'),
|
|
...normalizeResourceCapabilities(value, '备忘录', 'MEMO_RESPONSE_INVALID')
|
|
}
|
|
}
|
|
|
|
export const normalizeAppMemos = (value, expectedGenealogyId) => {
|
|
if (!Array.isArray(value)) throw createRequestError('备忘录响应不是列表', 'MEMO_RESPONSE_INVALID')
|
|
const memos = value.map((item) => normalizeAppMemo(item, expectedGenealogyId))
|
|
if (new Set(memos.map((item) => item.id)).size !== memos.length) {
|
|
throw createRequestError('备忘录响应包含重复标识', 'MEMO_RESPONSE_INVALID')
|
|
}
|
|
return memos
|
|
}
|
|
|
|
export const normalizeAppMeritRecord = (value, expectedGenealogyId, expectedMeritId = '') => {
|
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
throw createRequestError('功德记录响应无效', 'MERIT_RECORD_RESPONSE_INVALID')
|
|
}
|
|
const id = normalizeOptionalNumericId(value.meritId, '功德记录标识', 'MERIT_RECORD_RESPONSE_INVALID')
|
|
const genealogyId = normalizeOptionalNumericId(value.genealogyId, '功德记录家谱标识', 'MERIT_RECORD_RESPONSE_INVALID')
|
|
if (!id || genealogyId !== expectedGenealogyId || (expectedMeritId && id !== expectedMeritId)) {
|
|
throw createRequestError('功德记录响应缺少稳定归属字段', 'MERIT_RECORD_RESPONSE_INVALID')
|
|
}
|
|
const meritType = normalizeBusinessOptionProjection(
|
|
value.meritType,
|
|
value.meritTypeLabel,
|
|
value.meritTypeOptionState,
|
|
'功德类型',
|
|
'MERIT_RECORD_RESPONSE_INVALID'
|
|
)
|
|
return {
|
|
id,
|
|
genealogyId,
|
|
donor: normalizeResponseText(value.donorName, 'donorName') || '未署名',
|
|
title: normalizeResponseText(value.meritTitle, 'meritTitle') || '未命名功德',
|
|
type: meritType.value,
|
|
typeLabel: meritType.label,
|
|
typeOptionState: meritType.state,
|
|
amount: normalizeOptionalCurrencyAmount(value.amount, '功德金额', 'MERIT_RECORD_RESPONSE_INVALID', { required: true }),
|
|
time: normalizeResponseText(value.meritTime, 'meritTime'),
|
|
createTime: normalizeResponseText(value.createTime, 'createTime'),
|
|
content: normalizeResponseText(value.meritContent, 'meritContent'),
|
|
mediaFiles: normalizeBusinessFileAccessRows(value.mediaFiles, '功德记录图片', 'MERIT_RECORD_RESPONSE_INVALID'),
|
|
sortOrder: normalizeOptionalNonnegativeInteger(value.sortOrder, '功德记录排序值', 'MERIT_RECORD_RESPONSE_INVALID'),
|
|
status: normalizeNormalDisableResponseStatus(value.status, '功德记录状态', 'MERIT_RECORD_RESPONSE_INVALID'),
|
|
...normalizeResourceCapabilities(value, '功德记录', 'MERIT_RECORD_RESPONSE_INVALID')
|
|
}
|
|
}
|
|
|
|
export const normalizeAppMeritRecords = (value, expectedGenealogyId) => {
|
|
if (!Array.isArray(value)) throw createRequestError('功德记录响应不是列表', 'MERIT_RECORD_RESPONSE_INVALID')
|
|
const records = value.map((item) => normalizeAppMeritRecord(item, expectedGenealogyId))
|
|
if (new Set(records.map((item) => item.id)).size !== records.length) {
|
|
throw createRequestError('功德记录响应包含重复标识', 'MERIT_RECORD_RESPONSE_INVALID')
|
|
}
|
|
return records
|
|
}
|
|
|
|
export const normalizeRelativeRecordCreatePayload = (payload) => {
|
|
const allowedFields = new Set(['relativeName', 'relationName', 'eventName', 'eventTime', 'giftAmount', 'recordContent', 'mediaOssIds', 'sortOrder', 'status'])
|
|
assertPlainPayload(payload, allowedFields, '亲友往来请求')
|
|
const relativeName = typeof payload.relativeName === 'string' ? payload.relativeName.trim() : ''
|
|
if (!relativeName) throw new TypeError('亲友姓名不能为空')
|
|
const normalizedPayload = { relativeName }
|
|
for (const field of ['relationName', 'eventName', 'eventTime', 'recordContent']) {
|
|
const normalizedText = normalizeOptionalText(payload[field], field)
|
|
if (normalizedText) normalizedPayload[field] = normalizedText
|
|
}
|
|
const status = normalizeOptionalNormalDisableStatus(payload.status, '亲友往来状态')
|
|
if (status) normalizedPayload.status = status
|
|
if (payload.giftAmount !== undefined && payload.giftAmount !== '' && payload.giftAmount !== null) {
|
|
const giftAmount = normalizeOptionalCurrencyNumber(payload.giftAmount, '亲友往来礼金金额')
|
|
normalizedPayload.giftAmount = giftAmount
|
|
}
|
|
const mediaOssIds = normalizeOptionalOssIdList(payload.mediaOssIds)
|
|
if (mediaOssIds) normalizedPayload.mediaOssIds = mediaOssIds
|
|
const sortOrder = normalizeOptionalSafeInteger(payload.sortOrder, 'sortOrder')
|
|
if (sortOrder !== undefined) normalizedPayload.sortOrder = sortOrder
|
|
return normalizedPayload
|
|
}
|
|
|
|
export const normalizeGrowthRecordCreatePayload = (payload) => {
|
|
const allowedFields = new Set(['lineagePersonId', 'recordType', 'recordTitle', 'recordContent', 'recordDate', 'remindTime', 'mediaOssIds', 'sortOrder', 'status'])
|
|
assertPlainPayload(payload, allowedFields, '成长记录请求')
|
|
const recordTitle = typeof payload.recordTitle === 'string' ? payload.recordTitle.trim() : ''
|
|
if (!recordTitle) throw new TypeError('成长记录标题不能为空')
|
|
const normalizedPayload = { recordTitle }
|
|
for (const field of ['recordType', 'recordContent', 'recordDate', 'remindTime']) {
|
|
const normalizedText = normalizeOptionalText(payload[field], field)
|
|
if (normalizedText) normalizedPayload[field] = normalizedText
|
|
}
|
|
const status = normalizeOptionalNormalDisableStatus(payload.status, '成长记录状态')
|
|
if (status) normalizedPayload.status = status
|
|
if (payload.lineagePersonId !== undefined && payload.lineagePersonId !== null && payload.lineagePersonId !== '') {
|
|
normalizedPayload.lineagePersonId = normalizeResourcePathId(payload.lineagePersonId, '关联人物标识')
|
|
}
|
|
const mediaOssIds = normalizeOptionalOssIdList(payload.mediaOssIds)
|
|
if (mediaOssIds || payload.mediaOssIds === '') normalizedPayload.mediaOssIds = mediaOssIds || ''
|
|
const sortOrder = normalizeOptionalSafeInteger(payload.sortOrder, 'sortOrder')
|
|
if (sortOrder !== undefined) normalizedPayload.sortOrder = sortOrder
|
|
return normalizedPayload
|
|
}
|
|
|
|
export const normalizeLifeEventPayload = (payload) => {
|
|
const allowedFields = new Set(['eventType', 'eventTitle', 'eventContent', 'eventDate', 'datePrecision', 'eventPlace', 'sourceDescription', 'mediaOssIds'])
|
|
assertPlainPayload(payload, allowedFields, '人生大事请求')
|
|
const eventType = normalizeOptionalText(payload.eventType, 'eventType')
|
|
const eventTitle = normalizeOptionalText(payload.eventTitle, 'eventTitle')
|
|
const datePrecision = normalizeOptionalText(payload.datePrecision, 'datePrecision')
|
|
if (!lifeEventTypes.has(eventType) || !eventTitle || !lifeEventDatePrecisions.has(datePrecision)) {
|
|
throw new TypeError('请完整填写人生大事的类型、标题和日期精度')
|
|
}
|
|
const eventDate = normalizeLifeEventDate(payload.eventDate, 'eventDate', 'LIFE_EVENT_REQUEST_INVALID')
|
|
const normalizedPayload = { eventType, eventTitle, eventDate, datePrecision }
|
|
for (const field of ['eventContent', 'eventPlace', 'sourceDescription']) {
|
|
const normalizedText = normalizeOptionalText(payload[field], field)
|
|
if (normalizedText) normalizedPayload[field] = normalizedText
|
|
}
|
|
if (payload.mediaOssIds !== undefined && payload.mediaOssIds !== null) {
|
|
if (!Array.isArray(payload.mediaOssIds)) throw new TypeError('mediaOssIds 必须是文件标识数组')
|
|
const mediaOssIds = payload.mediaOssIds.map((item) => normalizeOssIdString(item, 'mediaOssIds'))
|
|
if (new Set(mediaOssIds).size !== mediaOssIds.length) throw new TypeError('mediaOssIds 不能重复')
|
|
if (mediaOssIds.length) normalizedPayload.mediaOssIds = mediaOssIds
|
|
}
|
|
return normalizedPayload
|
|
}
|
|
|
|
export const normalizeMemoCreatePayload = (payload) => {
|
|
const allowedFields = new Set(['memoType', 'memoTitle', 'memoContent', 'remindTime', 'completed', 'mediaOssIds', 'sortOrder', 'status'])
|
|
assertPlainPayload(payload, allowedFields, '备忘请求')
|
|
const memoTitle = typeof payload.memoTitle === 'string' ? payload.memoTitle.trim() : ''
|
|
if (!memoTitle) throw new TypeError('备忘标题不能为空')
|
|
const memoType = normalizeOptionalText(payload.memoType, 'memoType') || MEMO_TYPE.GENERAL
|
|
if (!memoTypes.has(memoType)) throw new TypeError('备忘类型无效')
|
|
const normalizedPayload = { memoType, memoTitle }
|
|
for (const field of ['memoContent', 'remindTime', 'completed']) {
|
|
const normalizedText = normalizeOptionalText(payload[field], field)
|
|
if (normalizedText) normalizedPayload[field] = normalizedText
|
|
}
|
|
const status = normalizeOptionalNormalDisableStatus(payload.status, '备忘状态')
|
|
if (status) normalizedPayload.status = status
|
|
const mediaOssIds = normalizeOptionalOssIdList(payload.mediaOssIds)
|
|
if (mediaOssIds) normalizedPayload.mediaOssIds = mediaOssIds
|
|
const sortOrder = normalizeOptionalSafeInteger(payload.sortOrder, 'sortOrder')
|
|
if (sortOrder !== undefined) normalizedPayload.sortOrder = sortOrder
|
|
return normalizedPayload
|
|
}
|
|
|
|
export const normalizeMeritRecordCreatePayload = (payload) => {
|
|
const allowedFields = new Set(['donorName', 'meritTitle', 'meritType', 'meritContent', 'amount', 'meritTime', 'mediaOssIds', 'sortOrder', 'status'])
|
|
assertPlainPayload(payload, allowedFields, '功德记录请求')
|
|
const donorName = typeof payload.donorName === 'string' ? payload.donorName.trim() : ''
|
|
const meritTitle = typeof payload.meritTitle === 'string' ? payload.meritTitle.trim() : ''
|
|
if (!donorName || !meritTitle) throw new TypeError('功德记录捐赠人和标题不能为空')
|
|
const normalizedPayload = { donorName, meritTitle }
|
|
for (const field of ['meritType', 'meritContent', 'meritTime']) {
|
|
const normalizedText = normalizeOptionalText(payload[field], field)
|
|
if (normalizedText) normalizedPayload[field] = normalizedText
|
|
}
|
|
const status = normalizeOptionalNormalDisableStatus(payload.status, '功德记录状态')
|
|
if (status) normalizedPayload.status = status
|
|
if (payload.amount !== undefined && payload.amount !== '' && payload.amount !== null) {
|
|
const amount = normalizeOptionalCurrencyNumber(payload.amount, '功德金额')
|
|
normalizedPayload.amount = amount
|
|
}
|
|
const mediaOssIds = normalizeOptionalOssIdList(payload.mediaOssIds)
|
|
if (mediaOssIds || payload.mediaOssIds === '') normalizedPayload.mediaOssIds = mediaOssIds || ''
|
|
const sortOrder = normalizeOptionalSafeInteger(payload.sortOrder, 'sortOrder')
|
|
if (sortOrder !== undefined) normalizedPayload.sortOrder = sortOrder
|
|
return normalizedPayload
|
|
}
|