@things-factory/dataset 6.0.92 → 6.0.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/dataset",
3
- "version": "6.0.92",
3
+ "version": "6.0.94",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -50,5 +50,5 @@
50
50
  "simple-statistics": "^7.8.3",
51
51
  "statistics": "^3.3.0"
52
52
  },
53
- "gitHead": "6b20d32f29809cd6c99fd22296f809816a6c954d"
53
+ "gitHead": "87ca0acbca2c5b70a2b1961711b9078f2b824324"
54
54
  }
@@ -1,6 +1,6 @@
1
1
  import moment from 'moment-timezone'
2
2
 
3
- import { getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
3
+ import { Filter, getQueryBuilderFromListParams, getRepository } from '@things-factory/shell'
4
4
 
5
5
  import { DataSet, DataSetSummaryPeriodType } from '../service/data-set/data-set'
6
6
 
@@ -57,7 +57,8 @@ export async function queryDataSummaryByPeriod(
57
57
  period: 'today' | 'this month' | '30 days' | 'this year' | '12 months',
58
58
  dataSetName: string,
59
59
  dataKeys: string[] | null,
60
- params: ListParam,
60
+ filters: Filter[] | null,
61
+ desc: boolean = false,
61
62
  context: ResolverContext
62
63
  ): Promise<DataSummary[]> {
63
64
  const { domain, user, tx } = context.state
@@ -150,7 +151,7 @@ export async function queryDataSummaryByPeriod(
150
151
  period == 'today'
151
152
  ? 'summary.date, summary.period'
152
153
  : ['this year', '12 months'].includes(period)
153
- ? 'month'
154
+ ? 'SUBSTRING(summary.date, 1, 7)'
154
155
  : 'summary.date'
155
156
  const groupByKeys = dataKeyItems
156
157
  .map((item, index) => {
@@ -163,27 +164,25 @@ export async function queryDataSummaryByPeriod(
163
164
  ? [
164
165
  {
165
166
  sort: 'summary.date',
166
- order: 'DESC'
167
+ order: desc ? 'DESC' : 'ASC'
167
168
  },
168
169
  {
169
170
  sort: 'summary.period',
170
- order: 'DESC'
171
+ order: desc ? 'DESC' : 'ASC'
171
172
  }
172
173
  ]
173
174
  : ['this year', '12 months'].includes(period)
174
- ? [{ sort: 'month', order: 'DESC' }]
175
- : [{ sort: 'summary.date', order: 'DESC' }]
175
+ ? [{ sort: 'month', order: desc ? 'DESC' : 'ASC' }]
176
+ : [{ sort: 'summary.date', order: desc ? 'DESC' : 'ASC' }]
176
177
 
177
178
  var queryBuilder = getQueryBuilderFromListParams({
178
179
  repository: getRepository(DataSummary),
179
- params,
180
+ params: { filters },
180
181
  domain,
181
182
  alias: 'summary',
182
- searchables: ['name', 'description'].concat(searchables)
183
+ searchables: searchables
183
184
  })
184
185
  .select('summary.dataSet')
185
- .addSelect('ds.name', 'name')
186
- .addSelect('ds.description', 'description')
187
186
  .addSelect(selectData)
188
187
  .addSelect('SUM(summary.count)', 'count')
189
188
  .addSelect('SUM(summary.countOoc)', 'countOoc')
@@ -197,8 +196,6 @@ export async function queryDataSummaryByPeriod(
197
196
  .andWhere('summary.date >= :from', { from })
198
197
  .andWhere('summary.date < :to', { to })
199
198
  .addGroupBy('summary.dataSet')
200
- .addGroupBy('ds.name')
201
- .addGroupBy('ds.description')
202
199
  .addGroupBy(groupByPeriod)
203
200
 
204
201
  if (dataKeyItems.length > 0) {
@@ -207,7 +204,7 @@ export async function queryDataSummaryByPeriod(
207
204
 
208
205
  orderByPeriod.map(orderBy => {
209
206
  const { sort, order } = orderBy
210
- queryBuilder.addOrderBy(sort, order)
207
+ queryBuilder.orderBy(sort, order)
211
208
  })
212
209
 
213
210
  const items = await queryBuilder.getRawMany()
@@ -1,5 +1,5 @@
1
1
  import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
2
- import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
2
+ import { Domain, Filter, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
3
3
  import { User } from '@things-factory/auth-base'
4
4
  import { DataKeySet } from '../data-key-set/data-key-set'
5
5
  import { DataItem } from '../data-set/data-item-type'
@@ -40,10 +40,11 @@ export class DataSummaryQuery {
40
40
  @Arg('period') period: 'today' | 'this month' | '30 days' | 'this year' | '12 months',
41
41
  @Arg('dataSetName') dataSetName: string,
42
42
  @Arg('dataKeys', type => [String], { nullable: true }) dataKeys: string[] | null,
43
- @Args() params: ListParam,
43
+ @Arg('filters', type => [Filter], { nullable: true }) filters: Filter[] | null,
44
+ @Arg('desc', type => Boolean, { nullable: true }) desc: boolean,
44
45
  @Ctx() context: ResolverContext
45
46
  ): Promise<DynamicDataSummary[]> {
46
- return await queryDataSummaryByPeriod(period, dataSetName, dataKeys, params, context)
47
+ return await queryDataSummaryByPeriod(period, dataSetName, dataKeys, filters, desc, context)
47
48
  }
48
49
 
49
50
  @Directive('@privilege(category: "data-summary", privilege: "query", domainOwnerGranted: true)')