@spytecgps/nova-orm 0.0.5 → 0.0.7
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/index.js +2 -5
- package/dist/index.js.LICENSE.txt +41 -0
- package/dist/utils/uuidHelpers.d.ts +0 -1
- package/package.json +3 -3
- package/dist/entities/alert.js +0 -118
- package/dist/entities/alertType.js +0 -65
- package/dist/entities/assetCategory.js +0 -29
- package/dist/entities/billing.js +0 -81
- package/dist/entities/billingCustomerBraintree.js +0 -53
- package/dist/entities/billingDeviceHistory.js +0 -52
- package/dist/entities/billingStatusHistoryBraintree.js +0 -55
- package/dist/entities/billingSubscriptionBraintree.js +0 -169
- package/dist/entities/blacklist.js +0 -44
- package/dist/entities/blacklistType.js +0 -28
- package/dist/entities/cellTower.js +0 -56
- package/dist/entities/client.js +0 -96
- package/dist/entities/clientConfiguration.js +0 -42
- package/dist/entities/clientDeviceSetting.js +0 -76
- package/dist/entities/clientType.js +0 -32
- package/dist/entities/country.js +0 -76
- package/dist/entities/dataSourceType.js +0 -28
- package/dist/entities/deactivation.js +0 -63
- package/dist/entities/deactivationReason.js +0 -36
- package/dist/entities/device.js +0 -123
- package/dist/entities/deviceBehavior.js +0 -105
- package/dist/entities/deviceHistory.js +0 -44
- package/dist/entities/deviceModelListener.js +0 -40
- package/dist/entities/deviceReplacement.js +0 -49
- package/dist/entities/deviceType.js +0 -100
- package/dist/entities/deviceTypeEvent.js +0 -29
- package/dist/entities/deviceTypeFeature.js +0 -29
- package/dist/entities/deviceTypeFirmware.js +0 -57
- package/dist/entities/entityTag.js +0 -42
- package/dist/entities/entityType.js +0 -28
- package/dist/entities/event.js +0 -32
- package/dist/entities/feature.js +0 -32
- package/dist/entities/firmwareUpgradeTask.js +0 -53
- package/dist/entities/geofence.js +0 -86
- package/dist/entities/geofenceEvent.js +0 -87
- package/dist/entities/imeiIccidCarrier.js +0 -78
- package/dist/entities/imeiIccidHistory.js +0 -38
- package/dist/entities/index.js +0 -68
- package/dist/entities/industry.js +0 -40
- package/dist/entities/mobileNetwork.js +0 -44
- package/dist/entities/notificationRecipient.js +0 -70
- package/dist/entities/organization.js +0 -40
- package/dist/entities/plan.js +0 -72
- package/dist/entities/position.js +0 -84
- package/dist/entities/securityRole.js +0 -36
- package/dist/entities/serviceProvider.js +0 -36
- package/dist/entities/serviceProviderProduct.js +0 -54
- package/dist/entities/serviceProviderProductNetwork.js +0 -28
- package/dist/entities/serviceProviderProductType.js +0 -28
- package/dist/entities/sim.js +0 -78
- package/dist/entities/trip.js +0 -103
- package/dist/entities/tripCompletionStatus.js +0 -32
- package/dist/entities/tripPosition.js +0 -24
- package/dist/entities/user.js +0 -116
- package/dist/entities/userActivation.js +0 -45
- package/dist/entities/userActivationDevice.js +0 -105
- package/dist/entities/userActivationEvent.js +0 -52
- package/dist/entities/userActivationMetric.js +0 -167
- package/dist/entities/userAlertConfiguration.js +0 -68
- package/dist/entities/userAppFeedback.js +0 -45
- package/dist/entities/userAppIncident.js +0 -131
- package/dist/entities/userConfiguration.js +0 -87
- package/dist/entities/userDataDeletionRequest.js +0 -48
- package/dist/entities/userDeviceBehaviorTask.js +0 -61
- package/dist/entities/userInvitation.js +0 -75
- package/dist/entities/userRatingRequest.js +0 -63
- package/dist/entities/userRegistrationAttempt.js +0 -145
- package/dist/entities/userSecurityRole.js +0 -30
- package/dist/novaDataSource.js +0 -59
- package/dist/repositories/baseRepository.js +0 -5
- package/dist/repositories/devicesRepository.js +0 -122
- package/dist/repositories/index.js +0 -3
- package/dist/repositories/securityRepository.js +0 -99
- package/dist/types/enums.js +0 -11
- package/dist/utils/uuidHelpers.js +0 -6
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
|
11
|
-
let UserRegistrationAttempt = class UserRegistrationAttempt {
|
|
12
|
-
};
|
|
13
|
-
__decorate([
|
|
14
|
-
PrimaryGeneratedColumn({ type: 'int', name: 'id' }),
|
|
15
|
-
__metadata("design:type", Number)
|
|
16
|
-
], UserRegistrationAttempt.prototype, "id", void 0);
|
|
17
|
-
__decorate([
|
|
18
|
-
Column('varchar', { name: 'firstName', nullable: true, length: 100 }),
|
|
19
|
-
__metadata("design:type", String)
|
|
20
|
-
], UserRegistrationAttempt.prototype, "firstName", void 0);
|
|
21
|
-
__decorate([
|
|
22
|
-
Column('varchar', { name: 'lastName', nullable: true, length: 100 }),
|
|
23
|
-
__metadata("design:type", String)
|
|
24
|
-
], UserRegistrationAttempt.prototype, "lastName", void 0);
|
|
25
|
-
__decorate([
|
|
26
|
-
Column('varchar', { name: 'email', nullable: true, length: 255 }),
|
|
27
|
-
__metadata("design:type", String)
|
|
28
|
-
], UserRegistrationAttempt.prototype, "email", void 0);
|
|
29
|
-
__decorate([
|
|
30
|
-
Column('varchar', { name: 'phoneNumber', nullable: true, length: 20 }),
|
|
31
|
-
__metadata("design:type", String)
|
|
32
|
-
], UserRegistrationAttempt.prototype, "phoneNumber", void 0);
|
|
33
|
-
__decorate([
|
|
34
|
-
Column('varchar', { name: 'phoneCode', nullable: true, length: 10 }),
|
|
35
|
-
__metadata("design:type", String)
|
|
36
|
-
], UserRegistrationAttempt.prototype, "phoneCode", void 0);
|
|
37
|
-
__decorate([
|
|
38
|
-
Column('varchar', { name: 'phoneCodeCountryId', nullable: true, length: 10 }),
|
|
39
|
-
__metadata("design:type", String)
|
|
40
|
-
], UserRegistrationAttempt.prototype, "phoneCodeCountryId", void 0);
|
|
41
|
-
__decorate([
|
|
42
|
-
Column('varchar', { name: 'companyName', nullable: true, length: 255 }),
|
|
43
|
-
__metadata("design:type", String)
|
|
44
|
-
], UserRegistrationAttempt.prototype, "companyName", void 0);
|
|
45
|
-
__decorate([
|
|
46
|
-
Column('varchar', { name: 'street', nullable: true, length: 255 }),
|
|
47
|
-
__metadata("design:type", String)
|
|
48
|
-
], UserRegistrationAttempt.prototype, "street", void 0);
|
|
49
|
-
__decorate([
|
|
50
|
-
Column('varchar', { name: 'state', nullable: true, length: 100 }),
|
|
51
|
-
__metadata("design:type", String)
|
|
52
|
-
], UserRegistrationAttempt.prototype, "state", void 0);
|
|
53
|
-
__decorate([
|
|
54
|
-
Column('varchar', { name: 'postalCode', nullable: true, length: 20 }),
|
|
55
|
-
__metadata("design:type", String)
|
|
56
|
-
], UserRegistrationAttempt.prototype, "postalCode", void 0);
|
|
57
|
-
__decorate([
|
|
58
|
-
Column('varchar', { name: 'country', nullable: true, length: 100 }),
|
|
59
|
-
__metadata("design:type", String)
|
|
60
|
-
], UserRegistrationAttempt.prototype, "country", void 0);
|
|
61
|
-
__decorate([
|
|
62
|
-
Column('int', { name: 'pin', nullable: true }),
|
|
63
|
-
__metadata("design:type", Number)
|
|
64
|
-
], UserRegistrationAttempt.prototype, "pin", void 0);
|
|
65
|
-
__decorate([
|
|
66
|
-
Column('varchar', { name: 'imei', nullable: true, length: 15 }),
|
|
67
|
-
__metadata("design:type", String)
|
|
68
|
-
], UserRegistrationAttempt.prototype, "imei", void 0);
|
|
69
|
-
__decorate([
|
|
70
|
-
Column('varchar', { name: 'deviceType', nullable: true, length: 50 }),
|
|
71
|
-
__metadata("design:type", String)
|
|
72
|
-
], UserRegistrationAttempt.prototype, "deviceType", void 0);
|
|
73
|
-
__decorate([
|
|
74
|
-
Column('varchar', { name: 'deviceName', nullable: true, length: 255 }),
|
|
75
|
-
__metadata("design:type", String)
|
|
76
|
-
], UserRegistrationAttempt.prototype, "deviceName", void 0);
|
|
77
|
-
__decorate([
|
|
78
|
-
Column('varchar', { name: 'orderId', nullable: true, length: 255 }),
|
|
79
|
-
__metadata("design:type", String)
|
|
80
|
-
], UserRegistrationAttempt.prototype, "orderId", void 0);
|
|
81
|
-
__decorate([
|
|
82
|
-
Column('varchar', { name: 'trackingReason', nullable: true, length: 255 }),
|
|
83
|
-
__metadata("design:type", String)
|
|
84
|
-
], UserRegistrationAttempt.prototype, "trackingReason", void 0);
|
|
85
|
-
__decorate([
|
|
86
|
-
Column('varchar', { name: 'userName', nullable: true, length: 50 }),
|
|
87
|
-
__metadata("design:type", String)
|
|
88
|
-
], UserRegistrationAttempt.prototype, "userName", void 0);
|
|
89
|
-
__decorate([
|
|
90
|
-
Column('varchar', { name: 'plan', nullable: true, length: 50 }),
|
|
91
|
-
__metadata("design:type", String)
|
|
92
|
-
], UserRegistrationAttempt.prototype, "plan", void 0);
|
|
93
|
-
__decorate([
|
|
94
|
-
Column('varchar', { name: 'billingFrequency', nullable: true, length: 50 }),
|
|
95
|
-
__metadata("design:type", String)
|
|
96
|
-
], UserRegistrationAttempt.prototype, "billingFrequency", void 0);
|
|
97
|
-
__decorate([
|
|
98
|
-
Column('varchar', { name: 'planId', nullable: true, length: 50 }),
|
|
99
|
-
__metadata("design:type", String)
|
|
100
|
-
], UserRegistrationAttempt.prototype, "planId", void 0);
|
|
101
|
-
__decorate([
|
|
102
|
-
Column('varchar', { name: 'subscriptionSource', nullable: true, length: 50 }),
|
|
103
|
-
__metadata("design:type", String)
|
|
104
|
-
], UserRegistrationAttempt.prototype, "subscriptionSource", void 0);
|
|
105
|
-
__decorate([
|
|
106
|
-
Column('varchar', { name: 'subscriptionId', nullable: true, length: 50 }),
|
|
107
|
-
__metadata("design:type", String)
|
|
108
|
-
], UserRegistrationAttempt.prototype, "subscriptionId", void 0);
|
|
109
|
-
__decorate([
|
|
110
|
-
Column('varchar', { name: 'platform', nullable: true, length: 25 }),
|
|
111
|
-
__metadata("design:type", String)
|
|
112
|
-
], UserRegistrationAttempt.prototype, "platform", void 0);
|
|
113
|
-
__decorate([
|
|
114
|
-
Column('varchar', { name: 'status', nullable: true, length: 10 }),
|
|
115
|
-
__metadata("design:type", String)
|
|
116
|
-
], UserRegistrationAttempt.prototype, "status", void 0);
|
|
117
|
-
__decorate([
|
|
118
|
-
Column('datetime', { name: 'createdAt', nullable: true }),
|
|
119
|
-
__metadata("design:type", Date)
|
|
120
|
-
], UserRegistrationAttempt.prototype, "createdAt", void 0);
|
|
121
|
-
__decorate([
|
|
122
|
-
Column('datetime', { name: 'lastUpdatedAt', nullable: true }),
|
|
123
|
-
__metadata("design:type", Date)
|
|
124
|
-
], UserRegistrationAttempt.prototype, "lastUpdatedAt", void 0);
|
|
125
|
-
__decorate([
|
|
126
|
-
Column('varchar', { name: 'city', nullable: true, length: 255 }),
|
|
127
|
-
__metadata("design:type", String)
|
|
128
|
-
], UserRegistrationAttempt.prototype, "city", void 0);
|
|
129
|
-
__decorate([
|
|
130
|
-
Column('int', { name: 'clientId', nullable: true }),
|
|
131
|
-
__metadata("design:type", Number)
|
|
132
|
-
], UserRegistrationAttempt.prototype, "clientId", void 0);
|
|
133
|
-
__decorate([
|
|
134
|
-
Column('varchar', { name: 'countryCode', nullable: true, length: 3 }),
|
|
135
|
-
__metadata("design:type", String)
|
|
136
|
-
], UserRegistrationAttempt.prototype, "countryCode", void 0);
|
|
137
|
-
__decorate([
|
|
138
|
-
Column('binary', { name: 'tempUserId', nullable: true, length: 16 }),
|
|
139
|
-
__metadata("design:type", Buffer)
|
|
140
|
-
], UserRegistrationAttempt.prototype, "tempUserId", void 0);
|
|
141
|
-
UserRegistrationAttempt = __decorate([
|
|
142
|
-
Index('ixUserRegistrationAttemptTempUserId', ['tempUserId'], {}),
|
|
143
|
-
Entity('userRegistrationAttempt', { schema: 'nova' })
|
|
144
|
-
], UserRegistrationAttempt);
|
|
145
|
-
export { UserRegistrationAttempt };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Column, Entity, Index } from 'typeorm';
|
|
11
|
-
let UserSecurityRole = class UserSecurityRole {
|
|
12
|
-
};
|
|
13
|
-
__decorate([
|
|
14
|
-
Column('int', { name: 'clientId' }),
|
|
15
|
-
__metadata("design:type", Number)
|
|
16
|
-
], UserSecurityRole.prototype, "clientId", void 0);
|
|
17
|
-
__decorate([
|
|
18
|
-
Column('binary', { primary: true, name: 'userId', length: 16 }),
|
|
19
|
-
__metadata("design:type", Buffer)
|
|
20
|
-
], UserSecurityRole.prototype, "userId", void 0);
|
|
21
|
-
__decorate([
|
|
22
|
-
Column('tinyint', { primary: true, name: 'securityRoleId' }),
|
|
23
|
-
__metadata("design:type", Number)
|
|
24
|
-
], UserSecurityRole.prototype, "securityRoleId", void 0);
|
|
25
|
-
UserSecurityRole = __decorate([
|
|
26
|
-
Index('ixUserSecurityRoleClientId', ['clientId'], {}),
|
|
27
|
-
Index('ixUserSecurityRoleSecurityRoleId', ['securityRoleId'], {}),
|
|
28
|
-
Entity('userSecurityRole', { schema: 'nova' })
|
|
29
|
-
], UserSecurityRole);
|
|
30
|
-
export { UserSecurityRole };
|
package/dist/novaDataSource.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// import { logger } from '@spytecgps/sdk'
|
|
2
|
-
import { DataSource, } from 'typeorm';
|
|
3
|
-
export class NovaDataSource {
|
|
4
|
-
constructor(config) {
|
|
5
|
-
this.dataSource = new DataSource({
|
|
6
|
-
type: 'mysql',
|
|
7
|
-
host: 'aws.connect.psdb.cloud',
|
|
8
|
-
port: 3306,
|
|
9
|
-
database: 'nova',
|
|
10
|
-
ssl: {
|
|
11
|
-
rejectUnauthorized: true,
|
|
12
|
-
},
|
|
13
|
-
synchronize: false,
|
|
14
|
-
logging: false,
|
|
15
|
-
entities: ['src/entities/**/*.ts'],
|
|
16
|
-
subscribers: [],
|
|
17
|
-
...config,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Performs connection to the database.
|
|
22
|
-
*/
|
|
23
|
-
async connect() {
|
|
24
|
-
await this.dataSource.initialize();
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Closes connection with the database.
|
|
28
|
-
* Once connection is closed, you cannot use repositories or perform any operations except opening connection again.
|
|
29
|
-
*/
|
|
30
|
-
async disconnect() {
|
|
31
|
-
try {
|
|
32
|
-
if (this.dataSource.isInitialized) {
|
|
33
|
-
await this.dataSource.destroy();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
// TODO: Add logger
|
|
38
|
-
// logger.error({ error }, 'Failed to close connection to database')
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Gets repository for the given entity.
|
|
43
|
-
*/
|
|
44
|
-
getRepository(target) {
|
|
45
|
-
return this.dataSource.getRepository(target);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Executes raw SQL query and returns raw database results.
|
|
49
|
-
*/
|
|
50
|
-
async query(query, parameters) {
|
|
51
|
-
return this.dataSource.query(query, parameters, null);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Creates a new query builder that can be used to build a SQL query.
|
|
55
|
-
*/
|
|
56
|
-
async createQueryBuilder(entityClass, alias) {
|
|
57
|
-
return this.dataSource.createQueryBuilder(entityClass, alias, null);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
// import { logger } from '@spytecgps/sdk'
|
|
2
|
-
import { Device, DeviceType, ImeiIccidCarrier } from '../entities';
|
|
3
|
-
import { NovaDataSource } from '../novaDataSource';
|
|
4
|
-
import { DeviceStatus } from '../types/enums';
|
|
5
|
-
import { BaseRepository } from './baseRepository';
|
|
6
|
-
export class DevicesRepository extends BaseRepository {
|
|
7
|
-
/**
|
|
8
|
-
* Get device by imei
|
|
9
|
-
* @param {string} imei The imei of the device
|
|
10
|
-
*/
|
|
11
|
-
async getDeviceByImei(imei, options) {
|
|
12
|
-
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig);
|
|
13
|
-
try {
|
|
14
|
-
await novaDataSource.connect();
|
|
15
|
-
const devicesRepository = novaDataSource.getRepository(Device);
|
|
16
|
-
let device = null;
|
|
17
|
-
if (!options.withDeviceType && !options.withIccidCarrier) {
|
|
18
|
-
device = await devicesRepository.findOne({ where: { imei } });
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
let queryBuilder = devicesRepository.createQueryBuilder('device');
|
|
22
|
-
if (options.withDeviceType) {
|
|
23
|
-
queryBuilder = queryBuilder.leftJoinAndMapOne('device.deviceType', DeviceType, 'deviceType', 'device.deviceTypeId = deviceType.id');
|
|
24
|
-
}
|
|
25
|
-
if (options.withIccidCarrier) {
|
|
26
|
-
queryBuilder = queryBuilder.leftJoinAndMapOne('device.iccidCarrier', ImeiIccidCarrier, 'iccidCarrier', 'device.imei = iccidCarrier.imei');
|
|
27
|
-
}
|
|
28
|
-
device = await queryBuilder.where('device.imei = :imei', { imei }).getOne();
|
|
29
|
-
}
|
|
30
|
-
return device;
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
// TODO: Add logger
|
|
34
|
-
// logger.error({ error }, 'DevicesRepository::getDeviceByImei error')
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
finally {
|
|
38
|
-
await novaDataSource.disconnect();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Get devices by type id
|
|
43
|
-
* @param {number} deviceTypeId The device type id
|
|
44
|
-
* @param {boolean} onlyActiveDevices Whether to get only active devices
|
|
45
|
-
*/
|
|
46
|
-
async getDevicesByDeviceTypeId(deviceTypeId, onlyActiveDevices, options) {
|
|
47
|
-
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig);
|
|
48
|
-
try {
|
|
49
|
-
await novaDataSource.connect();
|
|
50
|
-
const devicesRepository = novaDataSource.getRepository(Device);
|
|
51
|
-
let devices = null;
|
|
52
|
-
if (!options.withDeviceType && !options.withIccidCarrier) {
|
|
53
|
-
const filterCondition = onlyActiveDevices
|
|
54
|
-
? { where: { deviceTypeId, status: DeviceStatus.Active } }
|
|
55
|
-
: {
|
|
56
|
-
where: { deviceTypeId },
|
|
57
|
-
};
|
|
58
|
-
devices = await devicesRepository.find(filterCondition);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
let queryBuilder = devicesRepository.createQueryBuilder('device');
|
|
62
|
-
if (options.withDeviceType) {
|
|
63
|
-
queryBuilder = queryBuilder.leftJoinAndMapOne('device.deviceType', DeviceType, 'deviceType', 'device.deviceTypeId = deviceType.id');
|
|
64
|
-
}
|
|
65
|
-
if (options.withIccidCarrier) {
|
|
66
|
-
queryBuilder = queryBuilder.leftJoinAndMapOne('device.iccidCarrier', ImeiIccidCarrier, 'iccidCarrier', 'device.imei = iccidCarrier.imei');
|
|
67
|
-
}
|
|
68
|
-
queryBuilder = queryBuilder.where('device.deviceTypeId = :deviceTypeId', { deviceTypeId });
|
|
69
|
-
if (onlyActiveDevices) {
|
|
70
|
-
queryBuilder = queryBuilder.andWhere('device.status = :status', {
|
|
71
|
-
status: DeviceStatus.Active,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
devices = await queryBuilder.getMany();
|
|
75
|
-
}
|
|
76
|
-
return devices;
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
// TODO: Add logger
|
|
80
|
-
// logger.error({ error }, 'DevicesRepository::getDeviceByImei error')
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
finally {
|
|
84
|
-
await novaDataSource.disconnect();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Get device types
|
|
89
|
-
* @param {boolean} onlyWithRelatedIccidCarrier Whether to get only device types with iccid carrier
|
|
90
|
-
*/
|
|
91
|
-
async getDeviceTypes(onlyWithRelatedIccidCarrier) {
|
|
92
|
-
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig);
|
|
93
|
-
try {
|
|
94
|
-
await novaDataSource.connect();
|
|
95
|
-
const deviceTypesRepository = novaDataSource.getRepository(DeviceType);
|
|
96
|
-
let deviceTypes = null;
|
|
97
|
-
if (!onlyWithRelatedIccidCarrier) {
|
|
98
|
-
deviceTypes = await deviceTypesRepository
|
|
99
|
-
.createQueryBuilder('deviceType')
|
|
100
|
-
.orderBy('deviceType.id')
|
|
101
|
-
.getMany();
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
deviceTypes = await deviceTypesRepository
|
|
105
|
-
.createQueryBuilder('deviceType')
|
|
106
|
-
.innerJoin(ImeiIccidCarrier, 'iccidCarrier', 'deviceType.id = iccidCarrier.deviceTypeId')
|
|
107
|
-
.groupBy('deviceType.id')
|
|
108
|
-
.orderBy('deviceType.id')
|
|
109
|
-
.getMany();
|
|
110
|
-
}
|
|
111
|
-
return deviceTypes;
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
// TODO: Add logger
|
|
115
|
-
// logger.error({ error }, 'DevicesRepository::getDeviceTypes error')
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
finally {
|
|
119
|
-
await novaDataSource.disconnect();
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
// import { logger } from '@spytecgps/sdk'
|
|
2
|
-
import { SecurityRole, UserSecurityRole } from '../entities';
|
|
3
|
-
import { NovaDataSource } from '../novaDataSource';
|
|
4
|
-
import { uuidStringToBinaryBuffer } from '../utils/uuidHelpers';
|
|
5
|
-
import { BaseRepository } from './baseRepository';
|
|
6
|
-
export class SecurityRepository extends BaseRepository {
|
|
7
|
-
/**
|
|
8
|
-
* Get all security roles
|
|
9
|
-
*/
|
|
10
|
-
async getAllRoles() {
|
|
11
|
-
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig);
|
|
12
|
-
try {
|
|
13
|
-
await novaDataSource.connect();
|
|
14
|
-
const rolesRepository = novaDataSource.getRepository(SecurityRole);
|
|
15
|
-
const roles = await rolesRepository.find();
|
|
16
|
-
return roles;
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
// TODO: Add logger
|
|
20
|
-
// logger.error({ error }, 'SecurityRepository::getAllRoles error')
|
|
21
|
-
throw error;
|
|
22
|
-
}
|
|
23
|
-
finally {
|
|
24
|
-
await novaDataSource.disconnect();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Get roles of the user
|
|
29
|
-
*/
|
|
30
|
-
async getUserRoles(userId) {
|
|
31
|
-
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig);
|
|
32
|
-
try {
|
|
33
|
-
await novaDataSource.connect();
|
|
34
|
-
const userSecurityRolesRepository = novaDataSource.getRepository(UserSecurityRole);
|
|
35
|
-
const userRoles = await userSecurityRolesRepository.find({
|
|
36
|
-
where: { userId: uuidStringToBinaryBuffer(userId) },
|
|
37
|
-
});
|
|
38
|
-
return userRoles;
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
// TODO: Add logger
|
|
42
|
-
// logger.error({ error }, 'SecurityRepository::getUserRoles error')
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
await novaDataSource.disconnect();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Get user roles by clientId
|
|
51
|
-
*/
|
|
52
|
-
async getUserRolesByClientId(clientId, filterRole = null) {
|
|
53
|
-
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig);
|
|
54
|
-
try {
|
|
55
|
-
await novaDataSource.connect();
|
|
56
|
-
const userSecurityRolesRepository = novaDataSource.getRepository(UserSecurityRole);
|
|
57
|
-
const filterCondition = filterRole
|
|
58
|
-
? { where: { clientId, securityRoleId: filterRole } }
|
|
59
|
-
: {
|
|
60
|
-
where: { clientId },
|
|
61
|
-
};
|
|
62
|
-
const userRoles = await userSecurityRolesRepository.find(filterCondition);
|
|
63
|
-
return userRoles;
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
// TODO: Add logger
|
|
67
|
-
// logger.error({ error }, 'SecurityRepository::getUserRolesByClientId error')
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
finally {
|
|
71
|
-
await novaDataSource.disconnect();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Whether the user is in role
|
|
76
|
-
*/
|
|
77
|
-
async isInRole(userId, role) {
|
|
78
|
-
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig);
|
|
79
|
-
try {
|
|
80
|
-
await novaDataSource.connect();
|
|
81
|
-
const userSecurityRolesRepository = novaDataSource.getRepository(UserSecurityRole);
|
|
82
|
-
const userRole = await userSecurityRolesRepository.findOne({
|
|
83
|
-
where: {
|
|
84
|
-
userId: uuidStringToBinaryBuffer(userId),
|
|
85
|
-
securityRoleId: role,
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
return userRole !== null;
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
// TODO: Add logger
|
|
92
|
-
// logger.error({ error }, 'SecurityRepository::isAdmin error')
|
|
93
|
-
throw error;
|
|
94
|
-
}
|
|
95
|
-
finally {
|
|
96
|
-
await novaDataSource.disconnect();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
package/dist/types/enums.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export var HapnSecurityRole;
|
|
2
|
-
(function (HapnSecurityRole) {
|
|
3
|
-
HapnSecurityRole[HapnSecurityRole["Admin"] = 1] = "Admin";
|
|
4
|
-
HapnSecurityRole[HapnSecurityRole["Collaborator"] = 2] = "Collaborator";
|
|
5
|
-
HapnSecurityRole[HapnSecurityRole["Owner"] = 3] = "Owner";
|
|
6
|
-
})(HapnSecurityRole || (HapnSecurityRole = {}));
|
|
7
|
-
export var DeviceStatus;
|
|
8
|
-
(function (DeviceStatus) {
|
|
9
|
-
DeviceStatus["Active"] = "A";
|
|
10
|
-
DeviceStatus["Deleted"] = "D";
|
|
11
|
-
})(DeviceStatus || (DeviceStatus = {}));
|