@spytecgps/nova-orm 1.0.15 → 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.
- package/dist/entities/billingDeviceTypePlan.d.ts +12 -0
- package/dist/entities/billingDeviceTypePlan.js +63 -0
- package/dist/entities/billingPlanFeatures.d.ts +6 -0
- package/dist/entities/billingPlanFeatures.js +36 -0
- package/dist/entities/billingPlans.d.ts +22 -0
- package/dist/entities/billingPlans.js +126 -0
- package/dist/entities/bleMeshConfiguration.js +0 -1
- package/dist/entities/deviceStatus.js +0 -2
- package/dist/entities/index.d.ts +4 -1
- package/dist/entities/index.js +4 -1
- package/dist/entities/userInvitation.d.ts +1 -0
- package/dist/entities/userInvitation.js +5 -0
- package/dist/index.js +1 -1
- package/dist/repositories/billing/getBillingDeviceTypePlans.d.ts +5 -0
- package/dist/repositories/billing/getBillingDeviceTypePlans.js +16 -0
- package/dist/repositories/billing/getBillingPlans.d.ts +4 -0
- package/dist/repositories/billing/getBillingPlans.js +62 -0
- package/dist/repositories/billing/index.d.ts +31 -2
- package/dist/repositories/billing/index.js +57 -0
- package/dist/repositories/billing/upsertBillingDeviceTypePlan.d.ts +5 -0
- package/dist/repositories/billing/upsertBillingDeviceTypePlan.js +66 -0
- package/dist/repositories/billing/upsertBillingPlans.d.ts +5 -0
- package/dist/repositories/billing/upsertBillingPlans.js +53 -0
- package/dist/repositories/devices/getDeviceTypes.js +34 -17
- package/dist/repositories/userInvitations/createUserInvitation.js +1 -0
- package/dist/repositories/userInvitations/updateUserInvitation.js +3 -1
- package/dist/types/billing.d.ts +64 -0
- package/dist/types/devices.d.ts +3 -0
- package/dist/types/userInvitations.d.ts +2 -0
- package/dist/utils/billingPlansHelper.d.ts +3 -0
- package/dist/utils/billingPlansHelper.js +49 -0
- package/package.json +1 -1
|
@@ -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?.
|
|
7
|
-
queryBuilder = queryBuilder.where('deviceType.
|
|
8
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.
|
|
24
|
-
|
|
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();
|
|
@@ -35,6 +35,7 @@ export const createUserInvitation = async (novaDataSource, params, logger) => {
|
|
|
35
35
|
minAccessDate: params.minAccessDate,
|
|
36
36
|
boundaries: params.boundaries,
|
|
37
37
|
boundaryAccess: params.boundaryAccess,
|
|
38
|
+
tasksAccess: params.tasksAccess,
|
|
38
39
|
createdAt: now,
|
|
39
40
|
modifiedAt: now,
|
|
40
41
|
};
|
|
@@ -21,7 +21,8 @@ export const updateUserInvitation = async (novaDataSource, params, logger) => {
|
|
|
21
21
|
!params?.values?.trackerAccess &&
|
|
22
22
|
!params?.values?.minAccessDate &&
|
|
23
23
|
!params?.values?.boundaries &&
|
|
24
|
-
!params?.values?.boundaryAccess
|
|
24
|
+
!params?.values?.boundaryAccess &&
|
|
25
|
+
!params?.values?.tasksAccess) {
|
|
25
26
|
logger.warn({ params }, 'UsersRepository::updateUserInvitation - missing required parameters');
|
|
26
27
|
return false;
|
|
27
28
|
}
|
|
@@ -41,6 +42,7 @@ export const updateUserInvitation = async (novaDataSource, params, logger) => {
|
|
|
41
42
|
minAccessDate: params?.values?.minAccessDate,
|
|
42
43
|
boundaries: params?.values?.boundaries,
|
|
43
44
|
boundaryAccess: params?.values?.boundaryAccess,
|
|
45
|
+
tasksAccess: params?.values?.tasksAccess,
|
|
44
46
|
modifiedAt: now,
|
|
45
47
|
});
|
|
46
48
|
queryBuilder = queryBuilder.where('id = :id', { id: invitationIdBinaryBuffer });
|
package/dist/types/billing.d.ts
CHANGED
|
@@ -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
|
+
}
|
package/dist/types/devices.d.ts
CHANGED
|
@@ -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 {
|
|
@@ -24,6 +24,7 @@ export interface UpdateUserInvitationParams {
|
|
|
24
24
|
minAccessDate?: Date;
|
|
25
25
|
boundaries?: string;
|
|
26
26
|
boundaryAccess?: string;
|
|
27
|
+
tasksAccess?: string;
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
export interface CreateUserInvitationParams {
|
|
@@ -38,4 +39,5 @@ export interface CreateUserInvitationParams {
|
|
|
38
39
|
minAccessDate?: Date;
|
|
39
40
|
boundaries?: string;
|
|
40
41
|
boundaryAccess?: string;
|
|
42
|
+
tasksAccess?: string;
|
|
41
43
|
}
|
|
@@ -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
|
+
};
|