mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 11:44:53 +00:00
Merge pull request #90 from SyncrowIOT/change-start-time-device-log
Update Device Log Retrieval Logic and Interface
This commit is contained in:
@ -66,7 +66,7 @@ export interface updateDeviceFirmwareInterface {
|
|||||||
}
|
}
|
||||||
export interface getDeviceLogsInterface {
|
export interface getDeviceLogsInterface {
|
||||||
data: [];
|
data: [];
|
||||||
startTime: string;
|
startTime: number;
|
||||||
endTime: string;
|
endTime: number;
|
||||||
deviceUuid?: string;
|
deviceUuid?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -721,18 +721,19 @@ export class DeviceService {
|
|||||||
): Promise<getDeviceLogsInterface> {
|
): Promise<getDeviceLogsInterface> {
|
||||||
try {
|
try {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const twoWeeksAgo = now - 14 * 24 * 60 * 60 * 1000;
|
const oneHourAgo = now - 1 * 60 * 60 * 1000;
|
||||||
const path = `/v2.0/cloud/thing/${deviceId}/report-logs?start_time=${twoWeeksAgo}&end_time=${now}&codes=${code}&size=50`;
|
const path = `/v2.0/cloud/thing/${deviceId}/report-logs?start_time=${oneHourAgo}&end_time=${now}&codes=${code}&size=50`;
|
||||||
const response = await this.tuya.request({
|
const response = await this.tuya.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path,
|
path,
|
||||||
});
|
});
|
||||||
// Convert keys to camel case
|
// Convert keys to camel case
|
||||||
const camelCaseResponse = convertKeysToCamelCase(response);
|
const camelCaseResponse = convertKeysToCamelCase(response);
|
||||||
|
const logs = camelCaseResponse.result.logs ?? [];
|
||||||
return {
|
return {
|
||||||
startTime: twoWeeksAgo.toString(),
|
startTime: oneHourAgo,
|
||||||
endTime: now.toString(),
|
endTime: now,
|
||||||
data: camelCaseResponse.result.logs,
|
data: logs,
|
||||||
} as getDeviceLogsInterface;
|
} as getDeviceLogsInterface;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
|
|||||||
Reference in New Issue
Block a user