mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
add start time and end time for the device logs
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { IsNotEmpty, IsString } from 'class-validator';
|
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
||||||
|
|
||||||
export class GetDeviceByRoomUuidDto {
|
export class GetDeviceByRoomUuidDto {
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
@ -18,4 +18,18 @@ export class GetDeviceLogsDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
public code: string;
|
public code: string;
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'startTime',
|
||||||
|
required: false,
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
public startTime: string;
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'endTime',
|
||||||
|
required: false,
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
public endTime: string;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ export interface updateDeviceFirmwareInterface {
|
|||||||
}
|
}
|
||||||
export interface getDeviceLogsInterface {
|
export interface getDeviceLogsInterface {
|
||||||
data: [];
|
data: [];
|
||||||
startTime: number;
|
startTime: string;
|
||||||
endTime: number;
|
endTime: string;
|
||||||
deviceUuid?: string;
|
deviceUuid?: string;
|
||||||
}
|
}
|
||||||
|
@ -806,6 +806,8 @@ export class DeviceService {
|
|||||||
const response = await this.getDeviceLogsTuya(
|
const response = await this.getDeviceLogsTuya(
|
||||||
deviceDetails.deviceTuyaUuid,
|
deviceDetails.deviceTuyaUuid,
|
||||||
query.code,
|
query.code,
|
||||||
|
query.startTime,
|
||||||
|
query.endTime,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -822,11 +824,13 @@ export class DeviceService {
|
|||||||
async getDeviceLogsTuya(
|
async getDeviceLogsTuya(
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
code: string,
|
code: string,
|
||||||
|
startTime: string = (Date.now() - 1 * 60 * 60 * 1000).toString(),
|
||||||
|
endTime: string = Date.now().toString(),
|
||||||
): Promise<getDeviceLogsInterface> {
|
): Promise<getDeviceLogsInterface> {
|
||||||
try {
|
try {
|
||||||
const now = Date.now();
|
console.log(startTime, endTime);
|
||||||
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 path = `/v2.0/cloud/thing/${deviceId}/report-logs?start_time=${startTime}&end_time=${endTime}&codes=${code}&size=50`;
|
||||||
const response = await this.tuya.request({
|
const response = await this.tuya.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path,
|
path,
|
||||||
@ -835,8 +839,8 @@ export class DeviceService {
|
|||||||
const camelCaseResponse = convertKeysToCamelCase(response);
|
const camelCaseResponse = convertKeysToCamelCase(response);
|
||||||
const logs = camelCaseResponse.result.logs ?? [];
|
const logs = camelCaseResponse.result.logs ?? [];
|
||||||
return {
|
return {
|
||||||
startTime: oneHourAgo,
|
startTime,
|
||||||
endTime: now,
|
endTime,
|
||||||
data: logs,
|
data: logs,
|
||||||
} as getDeviceLogsInterface;
|
} as getDeviceLogsInterface;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Reference in New Issue
Block a user