Skip to content

Commit

Permalink
fix: check empty params
Browse files Browse the repository at this point in the history
  • Loading branch information
jiho-kr committed Aug 29, 2024
1 parent 23e8058 commit 7c096dc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib/interceptor/create-request.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function CreateRequestInterceptor(crudOptions: CrudOptions, factoryOption
const req = context.switchToHttp().getRequest<Request>();
const createOptions = crudOptions.routes?.[method] ?? {};

if (req.params) {
if (Object.keys(req.params ?? {}).length > 0) {
Object.assign(req.body, req.params);
}
const body = await this.validateBody(req.body);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/interceptor/read-many-request.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function ReadManyRequestInterceptor(crudOptions: CrudOptions, factoryOpti
const customReadManyRequestOptions: CustomReadManyRequestOptions = req[CUSTOM_REQUEST_OPTIONS];
const paginationType = (readManyOptions.paginationType ?? CRUD_POLICY[method].default.paginationType) as PaginationType;

if (req.params) {
if (Object.keys(req.params ?? {}).length > 0) {
Object.assign(req.query, req.params);
}

Expand Down
9 changes: 4 additions & 5 deletions src/lib/interceptor/search-request.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ export function SearchRequestInterceptor(crudOptions: CrudOptions, factoryOption
const req: Record<string, any> = context.switchToHttp().getRequest<Request>();
const searchOptions = crudOptions.routes?.[method] ?? {};
const customSearchRequestOptions: CustomSearchRequestOptions = req[CUSTOM_REQUEST_OPTIONS];
const paginationType = (searchOptions.paginationType ?? CRUD_POLICY[method].default.paginationType) as PaginationType;
const pagination = PaginationHelper.getPaginationRequest(paginationType, req.body);
const isNextPage = PaginationHelper.isNextPage(pagination);

if (req.params) {
if (Object.keys(req.params ?? {}).length > 0 && !isNextPage) {
const paramsCondition = Object.entries(req.params).reduce(
(queryFilter, [key, operand]) => ({ ...queryFilter, [key]: { operator: '=', operand } }),
{},
Expand All @@ -51,10 +54,6 @@ export function SearchRequestInterceptor(crudOptions: CrudOptions, factoryOption
}
}

const paginationType = (searchOptions.paginationType ?? CRUD_POLICY[method].default.paginationType) as PaginationType;
const pagination = PaginationHelper.getPaginationRequest(paginationType, req.body);
const isNextPage = PaginationHelper.isNextPage(pagination);

const requestSearchDto = await (async () => {
if (isNextPage) {
const isQueryValid = pagination.setQuery(pagination.query);
Expand Down

0 comments on commit 7c096dc

Please sign in to comment.