Merge branch 'dev' of https://github.com/SyncrowIOT/backend into feature/space-management

This commit is contained in:
hannathkadher
2024-10-30 23:08:51 +04:00
35 changed files with 611 additions and 42 deletions

View File

@ -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;
}

View File

@ -0,0 +1 @@
export * from './device-status-log.entity';

View File

@ -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());
}
}

View File

@ -0,0 +1 @@
export * from './device-status.repository';

View File

@ -0,0 +1 @@
export * from './scene.dto';

View 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;
}

View File

@ -0,0 +1 @@
export * from './scene.entity';

View 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);
}
}

View File

@ -0,0 +1 @@
export * from './scene.repository';

View File

@ -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());
}
}

View 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 {}