Files
twenty/packages/twenty-server/src/api/rest/api-rest-query-builder/utils/compute-depth.utils.ts
T
Jérémy M 94487f6737 feat: refactor folder structure (#4498)
* feat: wip refactor folder structure

* Fix

* fix position

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
2024-03-15 14:40:58 +01:00

26 lines
572 B
TypeScript

import { BadRequestException } from '@nestjs/common';
import { Request } from 'express';
const ALLOWED_DEPTH_VALUES = [1, 2];
export const computeDepth = (request: Request): number | undefined => {
if (!request.query.depth) {
return undefined;
}
const depth = +request.query.depth;
if (isNaN(depth) || !ALLOWED_DEPTH_VALUES.includes(depth)) {
throw new BadRequestException(
`'depth=${
request.query.depth
}' parameter invalid. Allowed values are ${ALLOWED_DEPTH_VALUES.join(
', ',
)}`,
);
}
return depth;
};