@spytecgps/nova-orm 1.0.103 → 1.0.104
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 +1 -1
- package/dist/repositories/positions/getBatteryReportForDevice.d.ts +4 -0
- package/dist/repositories/positions/getBatteryReportForDevice.js +47 -0
- package/dist/repositories/positions/getBatteryReportForDevice.js.map +1 -0
- package/dist/repositories/positions/index.d.ts +2 -1
- package/dist/repositories/positions/index.js +8 -0
- package/dist/repositories/positions/index.js.map +1 -1
- package/dist/types/position.d.ts +9 -1
- package/package.json +1 -1
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { NovaDataSource } from '../../novaDataSource';
|
|
2
|
+
import { Logger } from '../../types/logger';
|
|
3
|
+
import { GetBatteryReportForDeviceParams } from '../../types/position';
|
|
4
|
+
export declare const getBatteryReportForDevice: (novaDataSource: NovaDataSource, params: GetBatteryReportForDeviceParams, logger: Logger) => Promise<any[]>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Position } from '../../entities/position';
|
|
2
|
+
export const getBatteryReportForDevice = async (novaDataSource, params, logger) => {
|
|
3
|
+
if (!(params.filters.clientId && params.filters.imei)) {
|
|
4
|
+
return [];
|
|
5
|
+
}
|
|
6
|
+
// Force the query to run on master or slave
|
|
7
|
+
const dbQueryRunner = novaDataSource.createQueryRunnerFromParams(params);
|
|
8
|
+
try {
|
|
9
|
+
await novaDataSource.connect();
|
|
10
|
+
const positionsRepository = novaDataSource.getRepository(Position);
|
|
11
|
+
let positionsQuery = positionsRepository
|
|
12
|
+
.createQueryBuilder('p')
|
|
13
|
+
.setQueryRunner(dbQueryRunner)
|
|
14
|
+
.select('DATE(p.actualDate)', 'actualDate')
|
|
15
|
+
.addSelect('MAX(p.batteryPercentage)', 'batteryPercentage')
|
|
16
|
+
.where('p.clientId = :clientId', { clientId: params.filters.clientId })
|
|
17
|
+
.andWhere('p.imei = :imei', { imei: params.filters.imei });
|
|
18
|
+
if (params.filters.startDate) {
|
|
19
|
+
positionsQuery = positionsQuery.andWhere('p.actualDate >= :startDate', {
|
|
20
|
+
startDate: params.filters.startDate,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (params.filters.endDate) {
|
|
24
|
+
positionsQuery = positionsQuery.andWhere('p.actualDate <= :endDate', {
|
|
25
|
+
endDate: params.filters.endDate,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const pageSize = params?.pagingOptions?.pageSize ?? 100;
|
|
29
|
+
const pageIndex = params?.pagingOptions?.pageIndex ?? 1;
|
|
30
|
+
positionsQuery = positionsQuery
|
|
31
|
+
.groupBy('DATE(p.actualDate)')
|
|
32
|
+
.orderBy('DATE(p.actualDate)', 'DESC')
|
|
33
|
+
.limit(pageSize)
|
|
34
|
+
.offset(pageSize * (pageIndex - 1));
|
|
35
|
+
const results = await positionsQuery.getRawMany();
|
|
36
|
+
return results;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
logger.error({ error }, 'PositionsRepository::GetPositionsReportByClientId error');
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
await dbQueryRunner.release();
|
|
44
|
+
await novaDataSource.disconnect();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=getBatteryReportForDevice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBatteryReportForDevice.js","sourceRoot":"","sources":["../../../src/repositories/positions/getBatteryReportForDevice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAKlD,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,EAC5C,cAA8B,EAC9B,MAAuC,EACvC,MAAc,EACd,EAAE;IACF,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACr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KAAK,CAAC,QAAQ,CAAC;aACf,MAAM,CAAC,QAAQ,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAA;QAErC,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,UAAU,EAAE,CAAA;QAEjD,OAAO,OAAO,CAAA;KACf;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,yDAAyD,CAAC,CAAA;QAClF,MAAM,KAAK,CAAA;KACZ;YAAS;QACR,MAAM,aAAa,CAAC,OAAO,EAAE,CAAA;QAC7B,MAAM,cAAc,CAAC,UAAU,EAAE,CAAA;KAClC;AACH,CAAC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LatestPosition, Position } from '../../entities';
|
|
2
|
-
import { CreatePositionParams, GetLatestPositionByImeiParams, GetPositionsByImeiParams, GetPositionsReportByClientParams, PositionReport } from '../../types/position';
|
|
2
|
+
import { CreatePositionParams, GetBatteryReportForDeviceParams, GetLatestPositionByImeiParams, GetPositionsByImeiParams, GetPositionsReportByClientParams, PositionReport } from '../../types/position';
|
|
3
3
|
import { BaseRepository } from '../baseRepository';
|
|
4
4
|
export declare class PositionRepository extends BaseRepository {
|
|
5
5
|
/**
|
|
@@ -65,4 +65,5 @@ export declare class PositionRepository extends BaseRepository {
|
|
|
65
65
|
*/
|
|
66
66
|
getPositionsReportByClient(params: GetPositionsReportByClientParams): Promise<PositionReport[]>;
|
|
67
67
|
getLatestPositionByImei(params: GetLatestPositionByImeiParams): Promise<LatestPosition>;
|
|
68
|
+
getBatteryReportForDevice(params: GetBatteryReportForDeviceParams): Promise<any[]>;
|
|
68
69
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NovaDataSource } from '../../novaDataSource';
|
|
2
2
|
import { BaseRepository } from '../baseRepository';
|
|
3
3
|
import { createPosition, upsertPositions } from './createPosition';
|
|
4
|
+
import { getBatteryReportForDevice } from './getBatteryReportForDevice';
|
|
4
5
|
import { getLatestPositionByImei } from './getLatestPositionByImei';
|
|
5
6
|
import { getPositionsByImei } from './getPositionsByImei';
|
|
6
7
|
import { getPositionsReportByClient } from './getPositionsReportByClient';
|
|
@@ -98,5 +99,12 @@ export class PositionRepository extends BaseRepository {
|
|
|
98
99
|
this.logger.trace(result, 'PositionsRepository::getLatestPositionByImei result');
|
|
99
100
|
return result;
|
|
100
101
|
}
|
|
102
|
+
async getBatteryReportForDevice(params) {
|
|
103
|
+
this.logger.trace(params, `PositionsRepository::getBatteryReportForDevice started with params`);
|
|
104
|
+
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger, this.replicaNovaDataSourceConfig);
|
|
105
|
+
const result = await getBatteryReportForDevice(novaDataSource, params, this.logger);
|
|
106
|
+
this.logger.trace(result, 'PositionsRepository::getLatestPositionByImei result');
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
101
109
|
}
|
|
102
110
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/repositories/positions/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/repositories/positions/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AASrD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA;AAEzE,MAAM,OAAO,k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AAC,yBAAyB,CAAC,MAAuC;QACrE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,oEAAoE,CAAC,CAAA;QAE/F,MAAM,cAAc,GAAG,IAAI,cAAc,CACvC,IAAI,CAAC,oBAAoB,EACzB,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,2BAA2B,CACjC,CAAA;QAED,MAAM,MAAM,GAAG,MAAM,yBAAyB,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QAEnF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,qDAAqD,CAAC,CAAA;QAEhF,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|
package/dist/types/position.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseSelectQueryParams, ReportPagination } from './common';
|
|
1
|
+
import { BaseSelectQueryParams, OptionalReportPagination, ReportPagination } from './common';
|
|
2
2
|
export interface CreatePositionParams {
|
|
3
3
|
id?: number;
|
|
4
4
|
imei: string;
|
|
@@ -61,3 +61,11 @@ export interface GetLatestPositionByImeiParams extends BaseSelectQueryParams {
|
|
|
61
61
|
imei: string;
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
+
export interface GetBatteryReportForDeviceParams extends OptionalReportPagination {
|
|
65
|
+
filters: {
|
|
66
|
+
imei: string;
|
|
67
|
+
clientId: number;
|
|
68
|
+
startDate?: Date;
|
|
69
|
+
endDate?: Date;
|
|
70
|
+
};
|
|
71
|
+
}
|