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 {
data: [];
startTime: string;
endTime: string;
startTime: number;
endTime: number;
deviceUuid?: string;
}

View File

@ -721,18 +721,19 @@ export class DeviceService {
): Promise<getDeviceLogsInterface> {
try {
const now = Date.now();
const twoWeeksAgo = now - 14 * 24 * 60 * 60 * 1000;
const path = `/v2.0/cloud/thing/${deviceId}/report-logs?start_time=${twoWeeksAgo}&end_time=${now}&codes=${code}&size=50`;
const oneHourAgo = now - 1 * 60 * 60 * 1000;
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({
method: 'GET',
path,
});
// Convert keys to camel case
const camelCaseResponse = convertKeysToCamelCase(response);
const logs = camelCaseResponse.result.logs ?? [];
return {
startTime: twoWeeksAgo.toString(),
endTime: now.toString(),
data: camelCaseResponse.result.logs,
startTime: oneHourAgo,
endTime: now,
data: logs,
} as getDeviceLogsInterface;
} catch (error) {
throw new HttpException(