@spytecgps/nova-orm 1.0.1 → 1.0.2

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,4 @@
1
+ import { NovaDataSource } from '../../novaDataSource';
2
+ import { AllImeisAreActiveForClientParams } from '../../types/devices';
3
+ import { Logger } from '../../types/logger';
4
+ export declare const allImeisAreActiveForClient: (novaDataSource: NovaDataSource, params: AllImeisAreActiveForClientParams, logger: Logger) => Promise<boolean>;
@@ -0,0 +1,24 @@
1
+ import { Device } from '../../entities';
2
+ import { DeviceStatus } from '../../types/enums';
3
+ export const allImeisAreActiveForClient = async (novaDataSource, params, logger) => {
4
+ if (!params?.clientId && !params?.imeiList?.length) {
5
+ logger.warn({ params }, 'DevicesRepository::allImeisAreActiveForClient missing required parameters');
6
+ return false;
7
+ }
8
+ return novaDataSource.safeQuery(async (dataSource) => {
9
+ const devicesRepository = dataSource.getRepository(Device);
10
+ const queryBuilder = devicesRepository
11
+ .createQueryBuilder('device')
12
+ .where('device.imei IN (:...imeiList)', {
13
+ imeiList: params.imeiList,
14
+ })
15
+ .andWhere('device.clientId = :clientId', {
16
+ clientId: params.clientId,
17
+ })
18
+ .andWhere('device.status = :status', {
19
+ status: DeviceStatus.Active,
20
+ });
21
+ const count = await queryBuilder.getCount();
22
+ return count === params.imeiList.length;
23
+ }, 'DevicesRepository::getDevicesImeis');
24
+ };
@@ -1,5 +1,5 @@
1
1
  import { ClientDeviceSetting, Device, DeviceCustomConfiguration, DeviceReplacement, DeviceType, IccidStatus, ImeiIccidCarrier } from '../../entities';
2
- import { CanceledDeviceWithActiveSimCard, CarrierStatus, CreateClientDeviceSettingParams, CreateDeviceParams, CreateDeviceReplacementParams, CreateDeviceTypeParams, DeleteDeviceParams, DeviceTypeModelWithDeviceCount, DeviceWithUsersInfo, GenerateIdentifierKeyParams, GetCanceledDevicesWithActiveSimCardsParams, GetCarrierStatusUpdatedBeforeParams, GetClientDeviceSettingParams, GetClientDeviceSettingsParams, GetDeviceCustomConfigParams, GetDeviceParams, GetDevicesParams, GetDeviceTypeByImeiParams, GetDeviceTypesModelsOrderedByDeviceCountParams, GetDeviceTypesParams, GetDeviceWithUsersInfoParams, GetFilteredImeisWithStatusParams, GetIccidStatusParams, GetImeiIccidCarrierParams, GetImeiIccidCarriersParams, UpdateClientDeviceSettingParams, UpdateDeviceParams, UpdateDeviceTypeParams, UpdateIccidStatusParams, UpdateImeiIccidCarrierParams, UpsertIccidStatusParams } from '../../types/devices';
2
+ import { AllImeisAreActiveForClientParams, CanceledDeviceWithActiveSimCard, CarrierStatus, CreateClientDeviceSettingParams, CreateDeviceParams, CreateDeviceReplacementParams, CreateDeviceTypeParams, DeleteDeviceParams, DeviceTypeModelWithDeviceCount, DeviceWithUsersInfo, GenerateIdentifierKeyParams, GetCanceledDevicesWithActiveSimCardsParams, GetCarrierStatusUpdatedBeforeParams, GetClientDeviceSettingParams, GetClientDeviceSettingsParams, GetDeviceCustomConfigParams, GetDeviceParams, GetDevicesParams, GetDeviceTypeByImeiParams, GetDeviceTypesModelsOrderedByDeviceCountParams, GetDeviceTypesParams, GetDeviceWithUsersInfoParams, GetFilteredImeisWithStatusParams, GetIccidStatusParams, GetImeiIccidCarrierParams, GetImeiIccidCarriersParams, UpdateClientDeviceSettingParams, UpdateDeviceParams, UpdateDeviceTypeParams, UpdateIccidStatusParams, UpdateImeiIccidCarrierParams, UpsertIccidStatusParams } from '../../types/devices';
3
3
  import { BaseRepository } from './../baseRepository';
4
4
  export declare class DevicesRepository extends BaseRepository {
5
5
  /**
@@ -22,6 +22,14 @@ export declare class DevicesRepository extends BaseRepository {
22
22
  * - projectionOptions.withIccidCarrier: Whether to get the iccid carrier object
23
23
  */
24
24
  getDevices(params: GetDevicesParams): Promise<Device[]>;
25
+ /**
26
+ * Check if all imeis are active for a client
27
+ * @param {AllImeisAreActiveForClientParams} params containing information to check if all imeis are active for a client
28
+ * - imeis: The imeis to check
29
+ * - clientId: The client id
30
+ * @returns {Promise<boolean>} Whether all imeis are active for a client
31
+ */
32
+ allImeisAreActiveForClient(params: AllImeisAreActiveForClientParams): Promise<boolean>;
25
33
  /**
26
34
  * Get filtered imeis with status
27
35
  * @param {GetFilteredImeisWithStatusParams} params containing information to get filtered imeis with status
@@ -1,5 +1,6 @@
1
1
  import { NovaDataSource } from '../../novaDataSource';
2
2
  import { BaseRepository } from './../baseRepository';
3
+ import { allImeisAreActiveForClient } from './allImeisAreActiveForClient';
3
4
  import { createClientDeviceSetting } from './createClientDeviceSetting';
4
5
  import { createDevice } from './createDevice';
5
6
  import { createDeviceReplacement } from './createDeviceReplacement';
@@ -60,6 +61,20 @@ export class DevicesRepository extends BaseRepository {
60
61
  this.logger.trace(result, 'DevicesRepository::getDevices result');
61
62
  return result;
62
63
  }
64
+ /**
65
+ * Check if all imeis are active for a client
66
+ * @param {AllImeisAreActiveForClientParams} params containing information to check if all imeis are active for a client
67
+ * - imeis: The imeis to check
68
+ * - clientId: The client id
69
+ * @returns {Promise<boolean>} Whether all imeis are active for a client
70
+ */
71
+ async allImeisAreActiveForClient(params) {
72
+ this.logger.trace(params, 'DevicesRepository::allImeisAreActiveForClient started with params');
73
+ const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
74
+ const result = await allImeisAreActiveForClient(novaDataSource, params, this.logger);
75
+ this.logger.trace({ result }, 'DevicesRepository::allImeisAreActiveForClient result');
76
+ return result;
77
+ }
63
78
  /**
64
79
  * Get filtered imeis with status
65
80
  * @param {GetFilteredImeisWithStatusParams} params containing information to get filtered imeis with status
@@ -23,6 +23,10 @@ export interface GetDevicesParams {
23
23
  withClientDeviceSettings: boolean;
24
24
  };
25
25
  }
26
+ export interface AllImeisAreActiveForClientParams {
27
+ imeiList: string[];
28
+ clientId: number;
29
+ }
26
30
  export interface GetFilteredImeisWithStatusParams {
27
31
  filters: {
28
32
  imeiList: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spytecgps/nova-orm",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "ORM with PlanetScale",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",