mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
Merge branch 'dev' of https://github.com/SyncrowIOT/backend into feature/space-management
This commit is contained in:
@ -0,0 +1,43 @@
|
||||
import { SourceType } from '@app/common/constants/source-type.enum';
|
||||
import { Entity, Column, PrimaryColumn, Unique } from 'typeorm';
|
||||
|
||||
@Entity('device-status-log')
|
||||
@Unique('event_time_idx', ['eventTime'])
|
||||
export class DeviceStatusLogEntity {
|
||||
@Column({ type: 'int', generated: true, unsigned: true })
|
||||
id: number;
|
||||
|
||||
@Column({ type: 'text' })
|
||||
eventId: string;
|
||||
|
||||
@PrimaryColumn({ type: 'timestamptz' })
|
||||
eventTime: Date;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: SourceType,
|
||||
default: SourceType.Device,
|
||||
})
|
||||
eventFrom: SourceType;
|
||||
|
||||
@Column({ type: 'text' })
|
||||
deviceId: string;
|
||||
|
||||
@Column({ type: 'text' })
|
||||
deviceTuyaId: string;
|
||||
|
||||
@Column({ type: 'text' })
|
||||
productId: string;
|
||||
|
||||
@Column({ type: 'text' })
|
||||
code: any;
|
||||
|
||||
@Column({ type: 'text' })
|
||||
value: any;
|
||||
|
||||
@Column({ type: 'jsonb' })
|
||||
log: any;
|
||||
|
||||
@Column({ type: 'timestamptz', default: new Date() })
|
||||
ingestionTime: Date;
|
||||
}
|
@ -0,0 +1 @@
|
||||
export * from './device-status-log.entity';
|
@ -0,0 +1,10 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DeviceStatusLogEntity } from '../entities/device-status-log.entity';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceStatusLogRepository extends Repository<DeviceStatusLogEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(DeviceStatusLogEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
export * from './device-status.repository';
|
1
libs/common/src/modules/scene/dtos/index.ts
Normal file
1
libs/common/src/modules/scene/dtos/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './scene.dto';
|
30
libs/common/src/modules/scene/dtos/scene.dto.ts
Normal file
30
libs/common/src/modules/scene/dtos/scene.dto.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { IsBoolean, IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class SceneDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public sceneTuyaUuid: string;
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public unitUuid: string;
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public iconUuid: string;
|
||||
|
||||
@IsBoolean()
|
||||
@IsNotEmpty()
|
||||
public inHomePage: boolean;
|
||||
}
|
||||
export class SceneIconDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public icon: string;
|
||||
}
|
1
libs/common/src/modules/scene/entities/index.ts
Normal file
1
libs/common/src/modules/scene/entities/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './scene.entity';
|
65
libs/common/src/modules/scene/entities/scene.entity.ts
Normal file
65
libs/common/src/modules/scene/entities/scene.entity.ts
Normal file
@ -0,0 +1,65 @@
|
||||
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
|
||||
import { SceneDto, SceneIconDto } from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SceneIconType } from '@app/common/constants/secne-icon-type.enum';
|
||||
|
||||
// Define SceneIconEntity before SceneEntity
|
||||
@Entity({ name: 'scene-icon' })
|
||||
export class SceneIconEntity extends AbstractEntity<SceneIconDto> {
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: 'text',
|
||||
})
|
||||
public icon: string;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: SceneIconType,
|
||||
default: SceneIconType.Other,
|
||||
})
|
||||
iconType: SceneIconType;
|
||||
|
||||
@OneToMany(
|
||||
() => SceneEntity,
|
||||
(scenesIconEntity) => scenesIconEntity.sceneIcon,
|
||||
)
|
||||
scenesIconEntity: SceneEntity[];
|
||||
|
||||
constructor(partial: Partial<SceneIconEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity({ name: 'scene' })
|
||||
export class SceneEntity extends AbstractEntity<SceneDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
sceneTuyaUuid: string;
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
unitUuid: string;
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
showInHomePage: boolean;
|
||||
|
||||
@ManyToOne(() => SceneIconEntity, (icon) => icon.scenesIconEntity, {
|
||||
nullable: false,
|
||||
})
|
||||
sceneIcon: SceneIconEntity;
|
||||
|
||||
constructor(partial: Partial<SceneEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
1
libs/common/src/modules/scene/repositories/index.ts
Normal file
1
libs/common/src/modules/scene/repositories/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './scene.repository';
|
@ -0,0 +1,17 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { SceneEntity, SceneIconEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class SceneRepository extends Repository<SceneEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(SceneEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class SceneIconRepository extends Repository<SceneIconEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(SceneIconEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
11
libs/common/src/modules/scene/scene.repository.module.ts
Normal file
11
libs/common/src/modules/scene/scene.repository.module.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { SceneEntity, SceneIconEntity } from './entities';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([SceneEntity, SceneIconEntity])],
|
||||
})
|
||||
export class SceneRepositoryModule {}
|
Reference in New Issue
Block a user