Skip to content

Commit

Permalink
Merge pull request #465 from debagger/debagger-fix
Browse files Browse the repository at this point in the history
Fix(crud): Do not return pageCount on getMany in some cases
  • Loading branch information
michaelyali committed Apr 12, 2020
2 parents 2783803 + 2421b79 commit 4bc9673
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
8 changes: 2 additions & 6 deletions packages/crud/src/services/crud-service.abstract.ts
Expand Up @@ -52,12 +52,8 @@ export abstract class CrudService<T> {
data,
count: data.length,
total,
page: Math.floor(offset / limit) + 1,
pageCount:
limit && total
? Math.ceil(total / limit)
: /* istanbul ignore next line */
undefined,
page: limit ? Math.floor(offset / limit) + 1 : 1,
pageCount: limit && total ? Math.ceil(total / limit) : 1,
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/crud/src/types/query-filter-option.type.ts
@@ -1,7 +1,7 @@
import {
QueryFilter,
SCondition,
} from '@nestjsx/crud-request/lib/types/request-query.types';
} from '@nestjsx/crud-request/src/types/request-query.types';

export type QueryFilterFunction = (
search?: SCondition,
Expand Down
2 changes: 1 addition & 1 deletion packages/crud/test/__fixture__/services/test.service.ts
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { ParsedRequestParams } from '@nestjsx/crud-request';
import { CrudRequestOptions } from '../../../lib/interfaces';
import { CrudRequestOptions } from '../../../src/interfaces';

import { CreateManyDto, CrudRequest } from '../../../src/interfaces';
import { CrudService } from '../../../src/services';
Expand Down
13 changes: 13 additions & 0 deletions packages/crud/test/crud-service.abstract.spec.ts
Expand Up @@ -37,6 +37,19 @@ describe('#crud', () => {
};
expect(service.createPageInfo([], 100, 10, 10)).toMatchObject(expected);
});

it('should return an object when limit and offset undefined', () => {
const expected = {
count: 0,
data: [],
page: 1,
pageCount: 1,
total: 100,
};
expect(service.createPageInfo([], 100, undefined, undefined)).toMatchObject(
expected,
);
});
});
});
});

0 comments on commit 4bc9673

Please sign in to comment.