Merge pull request #90 from SyncrowIOT/change-start-time-device-log

Update Device Log Retrieval Logic and Interface
This commit is contained in:
faris Aljohari
2024-08-26 16:06:18 +03:00
committed by GitHub
2 changed files with 8 additions and 7 deletions

View File

@ -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;
} }

View File

@ -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(