mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +00:00
replaced naming unit with space
This commit is contained in:
@ -48,8 +48,8 @@ export class AutomationController {
|
|||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Get(':spaceUuid')
|
@Get(':spaceUuid')
|
||||||
async getAutomationByUnit(@Param() param: SpaceParamDto) {
|
async getAutomationBySpace(@Param() param: SpaceParamDto) {
|
||||||
const automation = await this.automationService.getAutomationByUnit(
|
const automation = await this.automationService.getAutomationBySpace(
|
||||||
param.spaceUuid,
|
param.spaceUuid,
|
||||||
);
|
);
|
||||||
return automation;
|
return automation;
|
||||||
|
@ -5,7 +5,7 @@ export interface AddAutomationInterface {
|
|||||||
id: string;
|
id: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export interface GetAutomationByUnitInterface {
|
export interface GetAutomationBySpaceInterface {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
msg?: string;
|
msg?: string;
|
||||||
result: {
|
result: {
|
||||||
|
@ -20,7 +20,7 @@ import {
|
|||||||
AutomationDetailsResult,
|
AutomationDetailsResult,
|
||||||
AutomationResponseData,
|
AutomationResponseData,
|
||||||
DeleteAutomationInterface,
|
DeleteAutomationInterface,
|
||||||
GetAutomationByUnitInterface,
|
GetAutomationBySpaceInterface,
|
||||||
} from '../interface/automation.interface';
|
} from '../interface/automation.interface';
|
||||||
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||||
import {
|
import {
|
||||||
@ -48,20 +48,18 @@ export class AutomationService {
|
|||||||
|
|
||||||
async addAutomation(addAutomationDto: AddAutomationDto, spaceTuyaId = null) {
|
async addAutomation(addAutomationDto: AddAutomationDto, spaceTuyaId = null) {
|
||||||
try {
|
try {
|
||||||
let unitSpaceTuyaId;
|
let tuyaSpaceId;
|
||||||
if (!spaceTuyaId) {
|
if (!spaceTuyaId) {
|
||||||
const unitDetails = await this.getUnitByUuid(
|
const space = await this.getSpaceByUuid(addAutomationDto.spaceUuid);
|
||||||
addAutomationDto.spaceUuid,
|
|
||||||
);
|
|
||||||
|
|
||||||
unitSpaceTuyaId = unitDetails.spaceTuyaUuid;
|
tuyaSpaceId = space.spaceTuyaUuid;
|
||||||
if (!unitDetails) {
|
if (!space) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
`Invalid space UUID ${addAutomationDto.spaceUuid}`,
|
`Invalid space UUID ${addAutomationDto.spaceUuid}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unitSpaceTuyaId = spaceTuyaId;
|
tuyaSpaceId = spaceTuyaId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const actions = addAutomationDto.actions.map((action) =>
|
const actions = addAutomationDto.actions.map((action) =>
|
||||||
@ -100,7 +98,7 @@ export class AutomationService {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
path,
|
path,
|
||||||
body: {
|
body: {
|
||||||
space_id: unitSpaceTuyaId,
|
space_id: tuyaSpaceId,
|
||||||
name: addAutomationDto.automationName,
|
name: addAutomationDto.automationName,
|
||||||
effective_time: {
|
effective_time: {
|
||||||
...addAutomationDto.effectiveTime,
|
...addAutomationDto.effectiveTime,
|
||||||
@ -129,7 +127,7 @@ export class AutomationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async getUnitByUuid(spaceUuid: string) {
|
async getSpaceByUuid(spaceUuid: string) {
|
||||||
try {
|
try {
|
||||||
const space = await this.spaceRepository.findOne({
|
const space = await this.spaceRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
@ -151,19 +149,19 @@ export class AutomationService {
|
|||||||
if (err instanceof BadRequestException) {
|
if (err instanceof BadRequestException) {
|
||||||
throw err; // Re-throw BadRequestException
|
throw err; // Re-throw BadRequestException
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException('Unit not found', HttpStatus.NOT_FOUND);
|
throw new HttpException('Space not found', HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async getAutomationByUnit(spaceUuid: string) {
|
async getAutomationBySpace(spaceUuid: string) {
|
||||||
try {
|
try {
|
||||||
const unit = await this.getUnitByUuid(spaceUuid);
|
const space = await this.getSpaceByUuid(spaceUuid);
|
||||||
if (!unit.spaceTuyaUuid) {
|
if (!space.spaceTuyaUuid) {
|
||||||
throw new BadRequestException(`Invalid space UUID ${spaceUuid}`);
|
throw new BadRequestException(`Invalid space UUID ${spaceUuid}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = `/v2.0/cloud/scene/rule?space_id=${unit.spaceTuyaUuid}&type=automation`;
|
const path = `/v2.0/cloud/scene/rule?space_id=${space.spaceTuyaUuid}&type=automation`;
|
||||||
const response: GetAutomationByUnitInterface = await this.tuya.request({
|
const response: GetAutomationBySpaceInterface = await this.tuya.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path,
|
path,
|
||||||
});
|
});
|
||||||
@ -314,18 +312,18 @@ export class AutomationService {
|
|||||||
async deleteAutomation(param: DeleteAutomationParamDto, spaceTuyaId = null) {
|
async deleteAutomation(param: DeleteAutomationParamDto, spaceTuyaId = null) {
|
||||||
try {
|
try {
|
||||||
const { automationUuid, spaceUuid } = param;
|
const { automationUuid, spaceUuid } = param;
|
||||||
let unitSpaceTuyaId;
|
let tuyaSpaceId;
|
||||||
if (!spaceTuyaId) {
|
if (!spaceTuyaId) {
|
||||||
const space = await this.getUnitByUuid(spaceUuid);
|
const space = await this.getSpaceByUuid(spaceUuid);
|
||||||
unitSpaceTuyaId = space.spaceTuyaUuid;
|
tuyaSpaceId = space.spaceTuyaUuid;
|
||||||
if (!unitSpaceTuyaId) {
|
if (!tuyaSpaceId) {
|
||||||
throw new BadRequestException(`Invalid space UUID ${spaceUuid}`);
|
throw new BadRequestException(`Invalid space UUID ${spaceUuid}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unitSpaceTuyaId = spaceTuyaId;
|
tuyaSpaceId = spaceTuyaId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = `/v2.0/cloud/scene/rule?ids=${automationUuid}&space_id=${unitSpaceTuyaId}`;
|
const path = `/v2.0/cloud/scene/rule?ids=${automationUuid}&space_id=${tuyaSpaceId}`;
|
||||||
const response: DeleteAutomationInterface = await this.tuya.request({
|
const response: DeleteAutomationInterface = await this.tuya.request({
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
path,
|
path,
|
||||||
@ -392,7 +390,7 @@ export class AutomationService {
|
|||||||
automationUuid: string,
|
automationUuid: string,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const space = await this.getUnitByUuid(
|
const space = await this.getSpaceByUuid(
|
||||||
updateAutomationStatusDto.spaceUuid,
|
updateAutomationStatusDto.spaceUuid,
|
||||||
);
|
);
|
||||||
if (!space.spaceTuyaUuid) {
|
if (!space.spaceTuyaUuid) {
|
||||||
|
Reference in New Issue
Block a user