You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.6 KiB
39 lines
1.6 KiB
|
1 month ago
|
import { adminHttp } from './http'
|
||
|
|
import type { FormSchemaPayload, FormSchemaRow } from './types'
|
||
|
|
|
||
|
|
export async function listFormSchemas(competitionId: number, purpose?: 'signup' | 'review'): Promise<FormSchemaRow[]> {
|
||
|
|
const { data } = await adminHttp.get<unknown>(`/competitions/${competitionId}/form-schemas`, {
|
||
|
|
params: purpose ? { purpose } : {},
|
||
|
|
})
|
||
|
|
const body = data as { data?: FormSchemaRow[] }
|
||
|
|
return body.data ?? []
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function getFormSchema(competitionId: number, schemaId: number): Promise<FormSchemaRow> {
|
||
|
|
const { data } = await adminHttp.get<unknown>(`/competitions/${competitionId}/form-schemas/${schemaId}`)
|
||
|
|
const body = (data as { data?: FormSchemaRow })?.data ?? (data as FormSchemaRow)
|
||
|
|
if (!body || typeof body !== 'object' || !('id' in body)) throw new Error('表单详情无效')
|
||
|
|
return body as FormSchemaRow
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function createFormSchema(competitionId: number, payload: FormSchemaPayload): Promise<FormSchemaRow> {
|
||
|
|
const { data } = await adminHttp.post<FormSchemaRow>(`/competitions/${competitionId}/form-schemas`, payload)
|
||
|
|
return data
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function updateFormSchema(
|
||
|
|
competitionId: number,
|
||
|
|
schemaId: number,
|
||
|
|
payload: Partial<{ name: string; schema_json: unknown[]; is_published: boolean }>,
|
||
|
|
): Promise<FormSchemaRow> {
|
||
|
|
const { data } = await adminHttp.patch<FormSchemaRow>(
|
||
|
|
`/competitions/${competitionId}/form-schemas/${schemaId}`,
|
||
|
|
payload,
|
||
|
|
)
|
||
|
|
return data
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function deleteFormSchema(competitionId: number, schemaId: number): Promise<void> {
|
||
|
|
await adminHttp.delete(`/competitions/${competitionId}/form-schemas/${schemaId}`)
|
||
|
|
}
|