Skip to content

Commit 2a16877

Browse files
drop fields if using include merging all fields as include filtering bug fix for fields
1 parent 58d701b commit 2a16877

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@januscaler/tsed-helper",
3-
"version": "2.2.1",
3+
"version": "2.2.2",
44
"type": "module",
55
"publishConfig": {
66
"@januscaler:registry": "https://npm.pkg.github.com"

src/baseCrud.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,15 @@ export class SearchParams {
8989
include?: any;
9090
}
9191

92-
class GetItemsResponse<T> {
93-
@Property()
94-
items: T[];
95-
@Property()
96-
total: number;
97-
}
92+
9893
export function getItems(options: GetItems): Function {
9994
const { path, model, summary } = options;
95+
class GetItemsResponse<T> {
96+
@CollectionOf(model)
97+
items: T[];
98+
@Property()
99+
total: number;
100+
}
100101
return useDecorators(
101102
Post(path ?? '/search'),
102103
Summary(summary ? summary(options) : `Get all ${nameWithoutModel(model)}`),

src/baseService.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,23 @@ export class BaseService<T> implements OnInit, IBaseService {
226226
const properties = {
227227
skip: offset,
228228
take: limit,
229-
include: include,
229+
include: {
230+
...include,
231+
..._.transform(_.remove(fields, 'id'), (result, field) => {
232+
result[field] = true;
233+
}, {})
234+
},
230235
orderBy: orderBy,
231236
where: this.modeToFilter(filters),
232237
select: _.isNil(fields)
233238
? null
234-
: _.transform(
235-
fields,
236-
(result, field) => {
237-
result[field] = true;
238-
},
239-
{}
240-
)
239+
: _.transform(fields, (result, field) => {
240+
result[field] = true;
241+
}, {})
241242
};
243+
if (_.size(properties.include)) {
244+
delete properties.select;
245+
}
242246

243247
const { _count: { id: total } } = await this.injectedRepository.aggregate({
244248
where: this.modeToFilter(filters),

0 commit comments

Comments
 (0)