14 lines
373 B
TypeScript
14 lines
373 B
TypeScript
import { BadRequestException } from '@nestjs/common';
|
|
|
|
export function parseBigIntParam(value: unknown, label = 'ID'): bigint {
|
|
const text = String(value ?? '').trim();
|
|
if (!/^\d+$/.test(text)) {
|
|
throw new BadRequestException(`${label}格式无效`);
|
|
}
|
|
try {
|
|
return BigInt(text);
|
|
} catch {
|
|
throw new BadRequestException(`${label}格式无效`);
|
|
}
|
|
}
|