26 lines
727 B
TypeScript
26 lines
727 B
TypeScript
import { isRecord } from './guards'
|
|
import type { DriveAction } from './types'
|
|
|
|
interface StagingRequestBody {
|
|
stagingId: string
|
|
}
|
|
|
|
interface DriveRequestBody extends StagingRequestBody {
|
|
action: DriveAction
|
|
}
|
|
|
|
export function parseStagingRequestBody(value: unknown): StagingRequestBody {
|
|
if (!isRecord(value) || typeof value.stagingId !== 'string' || value.stagingId.trim() === '') {
|
|
throw new Error('stagingId manquant')
|
|
}
|
|
|
|
return { stagingId: value.stagingId }
|
|
}
|
|
|
|
export function parseDriveRequestBody(value: unknown): DriveRequestBody {
|
|
const { stagingId } = parseStagingRequestBody(value)
|
|
const action = isRecord(value) && value.action === 'replace' ? 'replace' : 'new'
|
|
|
|
return { stagingId, action }
|
|
}
|