Skip to content

Commit e0a6d93

Browse files
committed
feat: support groupby
Signed-off-by: Muhammad Aaqil <[email protected]>
1 parent d76f00c commit e0a6d93

File tree

7 files changed

+293
-7
lines changed

7 files changed

+293
-7
lines changed

packages/filter/src/query.ts

+24
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,30 @@ export interface Filter<MT extends object = AnyObject> {
230230
* To include related objects
231231
*/
232232
include?: InclusionFilter[];
233+
/**
234+
* return groupBy of
235+
*/
236+
groupBy?: string[];
237+
/**
238+
* return sum of
239+
*/
240+
sum?: string;
241+
/**
242+
* return min of
243+
*/
244+
min?: string;
245+
/**
246+
* return max of
247+
*/
248+
max?: string;
249+
/**
250+
* return avg of
251+
*/
252+
avg?: string;
253+
/**
254+
* return count of
255+
*/
256+
count?: string;
233257
}
234258

235259
/**

packages/openapi-v3/src/__tests__/unit/decorators/query.decorator.unit.ts

+81-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ describe('sugar decorators for filter and where', () => {
3434
title: 'MyModel.Filter',
3535
'x-typescript-type': '@loopback/repository#Filter<MyModel>',
3636
properties: {
37+
avg: {
38+
example: 'column1',
39+
type: 'string',
40+
},
41+
count: {
42+
example: 'column1',
43+
type: 'string',
44+
},
3745
fields: {
3846
oneOf: [
3947
{
@@ -55,11 +63,29 @@ describe('sugar decorators for filter and where', () => {
5563
},
5664
},
5765
],
58-
title: 'MyModel.Fields',
66+
title: 'MyModel.GroupBy',
5967
},
6068
offset: {type: 'integer', minimum: 0},
69+
groupBy: {
70+
items: {
71+
type: 'string',
72+
},
73+
type: 'array',
74+
},
6175
limit: {type: 'integer', minimum: 1, example: 100},
76+
max: {
77+
example: 'column1',
78+
type: 'string',
79+
},
80+
min: {
81+
example: 'column1',
82+
type: 'string',
83+
},
6284
skip: {type: 'integer', minimum: 0},
85+
sum: {
86+
example: 'column1',
87+
type: 'string',
88+
},
6389
order: {
6490
oneOf: [
6591
{type: 'string'},
@@ -92,6 +118,14 @@ describe('sugar decorators for filter and where', () => {
92118
title: 'MyModel.Filter',
93119
'x-typescript-type': '@loopback/repository#Filter<MyModel>',
94120
properties: {
121+
avg: {
122+
example: 'column1',
123+
type: 'string',
124+
},
125+
count: {
126+
example: 'column1',
127+
type: 'string',
128+
},
95129
fields: {
96130
oneOf: [
97131
{
@@ -113,11 +147,29 @@ describe('sugar decorators for filter and where', () => {
113147
},
114148
},
115149
],
116-
title: 'MyModel.Fields',
150+
title: 'MyModel.GroupBy',
117151
},
118152
offset: {type: 'integer', minimum: 0},
119153
limit: {type: 'integer', minimum: 1, example: 100},
154+
groupBy: {
155+
items: {
156+
type: 'string',
157+
},
158+
type: 'array',
159+
},
120160
skip: {type: 'integer', minimum: 0},
161+
max: {
162+
example: 'column1',
163+
type: 'string',
164+
},
165+
min: {
166+
example: 'column1',
167+
type: 'string',
168+
},
169+
sum: {
170+
example: 'column1',
171+
type: 'string',
172+
},
121173
order: {
122174
oneOf: [
123175
{type: 'string'},
@@ -157,6 +209,14 @@ describe('sugar decorators for filter and where', () => {
157209
title: 'MyModel.Filter',
158210
'x-typescript-type': '@loopback/repository#Filter<MyModel>',
159211
properties: {
212+
avg: {
213+
example: 'column1',
214+
type: 'string',
215+
},
216+
count: {
217+
example: 'column1',
218+
type: 'string',
219+
},
160220
fields: {
161221
oneOf: [
162222
{
@@ -178,11 +238,29 @@ describe('sugar decorators for filter and where', () => {
178238
},
179239
},
180240
],
181-
title: 'MyModel.Fields',
241+
title: 'MyModel.GroupBy',
182242
},
183243
offset: {type: 'integer', minimum: 0},
184244
limit: {type: 'integer', minimum: 1, example: 100},
245+
groupBy: {
246+
items: {
247+
type: 'string',
248+
},
249+
type: 'array',
250+
},
185251
skip: {type: 'integer', minimum: 0},
252+
max: {
253+
example: 'column1',
254+
type: 'string',
255+
},
256+
min: {
257+
example: 'column1',
258+
type: 'string',
259+
},
260+
sum: {
261+
example: 'column1',
262+
type: 'string',
263+
},
186264
order: {
187265
oneOf: [
188266
{type: 'string'},

packages/openapi-v3/src/__tests__/unit/filter-schema.unit.ts

+81-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ describe('filterSchema', () => {
2525
type: 'object',
2626
'x-typescript-type': '@loopback/repository#Filter<MyUserModel>',
2727
properties: {
28+
avg: {
29+
example: 'column1',
30+
type: 'string',
31+
},
32+
count: {
33+
example: 'column1',
34+
type: 'string',
35+
},
2836
where: {
2937
type: 'object',
3038
title: 'my-user-model.WhereFilter',
@@ -54,11 +62,29 @@ describe('filterSchema', () => {
5462
},
5563
},
5664
],
57-
title: 'my-user-model.Fields',
65+
title: 'my-user-model.GroupBy',
5866
},
5967
offset: {type: 'integer', minimum: 0},
6068
limit: {type: 'integer', minimum: 1, example: 100},
69+
max: {
70+
example: 'column1',
71+
type: 'string',
72+
},
73+
min: {
74+
example: 'column1',
75+
type: 'string',
76+
},
77+
groupBy: {
78+
items: {
79+
type: 'string',
80+
},
81+
type: 'array',
82+
},
6183
skip: {type: 'integer', minimum: 0},
84+
sum: {
85+
example: 'column1',
86+
type: 'string',
87+
},
6288
order: {
6389
oneOf: [{type: 'string'}, {type: 'array', items: {type: 'string'}}],
6490
},
@@ -75,6 +101,14 @@ describe('filterSchema', () => {
75101
type: 'object',
76102
'x-typescript-type': '@loopback/repository#Filter<MyUserModel>',
77103
properties: {
104+
avg: {
105+
example: 'column1',
106+
type: 'string',
107+
},
108+
count: {
109+
example: 'column1',
110+
type: 'string',
111+
},
78112
fields: {
79113
oneOf: [
80114
{
@@ -99,11 +133,29 @@ describe('filterSchema', () => {
99133
},
100134
},
101135
],
102-
title: 'my-user-model.Fields',
136+
title: 'my-user-model.GroupBy',
103137
},
104138
offset: {type: 'integer', minimum: 0},
139+
groupBy: {
140+
items: {
141+
type: 'string',
142+
},
143+
type: 'array',
144+
},
105145
limit: {type: 'integer', minimum: 1, example: 100},
146+
max: {
147+
example: 'column1',
148+
type: 'string',
149+
},
150+
min: {
151+
example: 'column1',
152+
type: 'string',
153+
},
106154
skip: {type: 'integer', minimum: 0},
155+
sum: {
156+
example: 'column1',
157+
type: 'string',
158+
},
107159
order: {
108160
oneOf: [{type: 'string'}, {type: 'array', items: {type: 'string'}}],
109161
},
@@ -129,6 +181,14 @@ describe('filterSchema', () => {
129181
type: 'object',
130182
'x-typescript-type': '@loopback/repository#Filter<CustomUserModel>',
131183
properties: {
184+
avg: {
185+
example: 'column1',
186+
type: 'string',
187+
},
188+
count: {
189+
example: 'column1',
190+
type: 'string',
191+
},
132192
where: {
133193
type: 'object',
134194
title: 'CustomUserModel.WhereFilter',
@@ -158,11 +218,29 @@ describe('filterSchema', () => {
158218
},
159219
},
160220
],
161-
title: 'CustomUserModel.Fields',
221+
title: 'CustomUserModel.GroupBy',
162222
},
163223
offset: {type: 'integer', minimum: 0},
224+
groupBy: {
225+
items: {
226+
type: 'string',
227+
},
228+
type: 'array',
229+
},
164230
limit: {type: 'integer', minimum: 1, example: 100},
231+
max: {
232+
example: 'column1',
233+
type: 'string',
234+
},
235+
min: {
236+
example: 'column1',
237+
type: 'string',
238+
},
165239
skip: {type: 'integer', minimum: 0},
240+
sum: {
241+
example: 'column1',
242+
type: 'string',
243+
},
166244
order: {
167245
oneOf: [{type: 'string'}, {type: 'array', items: {type: 'string'}}],
168246
},

packages/repository-json-schema/src/__tests__/unit/filter-json-schema.unit.ts

+9
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ describe('getFilterJsonSchemaFor', () => {
7272
limit: 10,
7373
order: ['id DESC'],
7474
skip: 0,
75+
sum: 'salary',
76+
min: 'salary',
77+
max: 'salary',
78+
avg: 'salary',
79+
count: 'salary',
80+
groupBy: ['salary'],
7581
};
7682

7783
expectSchemaToAllowFilter(customerFilterSchema, filter);
@@ -560,6 +566,9 @@ class Customer extends Entity {
560566
@property()
561567
name: string;
562568

569+
@property()
570+
salary: number;
571+
563572
@hasMany(() => Order)
564573
orders?: Order[];
565574
}

0 commit comments

Comments
 (0)