@spytecgps/nova-orm 0.0.38 → 0.0.40

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 { Country } from '../../entities';
2
+ import { NovaDataSource } from '../../novaDataSource';
3
+ import { GetCountryParams } from '../../types/countries';
4
+ export declare const getCountry: (novaDataSource: NovaDataSource, params: GetCountryParams) => Promise<Country>;
@@ -0,0 +1,13 @@
1
+ import { Country } from '../../entities';
2
+ import { GetCountryParams } from '../../types/countries';
3
+ import { BaseRepository } from '../baseRepository';
4
+ export declare class CountriesRepository extends BaseRepository {
5
+ /**
6
+ * Get country
7
+ * @param {GetCountryParams} params containing information to get a country
8
+ * - filters.id: The country id
9
+ * - filters.alpha2Code: The country alpha2Code
10
+ * @returns The country information
11
+ */
12
+ getCountry(params: GetCountryParams): Promise<Country>;
13
+ }
@@ -1,6 +1,9 @@
1
1
  import { BoundariesRepository } from './boundaries';
2
2
  import { ClientsRepository } from './clients';
3
+ import { CountriesRepository } from './countries';
3
4
  import { DevicesRepository } from './devices';
4
5
  import { FirmwaresRepository } from './firmwares';
6
+ import { PositionRepository } from './positions';
5
7
  import { SecurityRepository } from './security';
6
- export { SecurityRepository, DevicesRepository, BoundariesRepository, ClientsRepository, FirmwaresRepository, };
8
+ import { UsersRepository } from './users';
9
+ export { SecurityRepository, DevicesRepository, BoundariesRepository, ClientsRepository, FirmwaresRepository, PositionRepository, UsersRepository, CountriesRepository, };
@@ -0,0 +1,6 @@
1
+ import { Position } from '../../entities';
2
+ import { NovaDataSource } from '../../novaDataSource';
3
+ import { Logger } from '../../types/logger';
4
+ import { CreatePositionParams } from '../../types/position';
5
+ export declare const createPosition: (novaDataSource: NovaDataSource, params: CreatePositionParams, logger: Logger) => Promise<Position>;
6
+ export declare const createPositions: (novaDataSource: NovaDataSource, params: CreatePositionParams[], logger: Logger) => Promise<Position[]>;
@@ -0,0 +1,5 @@
1
+ import { Position } from '../../entities';
2
+ import { NovaDataSource } from '../../novaDataSource';
3
+ import { Logger } from '../../types/logger';
4
+ import { GetPositionsByImeiParams } from '../../types/position';
5
+ export declare const getPositionsByImei: (novaDataSource: NovaDataSource, params: GetPositionsByImeiParams, logger: Logger) => Promise<Position[]>;
@@ -0,0 +1,4 @@
1
+ import { NovaDataSource } from '../../novaDataSource';
2
+ import { Logger } from '../../types/logger';
3
+ import { GetPositionsReportByClientIdParams, PositionReport } from '../../types/position';
4
+ export declare const getPositionsReportByClientId: (novaDataSource: NovaDataSource, params: GetPositionsReportByClientIdParams, logger: Logger) => Promise<PositionReport[]>;
@@ -0,0 +1,62 @@
1
+ import { Position } from '../../entities';
2
+ import { CreatePositionParams, GetPositionsByImeiParams, GetPositionsReportByClientIdParams, PositionReport } from '../../types/position';
3
+ import { BaseRepository } from '../baseRepository';
4
+ export declare class PositionRepository extends BaseRepository {
5
+ /**
6
+ * Create a position
7
+ * @param {CreatePositionParams} params containing information to create a position
8
+ * - id: position id. if null will be generated
9
+ * - imei: imei of the device reporting the position
10
+ * - lat: the latitude of the position
11
+ * - lon: the longitude of the position
12
+ * - actualDate: the actual date of the message
13
+ * - speed: the speed reported by the device
14
+ * - odometer: the odometer reported by the device
15
+ * - messageId: the id of the message
16
+ * - batteryPercentage: the battery percentage reported by the device
17
+ * - clientId: the client id of owner of the device
18
+ * - address: the address of the position
19
+ * - sendTime: the time the message was sent
20
+ * - gpsUtcTime: the time the gps was set
21
+ * - externalBatteryPercentage: the external battery percentage reported by the device
22
+ */
23
+ createPosition(params: CreatePositionParams): Promise<Position>;
24
+ /**
25
+ * Create a position
26
+ * @param {CreatePositionParams[]} params array containing information to create a positions
27
+ * - id: position id. if null will be generated
28
+ * - imei: imei of the device reporting the position
29
+ * - lat: the latitude of the position
30
+ * - lon: the longitude of the position
31
+ * - actualDate: the actual date of the message
32
+ * - speed: the speed reported by the device
33
+ * - odometer: the odometer reported by the device
34
+ * - messageId: the id of the message
35
+ * - batteryPercentage: the battery percentage reported by the device
36
+ * - clientId: the client id of owner of the device
37
+ * - address: the address of the position
38
+ * - sendTime: the time the message was sent
39
+ * - gpsUtcTime: the time the gps was set
40
+ * - externalBatteryPercentage: the external battery percentage reported by the device
41
+ */
42
+ createPositions(params: CreatePositionParams[]): Promise<Position[]>;
43
+ /**
44
+ * Get positions by imei
45
+ * @param {GetPositionsByImeiParams} params containing information to get positions
46
+ * - filters.imei: filters by imei to get positions
47
+ */
48
+ getPositionsByImei(params: GetPositionsByImeiParams): Promise<Position[]>;
49
+ /**
50
+ * Get positions report by client id
51
+ * @param {GetPositionsReportByClientIdParams} params containing information to get positions
52
+ * - filters.clientId: filters by client id to get positions
53
+ * - filters.imeis: filters by imeis to get positions
54
+ * - filters.actualDateFrom: filters by actual date from to get positions
55
+ * - filters.actualDateTo: filters by actual date to to get positions
56
+ * - filters.speedMin: filters by speed min to get positions
57
+ * - filters.speedMax: filters by speed max to get positions
58
+ * - pageSize: the page size
59
+ * - pageIndex: the page index
60
+ */
61
+ getPositionsReportByClientId(params: GetPositionsReportByClientIdParams): Promise<PositionReport[]>;
62
+ }
@@ -0,0 +1,4 @@
1
+ import { User } from '../../entities/user';
2
+ import { NovaDataSource } from '../../novaDataSource';
3
+ import { CreateUserParams } from '../../types/user';
4
+ export declare const createUser: (novaDataSource: NovaDataSource, params: CreateUserParams) => Promise<User>;
@@ -0,0 +1,3 @@
1
+ import { NovaDataSource } from '../../novaDataSource';
2
+ import { DeleteUserParams } from '../../types/user';
3
+ export declare const deleteUser: (novaDataSource: NovaDataSource, params: DeleteUserParams) => Promise<boolean>;
@@ -0,0 +1,4 @@
1
+ import { User } from '../../entities';
2
+ import { NovaDataSource } from '../../novaDataSource';
3
+ import { GetUserByIdParams } from '../../types/user';
4
+ export declare const getUserById: (novaDataSource: NovaDataSource, params: GetUserByIdParams) => Promise<User>;
@@ -0,0 +1,4 @@
1
+ import { User } from '../../entities';
2
+ import { NovaDataSource } from '../../novaDataSource';
3
+ import { GetUsersParams } from '../../types/user';
4
+ export declare const getUsers: (novaDataSource: NovaDataSource, params: GetUsersParams) => Promise<User[]>;
@@ -0,0 +1,3 @@
1
+ import { NovaDataSource } from '../../novaDataSource';
2
+ import { GetUsersIdsByPhoneAndCountryCodeParams } from '../../types/user';
3
+ export declare const getUsersIdsByPhoneAndCountryCode: (novaDataSource: NovaDataSource, params: GetUsersIdsByPhoneAndCountryCodeParams) => Promise<string[]>;
@@ -0,0 +1,3 @@
1
+ import { NovaDataSource } from '../../novaDataSource';
2
+ import { GetUsersWithRolesParams, UserWithRole } from '../../types/user';
3
+ export declare const getUsersWithRoles: (novaDataSource: NovaDataSource, params: GetUsersWithRolesParams) => Promise<UserWithRole[]>;
@@ -0,0 +1,111 @@
1
+ import { User } from '../../entities/user';
2
+ import { CreateUserParams, DeleteUserParams, GetUserByIdParams, GetUsersConfigurationByImeiParams, GetUsersIdsByPhoneAndCountryCodeParams, GetUsersParams, GetUsersWithRolesParams, UpdateUserParams, UserWithRole } from '../../types/user';
3
+ import { BaseRepository } from '../baseRepository';
4
+ export declare class UsersRepository extends BaseRepository {
5
+ /**
6
+ * Get user by id
7
+ * @param {GetUserByIdParams} params containing information to get a user by id
8
+ * - filters.id: The user id
9
+ * @returns The user information
10
+ */
11
+ getUserById(params: GetUserByIdParams): Promise<User>;
12
+ /**
13
+ * Get users with filters
14
+ * @param {GetUsersParams} params containing information to get users with filters
15
+ * - filters.clientId: The client id to obtain all users from that client
16
+ * - filters.email: The user email to obtain all users with that email (lower case and trimmed comparison)
17
+ * - filters.userName: The userName to obtain all users with that userName (lower case and trimmed comparison, using userName and preferredUserName fields)
18
+ * - filters.search: Search test to obtain all users with that search text (lower case and trimmed comparison, using userName, preferredUserName, email and id fields)
19
+ * @returns The user information
20
+ */
21
+ getUsers(params: GetUsersParams): Promise<User[]>;
22
+ /**
23
+ * Get user data by imei
24
+ * @param {GetUsersConfigurationByImeiParams} params containing information to get a device by imei
25
+ * - filters.imei: The imei of the device
26
+ */
27
+ getUsersConfigurationByImei(params: GetUsersConfigurationByImeiParams): Promise<User[]>;
28
+ /**
29
+ * Get user ids by phone and country code
30
+ * @param {GetUsersIdsByPhoneAndCountryCodeParams} params containing information to get a user by phone and country code
31
+ * - filters.phone: The phone of the user. If the phone parameter is in the format +[internationalDirectDialing][phone], the +[internationalDirectDialing] should correspond to the internationalDirectDialing in the user's profile
32
+ * - filters.countryCode: The country code of the user (US, MX, etc)
33
+ */
34
+ getUsersIdsByPhoneAndCountryCode(params: GetUsersIdsByPhoneAndCountryCodeParams): Promise<string[]>;
35
+ /**
36
+ * Get users with roles
37
+ * @param {GetUsersWithRolesParams} params containing information to get users with roles
38
+ * - filters.clientId: The client id to obtain all users from that client
39
+ * - filters.roleId: The role id to obtain all users with that role, optional
40
+ * - filters.status: The status to obtain all users with that status, optional
41
+ * roleId or status must be provided
42
+ * @returns The user information with the role name
43
+ */
44
+ getUsersWithRoles(params: GetUsersWithRolesParams): Promise<UserWithRole[]>;
45
+ /**
46
+ * Create a new user
47
+ * @param {CreateUserParams} params containing information to create a new user
48
+ * id: the user id, required
49
+ * firstName: the first name, required
50
+ * lastName: the last name, required
51
+ * companyName: the company name, optional
52
+ * telephone: the phone number, optional
53
+ * street: the street from the user's address, optional
54
+ * postalCode: the postal code from the user's address, optional
55
+ * city: the city from the user's address, optional
56
+ * region: the region from the user's address, optional
57
+ * email: the email, required
58
+ * userName: the user name, required
59
+ * preferredUserName: the preferred user name, optional
60
+ * status: the status, optional. If not provided, the default value is 'A' (active)
61
+ * clientId: the client id, required
62
+ * pinCode: the pin code, optional
63
+ * isAdmin: whether the user is administrator, optional. If not provided, the default value is false
64
+ * countryId: the country id, optional
65
+ * telephoneCountryId: the country id corresponding to the phone number, optional
66
+ * dataSourceTypeId?: the data source type id, optional
67
+ * emailVerified: whether the email is verified, optional. If not provided, the default value is true
68
+ * @returns The created user
69
+ */
70
+ createUser(params: CreateUserParams): Promise<User>;
71
+ /**
72
+ * Delete a user
73
+ * @param {DeleteUserParams} params containing information to delete a user
74
+ * id: the user id, required
75
+ * @returns Whether the user was deleted or not
76
+ */
77
+ deleteUser(params: DeleteUserParams): Promise<boolean>;
78
+ /**
79
+ * Update a user
80
+ * @param {UpdateUserParams} params containing information to update a user
81
+ * At least one filter must be provided:
82
+ * filters.userId: the user id to filter the users to update, optional
83
+ * filters.email: the user email to filter the users to update, optional
84
+ * filters.statusList: a list of status to filter the users to update, optional
85
+ * At least one value must be provided:
86
+ * values.firstName: the first name, optional
87
+ * values.lastName: the last name, optional
88
+ * values.companyName: the company name, optional
89
+ * values.telephone: the phone number, optional
90
+ * values.street: the street from the user's address, optional
91
+ * values.postalCode: the postal code from the user's address, optional
92
+ * values.city: the city from the user's address, optional
93
+ * values.region: the region from the user's address, optional
94
+ * values.email: the email, optional
95
+ * values.userName: the user name, optional
96
+ * values.preferredUserName: the preferred user name, optional
97
+ * values.status: the status, optional
98
+ * values.isAdmin: whether the user is administrator, optional
99
+ * values.countryId: the country id, optional
100
+ * values.countryCode: the country alpha2 code to find the countryId, optional (if countryId is provided, countryCode is ignored)
101
+ * values.telephoneCountryId: the country id corresponding to the phone number, optional
102
+ * values.telephoneCountryCode: the country alpha2 code to find the telephoneCountryId, optional (if telephoneCountryId is provided, telephoneCountryCode is ignored)
103
+ * values.dataSourceTypeId?: the data source type id, optional
104
+ * values.emailVerified: whether the email is verified, optional
105
+ * values.latitude: the latitude, optional
106
+ * values.longitude: the longitude, optional
107
+ * values.lastLoginAt: the last login date, optional
108
+ * @returns Whether the user was updated or not
109
+ */
110
+ updateUser(params: UpdateUserParams): Promise<boolean>;
111
+ }
@@ -0,0 +1,3 @@
1
+ import { NovaDataSource } from '../../novaDataSource';
2
+ import { UpdateUserParams } from '../../types/user';
3
+ export declare const updateUser: (novaDataSource: NovaDataSource, params: UpdateUserParams) => Promise<boolean>;
@@ -0,0 +1,6 @@
1
+ export interface GetCountryParams {
2
+ filters: {
3
+ id?: string;
4
+ alpha2Code?: string;
5
+ };
6
+ }
@@ -4,4 +4,5 @@ import * as Devices from './devices';
4
4
  import * as Firmwares from './firmwares';
5
5
  import * as Logger from './logger';
6
6
  import * as Security from './security';
7
- export { Logger, Devices, Firmwares, Security, Boundaries, Clients };
7
+ import * as Users from './user';
8
+ export { Logger, Devices, Firmwares, Security, Boundaries, Clients, Users };
@@ -0,0 +1,51 @@
1
+ export interface CreatePositionParams {
2
+ id?: number;
3
+ imei: string;
4
+ lat?: number;
5
+ lon?: number;
6
+ actualDate: Date;
7
+ createdAt?: Date;
8
+ speed?: number;
9
+ odometer?: number;
10
+ messageId: string;
11
+ batteryPercentage?: number;
12
+ clientId: number;
13
+ address?: string;
14
+ sendTime: Date;
15
+ gpsUtcTime?: Date;
16
+ externalBatteryPercentage?: number;
17
+ externalPowerVoltage?: number;
18
+ }
19
+ export interface GetPositionsByImeiParams {
20
+ filters: {
21
+ imei: string;
22
+ };
23
+ }
24
+ export interface GetPositionsReportByClientIdParams {
25
+ filters: {
26
+ clientId: number;
27
+ imeis?: string[] | null;
28
+ actualDateFrom?: Date | null;
29
+ actualDateTo?: Date | null;
30
+ speedMin?: number | null;
31
+ speedMax?: number | null;
32
+ };
33
+ pagingOptions: {
34
+ limit: number | 25;
35
+ offset: number | 1;
36
+ };
37
+ }
38
+ export interface PositionReport {
39
+ imei: string;
40
+ created: Date;
41
+ actualDate: Date;
42
+ lat: number;
43
+ lon: number;
44
+ address: string;
45
+ speed: number;
46
+ odometer: number;
47
+ batteryPercentage: number;
48
+ externalPowerVoltage: number;
49
+ externalBatteryPercentage: number;
50
+ totalCount: number;
51
+ }
@@ -1,5 +1,91 @@
1
+ import { User } from '../entities/user';
1
2
  export interface GetUsersConfigurationByImeiParams {
2
3
  filters: {
3
4
  imei: string;
4
5
  };
5
6
  }
7
+ export interface GetUserByIdParams {
8
+ filters: {
9
+ id: string;
10
+ };
11
+ }
12
+ export interface GetUsersParams {
13
+ filters: {
14
+ email?: string;
15
+ userName?: string;
16
+ clientId?: number;
17
+ search?: string;
18
+ };
19
+ }
20
+ export interface GetUsersIdsByPhoneAndCountryCodeParams {
21
+ filters: {
22
+ phone: string;
23
+ countryCode: string;
24
+ };
25
+ }
26
+ export interface GetUsersWithRolesParams {
27
+ filters: {
28
+ clientId: number;
29
+ roleId?: number;
30
+ status?: string;
31
+ };
32
+ }
33
+ export interface UserWithRole extends User {
34
+ role: string;
35
+ }
36
+ export interface CreateUserParams {
37
+ id: string;
38
+ firstName: string;
39
+ lastName: string;
40
+ companyName?: string;
41
+ telephone?: string;
42
+ street?: string;
43
+ postalCode?: string;
44
+ city?: string;
45
+ region?: string;
46
+ email: string;
47
+ userName: string;
48
+ preferredUserName?: string;
49
+ status?: string;
50
+ clientId: number;
51
+ pinCode?: string;
52
+ isAdmin?: boolean;
53
+ countryId?: number;
54
+ telephoneCountryId?: number;
55
+ dataSourceTypeId?: number;
56
+ emailVerified?: boolean;
57
+ }
58
+ export interface DeleteUserParams {
59
+ id: string;
60
+ }
61
+ export interface UpdateUserParams {
62
+ filters: {
63
+ userId?: string;
64
+ email?: string;
65
+ statusList?: string[];
66
+ };
67
+ values: {
68
+ firstName?: string;
69
+ lastName?: string;
70
+ companyName?: string;
71
+ telephone?: string;
72
+ street?: string;
73
+ postalCode?: string;
74
+ city?: string;
75
+ region?: string;
76
+ email?: string;
77
+ userName?: string;
78
+ preferredUserName?: string;
79
+ status?: string;
80
+ isAdmin?: boolean;
81
+ countryId?: number;
82
+ countryCode?: string;
83
+ telephoneCountryId?: number;
84
+ telephoneCountryCode?: string;
85
+ dataSourceTypeId?: number;
86
+ emailVerified?: boolean;
87
+ latitude?: number;
88
+ longitude?: number;
89
+ lastLoginAt?: Date;
90
+ };
91
+ }
@@ -0,0 +1 @@
1
+ export declare const mapRawEntityToEntity: <T>(rawEntity: any, columnsPrefix?: string) => T;
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@spytecgps/nova-orm",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
4
4
  "description": "ORM with PlanetScale",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "devDependencies": {
8
8
  "@types/jest": "^29.5.1",
9
9
  "@types/node": "^14.18.36",
10
+ "@types/uuid": "^9.0.2",
10
11
  "@typescript-eslint/eslint-plugin": "^5.59.0",
11
12
  "@typescript-eslint/parser": "^5.59.0",
12
13
  "aws-sdk": "^2.877.0",
@@ -1,11 +0,0 @@
1
- import { User } from '../../entities/user';
2
- import { GetUsersConfigurationByImeiParams } from '../../types/user';
3
- import { BaseRepository } from '../baseRepository';
4
- export declare class UserRepository extends BaseRepository {
5
- /**
6
- * Get user data by imei
7
- * @param {GetUsersConfigurationByImeiParams} params containing information to get a device by imei
8
- * - filters.imei: The imei of the device
9
- */
10
- getUsersConfigurationByImei(params: GetUsersConfigurationByImeiParams): Promise<User[]>;
11
- }