Files
jiapuapp/services/api/generation-poem-service.js
T

77 lines
3.0 KiB
JavaScript

import { hasRemoteConfig } from '@/utils/runtime-config.js'
import {
normalizeGenerationPoemBatchPayload,
normalizeGenerationPoemPreview,
normalizeGenerationPoemRows
} from './generation-poem-contract.js'
import { normalizeGenealogyPathId } from './genealogy-contract.js'
import { createRequestError, requestStrict } from './request-client.js'
const requireRemoteGenerationPoem = (message, code) => {
if (hasRemoteConfig()) return
throw createRequestError(message, code)
}
export const generationPoemApi = {
async getGenerationPoems(genealogyId, requestOptions = {}) {
requireRemoteGenerationPoem(
'字辈列表需要真实读取服务,当前本地预览不会伪造字辈数据',
'REMOTE_READ_REQUIRED'
)
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
const generationPoems = await requestStrict({
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/generation-poems`,
method: 'GET'
}, {
requestController: requestOptions.requestController ?? null
})
return normalizeGenerationPoemRows(generationPoems, normalizedGenealogyId)
},
async getGenerationPoemManagement(genealogyId, requestOptions = {}) {
requireRemoteGenerationPoem(
'字辈维护列表需要真实读取服务,当前本地预览不会伪造管理权限',
'REMOTE_READ_REQUIRED'
)
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
const generationPoems = await requestStrict({
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/generation-poems/management`,
method: 'GET'
}, {
requestController: requestOptions.requestController ?? null
})
return normalizeGenerationPoemRows(generationPoems, normalizedGenealogyId)
},
async previewGenerationPoemBatch(genealogyId, payload, requestOptions = {}) {
requireRemoteGenerationPoem(
'字辈批量预览需要真实服务,当前本地预览不会伪造差异结果',
'REMOTE_READ_REQUIRED'
)
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
const preview = await requestStrict({
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/generation-poems/batch/preview`,
method: 'POST',
data: normalizeGenerationPoemBatchPayload(payload)
}, {
requestController: requestOptions.requestController ?? null
})
return normalizeGenerationPoemPreview(preview, normalizedGenealogyId)
},
async saveGenerationPoemBatch(genealogyId, payload, requestOptions = {}) {
requireRemoteGenerationPoem(
'字辈批量保存需要真实服务,当前本地预览不会伪造保存成功',
'REMOTE_WRITE_REQUIRED'
)
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
return requestStrict({
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/generation-poems/batch/save`,
method: 'POST',
data: normalizeGenerationPoemBatchPayload(payload)
}, {
requestController: requestOptions.requestController ?? null
})
}
}