@spytecgps/nova-orm 1.0.16 → 1.0.17

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 { BillingDeviceTypePlan } from '../../entities';
2
+ import { NovaDataSource } from '../../novaDataSource';
3
+ import { GetBillingDeviceTypePlansParams } from '../../types/billing';
4
+ import { Logger } from '../../types/logger';
5
+ export declare const getBillingDeviceTypePlans: (novaDataSource: NovaDataSource, params: GetBillingDeviceTypePlansParams, logger: Logger) => Promise<BillingDeviceTypePlan[]>;
@@ -0,0 +1,16 @@
1
+ import { BillingDeviceTypePlan } from '../../entities';
2
+ export const getBillingDeviceTypePlans = async (novaDataSource, params, logger) => {
3
+ if (!params?.planId) {
4
+ logger.warn({ params }, 'BillingRepository::getBillingDeviceTypePlans - missing required parameters');
5
+ return null;
6
+ }
7
+ return novaDataSource.safeQuery(async (dataSource) => {
8
+ const billingDeviceTypePlanRepository = dataSource.getRepository(BillingDeviceTypePlan);
9
+ return billingDeviceTypePlanRepository
10
+ .createQueryBuilder('billingDeviceTypePlan')
11
+ .where('billingDeviceTypePlan.planId = :planId', {
12
+ planId: params.planId,
13
+ })
14
+ .getMany();
15
+ }, 'BillingRepository::getBillingDeviceTypePlans');
16
+ };
@@ -0,0 +1,4 @@
1
+ import { NovaDataSource } from '../../novaDataSource';
2
+ import { GetBillingPlanResult, GetBillingPlansParams } from '../../types/billing';
3
+ import { Logger } from '../../types/logger';
4
+ export declare const getBillingPlans: (novaDataSource: NovaDataSource, params: GetBillingPlansParams, logger: Logger) => Promise<GetBillingPlanResult[]>;
@@ -0,0 +1,62 @@
1
+ import { Brackets } from 'typeorm';
2
+ import { BillingDeviceTypePlan, BillingPlans, DeviceType } from '../../entities';
3
+ export const getBillingPlans = async (novaDataSource, params, logger) => {
4
+ if (!params?.deviceTypeId && !params?.targetCustomer && !params?.status && !params?.date) {
5
+ logger.warn({ params }, 'BillingRepository::getBillingPlans - missing required parameters');
6
+ return [];
7
+ }
8
+ const statusToArray = params?.status.split(',');
9
+ const targetCustomerToArray = params?.targetCustomer.split(',');
10
+ return novaDataSource.safeQuery(async (dataSource) => {
11
+ const billingDeviceTypePlanRepository = dataSource.getRepository(BillingDeviceTypePlan);
12
+ let queryBuilder = billingDeviceTypePlanRepository
13
+ .createQueryBuilder('billingDeviceTypePlan')
14
+ .innerJoinAndSelect(BillingPlans, 'billingPlans', 'billingPlans.planId = billingDeviceTypePlan.planId')
15
+ .innerJoinAndSelect(DeviceType, 'deviceType', 'deviceType.id = billingDeviceTypePlan.deviceTypeId')
16
+ .where('billingDeviceTypePlan.deviceTypeId = :deviceTypeId', {
17
+ deviceTypeId: params.deviceTypeId,
18
+ })
19
+ .andWhere('billingDeviceTypePlan.status IN (:...status)', {
20
+ status: statusToArray,
21
+ })
22
+ .andWhere('billingPlans.status IN (:...status)', {
23
+ status: statusToArray,
24
+ })
25
+ .andWhere('billingPlans.targetCustomer IN (:...targetCustomer)', {
26
+ targetCustomer: targetCustomerToArray,
27
+ })
28
+ .andWhere(new Brackets(qb => {
29
+ qb.where('billingPlans.startDate is null').orWhere('billingPlans.endDate is null');
30
+ qb.orWhere('billingPlans.startDate <= :date', {
31
+ date: params.date,
32
+ }).andWhere('billingPlans.endDate >= :date', {
33
+ date: params.date,
34
+ });
35
+ }))
36
+ .select([
37
+ 'billingDeviceTypePlan.deviceTypeId as deviceTypeId',
38
+ 'billingDeviceTypePlan.planId as planId',
39
+ 'billingDeviceTypePlan.deviceType as deviceType',
40
+ 'billingDeviceTypePlan.deviceTypeModel as deviceTypeModel',
41
+ 'billingPlans.targetCustomer as targetCustomer',
42
+ 'billingPlans.code as plan',
43
+ 'billingPlans.platform as platform',
44
+ 'billingPlans.billingFrequency as billingFrequency',
45
+ 'billingPlans.contractLength as contractLength',
46
+ 'billingPlans.description as description',
47
+ 'billingPlans.name as title',
48
+ 'billingPlans.price as price',
49
+ 'billingPlans.createdAt as createdAt',
50
+ 'billingPlans.addOns as addOns',
51
+ 'billingPlans.discounts as discounts',
52
+ 'billingPlans.startDate as startDate',
53
+ 'deviceType.pictureUrl as imageUrl',
54
+ 'deviceType.name as productName',
55
+ ]);
56
+ const sortField = params?.sortField ?? 'billingFrequency';
57
+ const sortOrder = params?.sortOrder ?? 'ASC';
58
+ queryBuilder = queryBuilder.orderBy(`billingPlans.${sortField}`, sortOrder);
59
+ const result = await queryBuilder.getRawMany();
60
+ return result;
61
+ }, 'BillingRepository::getBillingPlans');
62
+ };
@@ -1,5 +1,5 @@
1
- import { Billing, BillingCustomerBraintree, BillingDeviceHistory, BillingHubspotPaymentLog, BillingKlarnaCustomer, BillingKlarnaOrder, BillingStatusHistoryBraintree, BillingSubscriptionBraintree, Magento2Plan, User } from '../../entities';
2
- import { BillingSubscriptionChurnStatus, BillingSubscriptionParams, CanceledImeiResult, CreateBillingDeviceHistoryParams, CreateBillingHubspotPaymentLogParams, CreateBillingParams, CreateBillingStatusHistoryBraintreeParams, GetBillingCustomerBraintreeByIdParams, GetBillingsParams, GetBillingSubscriptionsBraintreeParams, GetCanceledImeisParams, GetChurnStatusByClientIdParams, GetClientIdFromBraintreeCustomerParams, GetMagentoPlanParams, GetUserByBraintreeCustomerIdParams, UpdateBillingCustomerBraintreeParams, UpdateBillingParams, UpsertBillingCustomerBraintreeParams, UpsertBillingKlarnaCustomerParams, UpsertBillingKlarnaOrderParams, UpsertBillingSubscriptionBraintreeParams } from '../../types/billing';
1
+ import { Billing, BillingCustomerBraintree, BillingDeviceHistory, BillingDeviceTypePlan, BillingHubspotPaymentLog, BillingKlarnaCustomer, BillingKlarnaOrder, BillingPlans, BillingStatusHistoryBraintree, BillingSubscriptionBraintree, Magento2Plan, User } from '../../entities';
2
+ import { BillingSubscriptionChurnStatus, BillingSubscriptionParams, CanceledImeiResult, CreateBillingDeviceHistoryParams, CreateBillingHubspotPaymentLogParams, CreateBillingParams, CreateBillingStatusHistoryBraintreeParams, GetBillingCustomerBraintreeByIdParams, GetBillingDeviceTypePlansParams, GetBillingPlanResult, GetBillingPlansParams, GetBillingsParams, GetBillingSubscriptionsBraintreeParams, GetCanceledImeisParams, GetChurnStatusByClientIdParams, GetClientIdFromBraintreeCustomerParams, GetMagentoPlanParams, GetUserByBraintreeCustomerIdParams, UpdateBillingCustomerBraintreeParams, UpdateBillingParams, UpsertBillingCustomerBraintreeParams, UpsertBillingDeviceTypePlanParams, UpsertBillingKlarnaCustomerParams, UpsertBillingKlarnaOrderParams, UpsertBillingPlanParams, UpsertBillingSubscriptionBraintreeParams } from '../../types/billing';
3
3
  import { BaseRepository } from '../baseRepository';
4
4
  export declare class BillingRepository extends BaseRepository {
5
5
  /**
@@ -204,4 +204,33 @@ export declare class BillingRepository extends BaseRepository {
204
204
  * @returns {Promise<BillingSubscriptionBraintree>} The billing klarna order information
205
205
  */
206
206
  getBillingKlarnaOrderByImei(params: BillingSubscriptionParams): Promise<BillingKlarnaOrder>;
207
+ /**
208
+ * Upsert billing plan
209
+ * @param {UpsertBillingPlanParams} params containing information to upsert billing plan
210
+ * @returns The upserted billing plan information
211
+ */
212
+ upsertBillingPlans(params: UpsertBillingPlanParams): Promise<BillingPlans>;
213
+ /**
214
+ * Upsert billing device type plan
215
+ * @param {UpsertBillingDeviceTypePlanParams} params containing information to upsert billing device type plan
216
+ * @returns The upserted billing device type plan information
217
+ */
218
+ upsertBillingDeviceTypePlan(params: UpsertBillingDeviceTypePlanParams): Promise<BillingDeviceTypePlan>;
219
+ /**
220
+ * Get billing device type plans
221
+ * @param {GetBillingDeviceTypePlansParams} params containing information to get billing device type plans
222
+ * - params.planId: The planId
223
+ * @returns The billing device type plans
224
+ */
225
+ getBillingDeviceTypePlans(params: GetBillingDeviceTypePlansParams): Promise<BillingDeviceTypePlan[]>;
226
+ /**
227
+ * Get Billing Plans
228
+ * @param {GetBillingPlansParams} params containing information to get billing plans
229
+ * - params.deviceTypeId: The deviceTypeId
230
+ * - params.targetCustomer: The targetCustomer
231
+ * - params.status: The status
232
+ * - params.date: The date
233
+ * @returns The billing plans
234
+ */
235
+ getBillingPlans(params: GetBillingPlansParams): Promise<GetBillingPlanResult[]>;
207
236
  }
@@ -5,7 +5,9 @@ import { createBillingDeviceHistory } from './createBillingDeviceHistory';
5
5
  import { createBillingHubspotPaymentLog } from './createBillingHubspotPaymentLog';
6
6
  import { createBillingStatusHistoryBraintree } from './createBillingStatusHistoryBraintree';
7
7
  import { getBillingCustomerBraintreeById } from './getBillingCustomerBraintreeById';
8
+ import { getBillingDeviceTypePlans } from './getBillingDeviceTypePlans';
8
9
  import { getBillingKlarnaOrderByImei } from './getBillingKlarnaOrderByImei';
10
+ import { getBillingPlans } from './getBillingPlans';
9
11
  import { getBillings } from './getBillings';
10
12
  import { getBillingSubscriptionsBraintreeByImei } from './getBillingSubscriptionBraintreeByImei';
11
13
  import { getBillingSubscriptionsBraintree } from './getBillingSubscriptionsBraintree';
@@ -18,8 +20,10 @@ import { getUserByBraintreeCustomerId } from './getUserByBraintreeCustomerId';
18
20
  import { updateBilling } from './updateBilling';
19
21
  import { updateBillingCustomerBraintree } from './updateBillingCustomerBraintree';
20
22
  import { upsertBillingCustomerBraintree } from './upsertBillingCustomerBraintree';
23
+ import { upsertBillingDeviceTypePlan } from './upsertBillingDeviceTypePlan';
21
24
  import { upsertBillingKlarnaCustomer } from './upsertBillingKlarnaCustomer';
22
25
  import { upsertBillingKlarnaOrder } from './upsertBillingKlarnaOrder';
26
+ import { upsertBillingPlans } from './upsertBillingPlans';
23
27
  import { upsertBillingSubscriptionBraintree } from './upsertBillingSubscriptionBraintree';
24
28
  export class BillingRepository extends BaseRepository {
25
29
  /**
@@ -350,4 +354,57 @@ export class BillingRepository extends BaseRepository {
350
354
  this.logger.trace(result, 'BillingRepository::getBillingKlarnaOrderByImei result');
351
355
  return result;
352
356
  }
357
+ /**
358
+ * Upsert billing plan
359
+ * @param {UpsertBillingPlanParams} params containing information to upsert billing plan
360
+ * @returns The upserted billing plan information
361
+ */
362
+ async upsertBillingPlans(params) {
363
+ this.logger.trace(params, 'BillingRepository::upsertBillingPlan started with params');
364
+ const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
365
+ const result = await upsertBillingPlans(novaDataSource, params, this.logger);
366
+ this.logger.trace(result, 'BillingRepository::upsertBillingPlan result');
367
+ return result;
368
+ }
369
+ /**
370
+ * Upsert billing device type plan
371
+ * @param {UpsertBillingDeviceTypePlanParams} params containing information to upsert billing device type plan
372
+ * @returns The upserted billing device type plan information
373
+ */
374
+ async upsertBillingDeviceTypePlan(params) {
375
+ this.logger.trace(params, 'BillingRepository::upsertBillingDeviceTypePlan started with params');
376
+ const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
377
+ const result = await upsertBillingDeviceTypePlan(novaDataSource, params, this.logger);
378
+ this.logger.trace(result, 'BillingRepository::upsertBillingDeviceTypePlan result');
379
+ return result;
380
+ }
381
+ /**
382
+ * Get billing device type plans
383
+ * @param {GetBillingDeviceTypePlansParams} params containing information to get billing device type plans
384
+ * - params.planId: The planId
385
+ * @returns The billing device type plans
386
+ */
387
+ async getBillingDeviceTypePlans(params) {
388
+ this.logger.trace(params, 'BillingRepository::getBillingDeviceTypePlans started with params');
389
+ const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
390
+ const result = await getBillingDeviceTypePlans(novaDataSource, params, this.logger);
391
+ this.logger.trace(result, 'BillingRepository::getBillingDeviceTypePlans result');
392
+ return result;
393
+ }
394
+ /**
395
+ * Get Billing Plans
396
+ * @param {GetBillingPlansParams} params containing information to get billing plans
397
+ * - params.deviceTypeId: The deviceTypeId
398
+ * - params.targetCustomer: The targetCustomer
399
+ * - params.status: The status
400
+ * - params.date: The date
401
+ * @returns The billing plans
402
+ */
403
+ async getBillingPlans(params) {
404
+ this.logger.trace(params, 'BillingRepository::getBillingPlans started with params');
405
+ const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
406
+ const result = await getBillingPlans(novaDataSource, params, this.logger);
407
+ this.logger.trace(result, 'BillingRepository::getBillingPlans result');
408
+ return result;
409
+ }
353
410
  }
@@ -0,0 +1,5 @@
1
+ import { BillingDeviceTypePlan } from '../../entities';
2
+ import { NovaDataSource } from '../../novaDataSource';
3
+ import { UpsertBillingDeviceTypePlanParams } from '../../types/billing';
4
+ import { Logger } from '../../types/logger';
5
+ export declare const upsertBillingDeviceTypePlan: (novaDataSource: NovaDataSource, params: UpsertBillingDeviceTypePlanParams, logger: Logger) => Promise<BillingDeviceTypePlan>;
@@ -0,0 +1,66 @@
1
+ import { BillingDeviceTypePlan } from '../../entities';
2
+ export const upsertBillingDeviceTypePlan = async (novaDataSource, params, logger) => {
3
+ if (!params?.deviceTypeId && !params?.planId && !params?.status) {
4
+ logger.warn({ params }, 'BillingRepository::upsertBillingDeviceTypePlan - missing required parameters');
5
+ return null;
6
+ }
7
+ return novaDataSource.safeQuery(async (dataSource) => {
8
+ const billingDeviceTypePlanRepository = dataSource.getRepository(BillingDeviceTypePlan);
9
+ const existingBillingDeviceTypePlan = await billingDeviceTypePlanRepository
10
+ .createQueryBuilder('billingDeviceTypePlan')
11
+ .where('billingDeviceTypePlan.deviceTypeId = :deviceTypeId', {
12
+ deviceTypeId: params.deviceTypeId,
13
+ })
14
+ .andWhere('billingDeviceTypePlan.planId = :planId', {
15
+ planId: params.planId,
16
+ })
17
+ .getOne();
18
+ if (!existingBillingDeviceTypePlan) {
19
+ const billingDeviceTypePlan = {
20
+ deviceTypeId: params.deviceTypeId,
21
+ planId: params.planId,
22
+ deviceTypeModel: params.deviceTypeModel,
23
+ deviceType: params.deviceType ?? null,
24
+ createdAt: params.createdAt,
25
+ status: params.status,
26
+ };
27
+ const insertResult = await billingDeviceTypePlanRepository
28
+ .createQueryBuilder()
29
+ .insert()
30
+ .into(BillingDeviceTypePlan)
31
+ .values([billingDeviceTypePlan])
32
+ .execute();
33
+ return insertResult.identifiers.length > 0
34
+ ? await billingDeviceTypePlanRepository.findOne({
35
+ where: {
36
+ deviceTypeId: params.deviceTypeId,
37
+ planId: params.planId,
38
+ },
39
+ })
40
+ : null;
41
+ }
42
+ else {
43
+ const updateResult = await billingDeviceTypePlanRepository
44
+ .createQueryBuilder()
45
+ .update(BillingDeviceTypePlan)
46
+ .set({
47
+ status: params.status,
48
+ })
49
+ .where('deviceTypeId = :deviceTypeId', {
50
+ deviceTypeId: params.deviceTypeId,
51
+ })
52
+ .andWhere('planId = :planId', {
53
+ planId: params.planId,
54
+ })
55
+ .execute();
56
+ return updateResult.affected > 0
57
+ ? await billingDeviceTypePlanRepository.findOne({
58
+ where: {
59
+ deviceTypeId: params.deviceTypeId,
60
+ planId: params.planId,
61
+ },
62
+ })
63
+ : null;
64
+ }
65
+ }, 'BillingRepository::upsertBillingDeviceTypePlan');
66
+ };
@@ -0,0 +1,5 @@
1
+ import { BillingPlans } from '../../entities';
2
+ import { NovaDataSource } from '../../novaDataSource';
3
+ import { UpsertBillingPlanParams } from '../../types/billing';
4
+ import { Logger } from '../../types/logger';
5
+ export declare const upsertBillingPlans: (novaDataSource: NovaDataSource, params: UpsertBillingPlanParams, logger: Logger) => Promise<BillingPlans>;
@@ -0,0 +1,53 @@
1
+ import { BillingPlans } from '../../entities';
2
+ export const upsertBillingPlans = async (novaDataSource, params, logger) => {
3
+ if (!params?.planId &&
4
+ !params?.targetCustomer &&
5
+ !params?.code &&
6
+ !params?.status &&
7
+ !params?.platform &&
8
+ !params?.billingFrequency &&
9
+ !params?.contractLength &&
10
+ !params?.name &&
11
+ !params?.price &&
12
+ !params?.createdAt &&
13
+ !params?.updatedAt) {
14
+ logger.warn({ params }, 'BillingRepository::upsertBillingPlan - missing required parameters');
15
+ return null;
16
+ }
17
+ return novaDataSource.safeQuery(async (dataSource) => {
18
+ const billingPlansRepository = dataSource.getRepository(BillingPlans);
19
+ const billingPlan = {
20
+ planId: params.planId,
21
+ targetCustomer: params.targetCustomer,
22
+ code: params.code,
23
+ status: params.status,
24
+ platform: params.platform,
25
+ billingFrequency: params.billingFrequency,
26
+ contractLength: params.contractLength,
27
+ numberOfBillingCycles: params.numberOfBillingCycles ?? null,
28
+ description: params.description ?? null,
29
+ name: params.name,
30
+ price: params.price,
31
+ trialDuration: params.trialDuration ?? null,
32
+ trialDurationUnit: params.trialDurationUnit ?? null,
33
+ trialPeriod: params.trialPeriod ? params.trialPeriod : false,
34
+ createdAt: params.createdAt,
35
+ updatedAt: params.updatedAt,
36
+ addOns: params.addOns ?? [],
37
+ discounts: params.discounts ?? [],
38
+ startDate: params.startDate ?? null,
39
+ endDate: params.endDate ?? null,
40
+ };
41
+ const upsertResult = await billingPlansRepository.upsert(billingPlan, {
42
+ conflictPaths: ['planId'],
43
+ });
44
+ const insertedBillingPlan = upsertResult?.raw?.affectedRows > 0
45
+ ? await billingPlansRepository.findOne({
46
+ where: {
47
+ planId: params.planId,
48
+ },
49
+ })
50
+ : null;
51
+ return insertedBillingPlan;
52
+ }, 'BillingRepository::upsertBillingPlan');
53
+ };
@@ -3,25 +3,42 @@ export const getDeviceTypes = async (novaDataSource, params) => {
3
3
  return novaDataSource.safeQuery(async (dataSource) => {
4
4
  const deviceTypesRepository = dataSource.getRepository(DeviceType);
5
5
  let queryBuilder = deviceTypesRepository.createQueryBuilder('deviceType');
6
- if (params?.filters?.deviceTypeIdList?.length) {
7
- queryBuilder = queryBuilder.where('deviceType.id IN (:...deviceTypeIdList)', {
8
- deviceTypeIdList: params.filters.deviceTypeIdList,
6
+ if (params?.filters?.modelFamily) {
7
+ queryBuilder = queryBuilder.where('deviceType.modelFamily = UPPER(:modelFamily)', {
8
+ modelFamily: params.filters.modelFamily,
9
9
  });
10
+ if (params?.filters?.supported) {
11
+ queryBuilder = queryBuilder.andWhere('deviceType.supported = :supported', {
12
+ supported: true,
13
+ });
14
+ }
15
+ if (params?.filters?.activatable) {
16
+ queryBuilder = queryBuilder.andWhere('deviceType.activatable = :activatable', {
17
+ activatable: true,
18
+ });
19
+ }
10
20
  }
11
- if (params?.filters?.brand) {
12
- queryBuilder = queryBuilder.andWhere('LOWER(deviceType.brand) = LOWER(:brand)', {
13
- brand: params.filters.brand,
14
- });
15
- }
16
- if (params?.filters?.model) {
17
- queryBuilder = queryBuilder.andWhere('LOWER(deviceType.model) = LOWER(:model)', {
18
- model: params.filters.model,
19
- });
20
- }
21
- if (params?.filters?.onlyWithRelatedIccidCarrier) {
22
- queryBuilder = queryBuilder
23
- .innerJoin(ImeiIccidCarrier, 'iccidCarrier', 'deviceType.id = iccidCarrier.deviceTypeId')
24
- .groupBy('deviceType.id');
21
+ else {
22
+ if (params?.filters?.deviceTypeIdList?.length) {
23
+ queryBuilder = queryBuilder.where('deviceType.id IN (:...deviceTypeIdList)', {
24
+ deviceTypeIdList: params.filters.deviceTypeIdList,
25
+ });
26
+ }
27
+ if (params?.filters?.brand) {
28
+ queryBuilder = queryBuilder.andWhere('LOWER(deviceType.brand) = LOWER(:brand)', {
29
+ brand: params.filters.brand,
30
+ });
31
+ }
32
+ if (params?.filters?.model) {
33
+ queryBuilder = queryBuilder.andWhere('LOWER(deviceType.model) = LOWER(:model)', {
34
+ model: params.filters.model,
35
+ });
36
+ }
37
+ if (params?.filters?.onlyWithRelatedIccidCarrier) {
38
+ queryBuilder = queryBuilder
39
+ .innerJoin(ImeiIccidCarrier, 'iccidCarrier', 'deviceType.id = iccidCarrier.deviceTypeId')
40
+ .groupBy('deviceType.id');
41
+ }
25
42
  }
26
43
  queryBuilder = queryBuilder.orderBy('deviceType.id');
27
44
  const result = await queryBuilder.getMany();
@@ -262,3 +262,67 @@ export interface UpsertBillingKlarnaOrderParams {
262
262
  nextBillingPeriodAmount?: number | null;
263
263
  paymentMethodToken?: string | null;
264
264
  }
265
+ export type UpsertBillingPlanParamsStatus = 'active' | 'disabled' | 'draft';
266
+ export type UpsertBillingPlanParamsTagetConsumer = 'consumer' | 'enterprise' | 'any';
267
+ export type UpsertBillingPlanParamsTrialDurationUnit = 'day' | 'month' | null;
268
+ export interface UpsertBillingPlanParams {
269
+ planId: string;
270
+ targetCustomer: UpsertBillingPlanParamsTagetConsumer;
271
+ code: string;
272
+ status: UpsertBillingPlanParamsStatus;
273
+ platform: string;
274
+ billingFrequency: number;
275
+ contractLength: number;
276
+ numberOfBillingCycles?: number | null;
277
+ description?: string | null;
278
+ name: string;
279
+ price: string;
280
+ trialDuration?: number | null;
281
+ trialDurationUnit?: UpsertBillingPlanParamsTrialDurationUnit;
282
+ trialPeriod?: boolean | null;
283
+ createdAt: Date;
284
+ updatedAt: Date;
285
+ addOns?: Record<string, any>[] | null;
286
+ discounts?: Record<string, any>[] | null;
287
+ startDate?: Date | null;
288
+ endDate?: Date | null;
289
+ }
290
+ export interface UpsertBillingDeviceTypePlanParams {
291
+ deviceTypeId: number;
292
+ planId: string;
293
+ deviceTypeModel?: string;
294
+ deviceType?: string | null;
295
+ createdAt?: Date;
296
+ status: UpsertBillingPlanParamsStatus;
297
+ }
298
+ export interface GetBillingDeviceTypePlansParams {
299
+ planId: string;
300
+ }
301
+ export interface GetBillingPlansParams {
302
+ deviceTypeId: number;
303
+ targetCustomer: string;
304
+ status: string;
305
+ date: string | null;
306
+ sortField?: 'planId' | 'billingFrequency' | 'price' | 'createdAt';
307
+ sortOrder?: 'ASC' | 'DESC';
308
+ }
309
+ export interface GetBillingPlanResult {
310
+ deviceTypeId: number;
311
+ planId: string;
312
+ deviceType: string;
313
+ deviceTypeModel: string;
314
+ targetCustomer: 'consumer' | 'enterprise' | 'any';
315
+ plan: string;
316
+ platform: string;
317
+ billingFrequency: number;
318
+ contractLength: number;
319
+ description: string;
320
+ price: string;
321
+ createdAt: Date;
322
+ addOns: Record<string, any>[];
323
+ discounts: Record<string, any>[];
324
+ startDate: Date;
325
+ endDate: Date;
326
+ imageUrl: string;
327
+ productName: string;
328
+ }
@@ -99,6 +99,9 @@ export interface GetDeviceTypesParams {
99
99
  brand?: string;
100
100
  model?: string;
101
101
  onlyWithRelatedIccidCarrier?: boolean;
102
+ modelFamily?: string;
103
+ supported?: boolean;
104
+ activatable?: boolean;
102
105
  };
103
106
  }
104
107
  export interface GetImeiIccidCarrierParams {
@@ -0,0 +1,3 @@
1
+ export declare const getBillingPlanTargetCustomer: (planId: string) => 'consumer' | 'enterprise' | 'any';
2
+ export declare const buildBillingPlanCode: (planId: string, billingFrequency: number) => string;
3
+ export declare const formatBillingPlanDate: (date: any) => any;
@@ -0,0 +1,49 @@
1
+ export const getBillingPlanTargetCustomer = (planId) => {
2
+ if (planId.indexOf('b2c') !== -1) {
3
+ return 'consumer';
4
+ }
5
+ else if (planId.indexOf('b2b') !== -1) {
6
+ return 'enterprise';
7
+ }
8
+ return 'any';
9
+ };
10
+ export const buildBillingPlanCode = (planId, billingFrequency) => {
11
+ let createdOn = '';
12
+ if (planId.includes('b2c') || planId.includes('b2b')) {
13
+ createdOn = planId
14
+ .split('_')
15
+ .slice(-3, -1)
16
+ .join('_');
17
+ }
18
+ else {
19
+ createdOn = planId
20
+ .split('_')
21
+ .slice(-2)
22
+ .join('_');
23
+ }
24
+ switch (billingFrequency) {
25
+ case 1:
26
+ return `premium_monthly_${createdOn}`;
27
+ case 3:
28
+ return `premium_3month_${createdOn}`;
29
+ case 6:
30
+ return `premium_6month_${createdOn}`;
31
+ case 12:
32
+ return `premium_annual_${createdOn}`;
33
+ case 24:
34
+ return `premium_biennial_${createdOn}`;
35
+ case 36:
36
+ return `premium_triennial_${createdOn}`;
37
+ default:
38
+ return `premium_montlhy_${createdOn}`;
39
+ }
40
+ };
41
+ export const formatBillingPlanDate = (date) => {
42
+ if (date instanceof Date) {
43
+ return date
44
+ .toISOString()
45
+ .replace('T', ' ')
46
+ .replace('Z', '');
47
+ }
48
+ return date.replace('T', ' ').replace('Z', '');
49
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spytecgps/nova-orm",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "ORM with PlanetScale",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",