@spytecgps/nova-orm 1.0.13 → 1.0.15
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.
|
@@ -37,6 +37,9 @@ export const getDeviceStatuses = async (novaDataSource, params, logger) => {
|
|
|
37
37
|
if (params.projectionOptions?.withClientDeviceSettings) {
|
|
38
38
|
queryBuilder = queryBuilder.leftJoinAndMapOne('deviceStatus.clientDeviceSetting', ClientDeviceSetting, 'clientDeviceSetting', 'deviceStatus.imei = clientDeviceSetting.imei and deviceStatus.clientId = clientDeviceSetting.clientId');
|
|
39
39
|
}
|
|
40
|
+
queryBuilder = queryBuilder
|
|
41
|
+
.limit(params.pagingOptions?.limit ?? 100)
|
|
42
|
+
.offset(params.pagingOptions?.offset ?? 0);
|
|
40
43
|
const deviceStatuses = await queryBuilder.getMany();
|
|
41
44
|
return deviceStatuses;
|
|
42
45
|
}, 'DeviceStatusRepository::getDevice');
|
|
@@ -7,34 +7,40 @@ export const upsertDeviceStatuses = async (novaDataSource, params, logger) => {
|
|
|
7
7
|
return novaDataSource.safeQuery(async (dataSource) => {
|
|
8
8
|
const deviceStatusRepository = dataSource.getRepository(DeviceStatus);
|
|
9
9
|
const deviceStatuses = params.items.map(item => {
|
|
10
|
-
|
|
10
|
+
const ds = {
|
|
11
11
|
clientId: item.clientId,
|
|
12
12
|
imei: item.imei,
|
|
13
13
|
created: new Date(item.created),
|
|
14
14
|
sendTime: new Date(item.sendTime),
|
|
15
15
|
data: item,
|
|
16
16
|
};
|
|
17
|
+
ds.created.setMilliseconds(0);
|
|
18
|
+
ds.sendTime.setMilliseconds(0);
|
|
19
|
+
return ds;
|
|
17
20
|
});
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
21
|
+
const values = deviceStatuses
|
|
22
|
+
.map(() => {
|
|
23
|
+
return `(?, ?, ?, ?, ?)`;
|
|
24
|
+
})
|
|
25
|
+
.join(', ');
|
|
26
|
+
const queryParams = deviceStatuses.reduce((acc, ds) => {
|
|
27
|
+
acc.push(ds.imei);
|
|
28
|
+
acc.push(ds.clientId);
|
|
29
|
+
acc.push(ds.created);
|
|
30
|
+
acc.push(ds.sendTime);
|
|
31
|
+
acc.push(JSON.stringify(ds.data));
|
|
32
|
+
return acc;
|
|
33
|
+
}, []);
|
|
34
|
+
const updateQueryCondition = 'VALUES(sendTime) >= sendTime';
|
|
35
|
+
const query = `
|
|
36
|
+
INSERT INTO deviceStatus (imei, clientId, created, sendTime, \`data\`)
|
|
37
|
+
VALUES ${values}
|
|
38
|
+
ON DUPLICATE KEY UPDATE
|
|
39
|
+
clientId = CASE WHEN ${updateQueryCondition} THEN VALUES(clientId) ELSE clientId END,
|
|
40
|
+
\`data\` = CASE WHEN ${updateQueryCondition} THEN VALUES(\`data\`) ELSE \`data\` END,
|
|
41
|
+
created = CASE WHEN ${updateQueryCondition} THEN VALUES(created) ELSE created END,
|
|
42
|
+
sendTime = CASE WHEN ${updateQueryCondition} THEN VALUES(sendTime) ELSE sendTime END;`;
|
|
43
|
+
const result = await deviceStatusRepository.query(query, queryParams);
|
|
44
|
+
return result?.affectedRows > 0;
|
|
39
45
|
}, 'DeviceStatusRepository::upsertDeviceStatus');
|
|
40
46
|
};
|
|
@@ -22,6 +22,10 @@ export interface GetDeviceStatusesParams {
|
|
|
22
22
|
withClientDeviceSettings?: boolean;
|
|
23
23
|
clientDeviceSettingsProperties?: (keyof ClientDeviceSetting)[];
|
|
24
24
|
};
|
|
25
|
+
pagingOptions?: {
|
|
26
|
+
limit?: number;
|
|
27
|
+
offset?: number;
|
|
28
|
+
};
|
|
25
29
|
}
|
|
26
30
|
export interface UpsertDeviceStatusesParams {
|
|
27
31
|
items: DeviceStatusEntity[];
|