@spytecgps/nova-orm 1.0.9 → 1.0.10

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.
@@ -0,0 +1,5 @@
1
+ import { DevicePairing } from '../../entities';
2
+ import { NovaDataSource } from '../../novaDataSource';
3
+ import { GetDevicePairingsByClientIdParams } from '../../types/devicePairings';
4
+ import { Logger } from '../../types/logger';
5
+ export declare const getDevicePairingsByClientId: (novaDataSource: NovaDataSource, params: GetDevicePairingsByClientIdParams, logger: Logger) => Promise<DevicePairing[]>;
@@ -0,0 +1,22 @@
1
+ import { Device, DevicePairing } from '../../entities';
2
+ export const getDevicePairingsByClientId = async (novaDataSource, params, logger) => {
3
+ if (!params?.filters?.clientId) {
4
+ logger.warn({ params }, 'DevicePairingsRepository::getDevicePairingsByClientId missing required parameters');
5
+ return [];
6
+ }
7
+ return novaDataSource.safeQuery(async (dataSource) => {
8
+ const devicePairingsRepository = dataSource.getRepository(DevicePairing);
9
+ let queryBuilder = devicePairingsRepository
10
+ .createQueryBuilder('devicePairing')
11
+ .innerJoin(Device, 'device', 'devicePairing.imeiMain = device.imei or devicePairing.imeiSecondary = device.imei')
12
+ .where('device.clientId = :clientId', {
13
+ clientId: params.filters.clientId,
14
+ });
15
+ if (params?.pagingOptions?.offset) {
16
+ queryBuilder = queryBuilder.offset(params?.pagingOptions?.offset);
17
+ }
18
+ queryBuilder = queryBuilder.limit(params?.pagingOptions?.limit ?? 100);
19
+ const devicePairings = await queryBuilder.getMany();
20
+ return devicePairings;
21
+ }, 'DevicePairingsRepository::getDevicePairingsByClientId');
22
+ };
@@ -1,5 +1,5 @@
1
1
  import { DevicePairing } from '../../entities';
2
- import { CreateDevicePairingParams, DeleteDevicePairingParams, GetDevicePairingsByImeiParams, GetDevicePairingsParams, UpdateDevicePairingParams } from '../../types/devicePairings';
2
+ import { CreateDevicePairingParams, DeleteDevicePairingParams, GetDevicePairingsByClientIdParams, GetDevicePairingsByImeiParams, GetDevicePairingsParams, UpdateDevicePairingParams } from '../../types/devicePairings';
3
3
  import { BaseRepository } from '../baseRepository';
4
4
  export declare class DevicePairingsRepository extends BaseRepository {
5
5
  /**
@@ -20,6 +20,15 @@ export declare class DevicePairingsRepository extends BaseRepository {
20
20
  * @returns Promise<DevicePairing[]> the device pairings
21
21
  */
22
22
  getDevicePairingsByImei(params: GetDevicePairingsByImeiParams): Promise<DevicePairing[]>;
23
+ /**
24
+ * Get device pairings by clientId
25
+ * @param params params containing information to get device pairings by clientId with filters
26
+ * filters.clientId: the clientId to get device pairings
27
+ * pagingOptions.limit: the limit of the number of device pairings to get
28
+ * pagingOptions.offset: the offset of the number of device pairings to get
29
+ * @returns Promise<DevicePairing[]> the device pairings
30
+ */
31
+ getDevicePairingsByClientId(params: GetDevicePairingsByClientIdParams): Promise<DevicePairing[]>;
23
32
  /**
24
33
  * Create device pairing
25
34
  * @param params params containing information to create device pairing
@@ -3,6 +3,7 @@ import { BaseRepository } from '../baseRepository';
3
3
  import { createDevicePairing } from './createDevicePairing';
4
4
  import { deleteDevicePairing } from './deleteDevicePairing';
5
5
  import { getDevicePairings } from './getDevicePairings';
6
+ import { getDevicePairingsByClientId } from './getDevicePairingsByClientId';
6
7
  import { getDevicePairingsByImei } from './getDevicePairingsByImei';
7
8
  import { updateDevicePairing } from './updateDevicePairing';
8
9
  export class DevicePairingsRepository extends BaseRepository {
@@ -36,6 +37,21 @@ export class DevicePairingsRepository extends BaseRepository {
36
37
  this.logger.trace(result, 'DevicePairingsRepository::getDevicePairingsByImei result');
37
38
  return result;
38
39
  }
40
+ /**
41
+ * Get device pairings by clientId
42
+ * @param params params containing information to get device pairings by clientId with filters
43
+ * filters.clientId: the clientId to get device pairings
44
+ * pagingOptions.limit: the limit of the number of device pairings to get
45
+ * pagingOptions.offset: the offset of the number of device pairings to get
46
+ * @returns Promise<DevicePairing[]> the device pairings
47
+ */
48
+ async getDevicePairingsByClientId(params) {
49
+ this.logger.trace(params, 'DevicePairingsRepository::getDevicePairingsByClientId started with params');
50
+ const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
51
+ const result = await getDevicePairingsByClientId(novaDataSource, params, this.logger);
52
+ this.logger.trace(result, 'DevicePairingsRepository::getDevicePairingsByClientId result');
53
+ return result;
54
+ }
39
55
  /**
40
56
  * Create device pairing
41
57
  * @param params params containing information to create device pairing
@@ -23,6 +23,15 @@ export interface GetDevicePairingsByImeiParams {
23
23
  imei: string;
24
24
  };
25
25
  }
26
+ export interface GetDevicePairingsByClientIdParams {
27
+ filters: {
28
+ clientId: number;
29
+ };
30
+ pagingOptions?: {
31
+ limit?: number;
32
+ offset?: number;
33
+ };
34
+ }
26
35
  export interface UpdateDevicePairingParams {
27
36
  filters: {
28
37
  id: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spytecgps/nova-orm",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "ORM with PlanetScale",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",