@spytecgps/nova-orm 1.0.10 → 1.0.11

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.
@@ -40,6 +40,15 @@ export const getDevices = async (novaDataSource, params, logger) => {
40
40
  if (params.projectionOptions.withClientDeviceSettings) {
41
41
  queryBuilder = queryBuilder.leftJoinAndMapOne('device.clientDeviceSetting', ClientDeviceSetting, 'clientDeviceSetting', 'device.imei = clientDeviceSetting.imei and device.clientId = clientDeviceSetting.clientId');
42
42
  }
43
+ if (params?.sortOptions?.sortField) {
44
+ queryBuilder = queryBuilder.orderBy(`device.${params.sortOptions.sortField}`, params?.sortOptions?.sortOrder ?? 'ASC');
45
+ }
46
+ if (params?.pagingOptions?.pageIndex) {
47
+ const pageSize = params?.pagingOptions?.pageSize ?? 1000;
48
+ const realPageIndex = (params?.pagingOptions?.pageIndex ?? 1) - 1;
49
+ queryBuilder = queryBuilder.offset(realPageIndex * pageSize);
50
+ queryBuilder = queryBuilder.limit(pageSize);
51
+ }
43
52
  const devices = await queryBuilder.getMany();
44
53
  return devices;
45
54
  }, 'DevicesRepository::getDevices');
@@ -4,3 +4,9 @@ export interface ReportPagination {
4
4
  pageIndex: number | 0;
5
5
  };
6
6
  }
7
+ export interface OptionalReportPagination {
8
+ pagingOptions?: {
9
+ pageSize?: number;
10
+ pageIndex?: number;
11
+ };
12
+ }
@@ -1,3 +1,4 @@
1
+ import { OptionalReportPagination } from './common';
1
2
  import { DeviceStatus } from './enums';
2
3
  export interface GetDeviceParams {
3
4
  filters: {
@@ -10,7 +11,7 @@ export interface GetDeviceParams {
10
11
  withClientDeviceSettings: boolean;
11
12
  };
12
13
  }
13
- export interface GetDevicesParams {
14
+ export interface GetDevicesParams extends OptionalReportPagination {
14
15
  filters: {
15
16
  deviceTypeId?: number;
16
17
  status?: DeviceStatus;
@@ -18,9 +19,13 @@ export interface GetDevicesParams {
18
19
  imeiList?: string[];
19
20
  };
20
21
  projectionOptions: {
21
- withDeviceType: boolean;
22
- withIccidCarrier: boolean;
23
- withClientDeviceSettings: boolean;
22
+ withDeviceType?: boolean;
23
+ withIccidCarrier?: boolean;
24
+ withClientDeviceSettings?: boolean;
25
+ };
26
+ sortOptions?: {
27
+ sortField?: 'name';
28
+ sortOrder?: 'ASC' | 'DESC';
24
29
  };
25
30
  }
26
31
  export interface AllImeisAreActiveForClientParams {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spytecgps/nova-orm",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "ORM with PlanetScale",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",