feat: migrate app routes and business modules
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
import { listPreviewCeremonies } from '@/data/preview/records.js'
|
||||
import { hasRemoteConfig } from '@/utils/runtime-config.js'
|
||||
import {
|
||||
normalizeAppCeremonies,
|
||||
normalizeAppCeremony,
|
||||
normalizeAppCeremonyGift,
|
||||
normalizeAppCeremonyGifts,
|
||||
normalizeAppCeremonyWithTypeLabel,
|
||||
normalizeCeremonyGiftPayload,
|
||||
normalizeCeremonyInvitationResponsePayload,
|
||||
normalizeCeremonyInvitationRows,
|
||||
normalizeCeremonyInviteeOptions,
|
||||
normalizeCeremonyInviteePayload,
|
||||
normalizeCeremonyPayload,
|
||||
projectPreviewCeremonies
|
||||
} from './ceremony-contract.js'
|
||||
import { normalizeGenealogyPathId } from './genealogy-contract.js'
|
||||
import { normalizeResourcePathId } from './request-normalizers.js'
|
||||
import { createRequestError, requestStrict } from './request-client.js'
|
||||
|
||||
const requireRemoteCeremony = (message, code) => {
|
||||
if (hasRemoteConfig()) return
|
||||
throw createRequestError(message, code)
|
||||
}
|
||||
|
||||
export const ceremonyApi = {
|
||||
async createCeremony(genealogyId, payload, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
requireRemoteCeremony('创建礼仪活动需要真实服务,当前本地预览不会伪造保存成功', 'REMOTE_WRITE_REQUIRED')
|
||||
return requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/ceremonies`,
|
||||
method: 'POST',
|
||||
data: normalizeCeremonyPayload(payload)
|
||||
}, { requestController: requestOptions.requestController ?? null })
|
||||
},
|
||||
|
||||
async updateCeremony(genealogyId, ceremonyId, payload, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedCeremonyId = normalizeResourcePathId(ceremonyId, '礼仪活动标识')
|
||||
requireRemoteCeremony('修改礼仪活动需要真实服务,当前本地预览不会伪造保存成功', 'REMOTE_WRITE_REQUIRED')
|
||||
return requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/ceremonies/${normalizedCeremonyId}`,
|
||||
method: 'PUT',
|
||||
data: normalizeCeremonyPayload(payload)
|
||||
}, { requestController: requestOptions.requestController ?? null })
|
||||
},
|
||||
|
||||
async deleteCeremony(genealogyId, ceremonyId, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedCeremonyId = normalizeResourcePathId(ceremonyId, '礼仪活动标识')
|
||||
requireRemoteCeremony('删除礼仪活动需要真实服务,当前本地预览不会伪造删除成功', 'REMOTE_WRITE_REQUIRED')
|
||||
await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/ceremonies/${normalizedCeremonyId}`,
|
||||
method: 'DELETE'
|
||||
}, { requireData: false, requestController: requestOptions.requestController ?? null })
|
||||
return null
|
||||
},
|
||||
|
||||
async createCeremonyGift(genealogyId, ceremonyId, payload, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedCeremonyId = normalizeResourcePathId(ceremonyId, '礼仪活动标识')
|
||||
requireRemoteCeremony('新增礼仪献礼需要真实服务,当前本地预览不会伪造保存成功', 'REMOTE_WRITE_REQUIRED')
|
||||
const gift = await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/ceremonies/${normalizedCeremonyId}/gifts`,
|
||||
method: 'POST',
|
||||
data: normalizeCeremonyGiftPayload(payload)
|
||||
}, { requestController: requestOptions.requestController ?? null })
|
||||
return normalizeAppCeremonyGift(gift, normalizedGenealogyId, normalizedCeremonyId)
|
||||
},
|
||||
|
||||
async deleteCeremonyGift(genealogyId, ceremonyId, giftId, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedCeremonyId = normalizeResourcePathId(ceremonyId, '礼仪活动标识')
|
||||
const normalizedGiftId = normalizeResourcePathId(giftId, '献礼标识')
|
||||
requireRemoteCeremony('删除礼仪献礼需要真实服务,当前本地预览不会伪造删除成功', 'REMOTE_WRITE_REQUIRED')
|
||||
await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/ceremonies/${normalizedCeremonyId}/gifts/${normalizedGiftId}`,
|
||||
method: 'DELETE'
|
||||
}, { requireData: false, requestController: requestOptions.requestController ?? null })
|
||||
return null
|
||||
},
|
||||
|
||||
async getCeremonies(genealogyId, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
if (!hasRemoteConfig()) {
|
||||
return projectPreviewCeremonies(listPreviewCeremonies(normalizedGenealogyId), normalizedGenealogyId)
|
||||
}
|
||||
const ceremonies = await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/ceremonies`,
|
||||
method: 'GET'
|
||||
}, { requestController: requestOptions.requestController ?? null })
|
||||
return normalizeAppCeremonies(ceremonies, normalizedGenealogyId)
|
||||
},
|
||||
|
||||
async replaceCeremonyInvitees(genealogyId, ceremonyId, payload, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedCeremonyId = normalizeResourcePathId(ceremonyId, '礼仪活动标识')
|
||||
const invitees = normalizeCeremonyInviteePayload(payload)
|
||||
requireRemoteCeremony('活动受邀人写入需要真实服务,当前本地预览不会伪造结果', 'REMOTE_WRITE_REQUIRED')
|
||||
const invitations = await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/ceremonies/${normalizedCeremonyId}/invitees`,
|
||||
method: 'PUT',
|
||||
data: invitees
|
||||
}, { requestController: requestOptions.requestController ?? null })
|
||||
return normalizeCeremonyInvitationRows(invitations, normalizedGenealogyId)
|
||||
},
|
||||
|
||||
async getCeremonyInviteeOptions(genealogyId, ceremonyId, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedCeremonyId = normalizeResourcePathId(ceremonyId, '礼仪活动标识')
|
||||
requireRemoteCeremony('活动受邀候选读取需要真实服务,当前本地预览不会伪造结果', 'REMOTE_READ_REQUIRED')
|
||||
const options = await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/ceremonies/${normalizedCeremonyId}/invitee-options`,
|
||||
method: 'GET'
|
||||
}, { requestController: requestOptions.requestController ?? null })
|
||||
return normalizeCeremonyInviteeOptions(options)
|
||||
},
|
||||
|
||||
async getCeremonyInvitations(genealogyId, ceremonyId, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedCeremonyId = normalizeResourcePathId(ceremonyId, '礼仪活动标识')
|
||||
requireRemoteCeremony('活动邀请名单读取需要真实服务,当前本地预览不会伪造结果', 'REMOTE_READ_REQUIRED')
|
||||
const invitations = await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/ceremonies/${normalizedCeremonyId}/invitations`,
|
||||
method: 'GET'
|
||||
}, { requestController: requestOptions.requestController ?? null })
|
||||
return normalizeCeremonyInvitationRows(invitations, normalizedGenealogyId)
|
||||
},
|
||||
|
||||
async respondToCeremonyInvitation(genealogyId, ceremonyId, payload, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedCeremonyId = normalizeResourcePathId(ceremonyId, '礼仪活动标识')
|
||||
const response = normalizeCeremonyInvitationResponsePayload(payload)
|
||||
requireRemoteCeremony('活动邀请响应写入需要真实服务,当前本地预览不会伪造结果', 'REMOTE_WRITE_REQUIRED')
|
||||
return requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/ceremonies/${normalizedCeremonyId}/invitations/me`,
|
||||
method: 'PUT',
|
||||
data: response
|
||||
}, { requestController: requestOptions.requestController ?? null })
|
||||
},
|
||||
|
||||
async getMyCeremonyInvitations(requestOptions = {}) {
|
||||
requireRemoteCeremony('我的活动邀请读取需要真实服务,当前本地预览不会伪造结果', 'REMOTE_READ_REQUIRED')
|
||||
const invitations = await requestStrict({
|
||||
url: '/genealogy/app/genealogies/ceremony-invitations/mine',
|
||||
method: 'GET'
|
||||
}, { requestController: requestOptions.requestController ?? null })
|
||||
return normalizeCeremonyInvitationRows(invitations)
|
||||
},
|
||||
|
||||
async getCeremonyDetail(genealogyId, ceremonyId, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedCeremonyId = normalizeResourcePathId(ceremonyId, '礼仪活动标识')
|
||||
requireRemoteCeremony('礼仪详情需要真实读取服务,当前本地预览不会伪造详情', 'REMOTE_READ_REQUIRED')
|
||||
const ceremony = await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/ceremonies/${normalizedCeremonyId}`,
|
||||
method: 'GET'
|
||||
}, { requestController: requestOptions.requestController ?? null })
|
||||
return normalizeAppCeremonyWithTypeLabel(
|
||||
normalizeAppCeremony(ceremony, normalizedGenealogyId, normalizedCeremonyId)
|
||||
)
|
||||
},
|
||||
|
||||
async getCeremonyGifts(genealogyId, ceremonyId, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedCeremonyId = normalizeResourcePathId(ceremonyId, '礼仪活动标识')
|
||||
requireRemoteCeremony('礼仪献礼需要真实读取服务,当前本地预览不会伪造列表', 'REMOTE_READ_REQUIRED')
|
||||
const gifts = await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/ceremonies/${normalizedCeremonyId}/gifts`,
|
||||
method: 'GET'
|
||||
}, { requestController: requestOptions.requestController ?? null })
|
||||
return normalizeAppCeremonyGifts(gifts, normalizedGenealogyId, normalizedCeremonyId)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user