Skip to content

Commit b40a579

Browse files
committed
feat(core): default option key
1 parent 08d4925 commit b40a579

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

libs/core/src/crud/paging/resource.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class CrudPagingResource<TSchema extends CrudSchemataTypes = any> {
6767
filter: 'filter',
6868
paging: 'paging',
6969
sorting: 'sorting',
70-
totalCount: 'total',
70+
totalCount: 'totalCount',
7171
};
7272

7373
public custom: NonNullable<CrudPagingOptions<TSchema>['custom']>;
@@ -109,16 +109,18 @@ export class CrudPagingResource<TSchema extends CrudSchemataTypes = any> {
109109
this.custom = options.custom ?? fallbackCustomPagingOptions;
110110

111111
this.keys = {
112-
totalCount: keys?.totalCount ?? 'total',
112+
totalCount:
113+
keys?.totalCount ??
114+
CrudPagingResource.getDefaultOptionsKey(this.strategy, 'totalCount'),
113115
filter:
114116
keys?.filter ??
115-
CrudPagingResource.getOptionsKey(this.strategy, 'filter'),
117+
CrudPagingResource.getDefaultOptionsKey(this.strategy, 'filter'),
116118
paging:
117119
keys?.paging ??
118-
CrudPagingResource.getOptionsKey(this.strategy, 'paging'),
120+
CrudPagingResource.getDefaultOptionsKey(this.strategy, 'paging'),
119121
sorting:
120122
keys?.sorting ??
121-
CrudPagingResource.getOptionsKey(this.strategy, 'sorting'),
123+
CrudPagingResource.getDefaultOptionsKey(this.strategy, 'sorting'),
122124
};
123125

124126
// initialize paging paginate resource
@@ -129,21 +131,27 @@ export class CrudPagingResource<TSchema extends CrudSchemataTypes = any> {
129131
}
130132

131133
// =============== STATIC
132-
static getOptionsKey = (
134+
static getDefaultOptionsKey = (
133135
strategy: CrudPagingStrategy = 'OFFSET',
134136
type: CrudPagingKeyType
135137
): string | null => {
136138
if (strategy === 'CURSOR') {
137139
if (type === 'paging') return 'paging';
138-
return type === 'sorting' ? 'sorting' : 'filter';
140+
if (type === 'sorting') return 'sorting';
141+
if (type === 'totalCount') return 'totalCount';
142+
return 'filter';
139143
}
140144
if (strategy === 'OFFSET') {
141145
if (type === 'paging') return 'paging';
142-
return type === 'sorting' ? 'sorting' : 'filter';
146+
if (type === 'sorting') return 'sorting';
147+
if (type === 'totalCount') return 'totalCount';
148+
return 'filter';
143149
}
144150
if (strategy === 'NONE') {
145151
if (type === 'paging') return null;
146-
return type === 'sorting' ? 'sorting' : 'filter';
152+
if (type === 'totalCount') return 'total';
153+
if (type === 'sorting') return 'sorting';
154+
return 'filter';
147155
}
148156
// if custom strategy always return null;
149157
return null;
@@ -187,6 +195,10 @@ export class CrudPagingResource<TSchema extends CrudSchemataTypes = any> {
187195
return this.keys.paging ?? 'paging';
188196
}
189197

198+
get keyTotalCount(): string {
199+
return this.keys.totalCount ?? 'totalCount';
200+
}
201+
190202
// =============== SETTER
191203
private setPagingInfo(info: CrudPagingPageInfo) {
192204
this.pageSize = info?.pageSize ?? this.defaultPageSize;

0 commit comments

Comments
 (0)