mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-17 03:05:13 +00:00
Add Automation Module and Entity
This commit is contained in:
@ -37,6 +37,7 @@ import {
|
||||
InviteUserSpaceEntity,
|
||||
} from '../modules/Invite-user/entities';
|
||||
import { InviteSpaceEntity } from '../modules/space/entities/invite-space.entity';
|
||||
import { AutomationEntity } from '../modules/automation/entities';
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forRootAsync({
|
||||
@ -82,6 +83,7 @@ import { InviteSpaceEntity } from '../modules/space/entities/invite-space.entity
|
||||
InviteUserEntity,
|
||||
InviteUserSpaceEntity,
|
||||
InviteSpaceEntity,
|
||||
AutomationEntity,
|
||||
],
|
||||
namingStrategy: new SnakeNamingStrategy(),
|
||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
||||
|
@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AutomationEntity } from './entities';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([AutomationEntity])],
|
||||
})
|
||||
export class AutomationRepositoryModule {}
|
14
libs/common/src/modules/automation/dtos/automation.dto.ts
Normal file
14
libs/common/src/modules/automation/dtos/automation.dto.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class AutomationDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public automationTuyaUuid: string;
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public spaceUuid: string;
|
||||
}
|
1
libs/common/src/modules/automation/dtos/index.ts
Normal file
1
libs/common/src/modules/automation/dtos/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './automation.dto';
|
@ -0,0 +1,37 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
|
||||
import { AutomationDto } from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
|
||||
@Entity({ name: 'automation' })
|
||||
export class AutomationEntity extends AbstractEntity<AutomationDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
automationTuyaUuid: string;
|
||||
|
||||
@ManyToOne(() => SpaceEntity, (space) => space.scenes, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
@JoinColumn({ name: 'space_uuid' })
|
||||
space: SpaceEntity;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: false,
|
||||
})
|
||||
public disabled: boolean;
|
||||
|
||||
constructor(partial: Partial<AutomationEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
1
libs/common/src/modules/automation/entities/index.ts
Normal file
1
libs/common/src/modules/automation/entities/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './automation.entity';
|
@ -0,0 +1,10 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { AutomationEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class AutomationRepository extends Repository<AutomationEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(AutomationEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user