fix: 删除类型
This commit is contained in:
+31
-2
@@ -134,6 +134,28 @@ function getBannerUrlFromResponse(data: unknown): string {
|
||||
return ''
|
||||
}
|
||||
|
||||
function getInstitutionIdFromResponse(data: unknown): number {
|
||||
if (!data || typeof data !== 'object') {
|
||||
return 0
|
||||
}
|
||||
|
||||
const record = data as Record<string, unknown>
|
||||
const id = record.id || record.institution_id || record.institutionId
|
||||
if (typeof id === 'number' && Number.isFinite(id)) {
|
||||
return id
|
||||
}
|
||||
if (typeof id === 'string' && Number.isFinite(Number(id))) {
|
||||
return Number(id)
|
||||
}
|
||||
|
||||
const nested = record.data || record.result || record.payload || record.institution
|
||||
if (nested && typeof nested === 'object') {
|
||||
return getInstitutionIdFromResponse(nested)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function normalizeInstitution(item: unknown): InstitutionListItem {
|
||||
const record = item && typeof item === 'object' ? (item as Record<string, unknown>) : {}
|
||||
const id = record.id
|
||||
@@ -283,7 +305,7 @@ export async function fetchInstitutions(params: InstitutionListParams): Promise<
|
||||
}
|
||||
}
|
||||
|
||||
export async function createInstitution(params: InstitutionMutationParams): Promise<unknown> {
|
||||
export async function createInstitution(params: InstitutionMutationParams): Promise<InstitutionListItem> {
|
||||
const response = await fetch('/server/api/cms/institutions/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -294,7 +316,14 @@ export async function createInstitution(params: InstitutionMutationParams): Prom
|
||||
body: JSON.stringify(params.payload)
|
||||
})
|
||||
|
||||
return parseMutationResponse(response, '新增机构失败')
|
||||
const data = await parseMutationResponse(response, '新增机构失败')
|
||||
const normalized = normalizeInstitution(data)
|
||||
const id = normalized.id || getInstitutionIdFromResponse(data)
|
||||
|
||||
return {
|
||||
...normalized,
|
||||
id
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateInstitution(params: UpdateInstitutionParams): Promise<unknown> {
|
||||
|
||||
Reference in New Issue
Block a user