mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-13 17:37:38 +00:00
refactor: rename presence sensor entities and update related references
This commit is contained in:
@ -51,7 +51,10 @@ import {
|
||||
PowerClampHourlyEntity,
|
||||
PowerClampMonthlyEntity,
|
||||
} from '../modules/power-clamp/entities/power-clamp.entity';
|
||||
import { PresenceSensorDailyEntity } from '../modules/presence-sensor/entities';
|
||||
import {
|
||||
PresenceSensorDailyDeviceEntity,
|
||||
PresenceSensorDailySpaceEntity,
|
||||
} from '../modules/presence-sensor/entities';
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forRootAsync({
|
||||
@ -110,7 +113,8 @@ import { PresenceSensorDailyEntity } from '../modules/presence-sensor/entities';
|
||||
PowerClampHourlyEntity,
|
||||
PowerClampDailyEntity,
|
||||
PowerClampMonthlyEntity,
|
||||
PresenceSensorDailyEntity,
|
||||
PresenceSensorDailyDeviceEntity,
|
||||
PresenceSensorDailySpaceEntity,
|
||||
],
|
||||
namingStrategy: new SnakeNamingStrategy(),
|
||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
||||
|
@ -18,7 +18,7 @@ import { SpaceEntity } from '../../space/entities/space.entity';
|
||||
import { SubspaceEntity } from '../../space/entities/subspace/subspace.entity';
|
||||
import { NewTagEntity } from '../../tag';
|
||||
import { PowerClampHourlyEntity } from '../../power-clamp/entities/power-clamp.entity';
|
||||
import { PresenceSensorDailyEntity } from '../../presence-sensor/entities';
|
||||
import { PresenceSensorDailyDeviceEntity } from '../../presence-sensor/entities';
|
||||
|
||||
@Entity({ name: 'device' })
|
||||
@Unique(['deviceTuyaUuid'])
|
||||
@ -83,8 +83,8 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
||||
public tag: NewTagEntity;
|
||||
@OneToMany(() => PowerClampHourlyEntity, (powerClamp) => powerClamp.device)
|
||||
powerClampHourly: PowerClampHourlyEntity[];
|
||||
@OneToMany(() => PresenceSensorDailyEntity, (sensor) => sensor.device)
|
||||
presenceSensorDaily: PresenceSensorDailyEntity[];
|
||||
@OneToMany(() => PresenceSensorDailyDeviceEntity, (sensor) => sensor.device)
|
||||
presenceSensorDaily: PresenceSensorDailyDeviceEntity[];
|
||||
constructor(partial: Partial<DeviceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
@ -2,10 +2,11 @@ import { Column, Entity, ManyToOne, Unique } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { PresenceSensorDto } from '../dtos';
|
||||
import { DeviceEntity } from '../../device/entities/device.entity';
|
||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||
|
||||
@Entity({ name: 'presence-sensor-daily-detection' })
|
||||
@Entity({ name: 'presence-sensor-daily-device-detection' })
|
||||
@Unique(['deviceUuid', 'eventDate'])
|
||||
export class PresenceSensorDailyEntity extends AbstractEntity<PresenceSensorDto> {
|
||||
export class PresenceSensorDailyDeviceEntity extends AbstractEntity<PresenceSensorDto> {
|
||||
@Column({ nullable: false })
|
||||
public deviceUuid: string;
|
||||
|
||||
@ -24,7 +25,33 @@ export class PresenceSensorDailyEntity extends AbstractEntity<PresenceSensorDto>
|
||||
@ManyToOne(() => DeviceEntity, (device) => device.presenceSensorDaily)
|
||||
device: DeviceEntity;
|
||||
|
||||
constructor(partial: Partial<PresenceSensorDailyEntity>) {
|
||||
constructor(partial: Partial<PresenceSensorDailyDeviceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
@Entity({ name: 'presence-sensor-daily-space-detection' })
|
||||
@Unique(['spaceUuid', 'eventDate'])
|
||||
export class PresenceSensorDailySpaceEntity extends AbstractEntity<PresenceSensorDto> {
|
||||
@Column({ nullable: false })
|
||||
public spaceUuid: string;
|
||||
|
||||
@Column({ nullable: false, type: 'date' })
|
||||
public eventDate: string;
|
||||
|
||||
@Column({ nullable: false })
|
||||
public CountMotionDetected: number;
|
||||
|
||||
@Column({ nullable: false })
|
||||
public CountPresenceDetected: number;
|
||||
|
||||
@Column({ nullable: false })
|
||||
public CountTotalPresenceDetected: number;
|
||||
|
||||
@ManyToOne(() => SpaceEntity, (space) => space.presenceSensorDaily)
|
||||
space: SpaceEntity;
|
||||
|
||||
constructor(partial: Partial<PresenceSensorDailySpaceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
|
@ -1,11 +1,19 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { PresenceSensorDailyEntity } from './entities/presence-sensor.entity';
|
||||
import {
|
||||
PresenceSensorDailyDeviceEntity,
|
||||
PresenceSensorDailySpaceEntity,
|
||||
} from './entities/presence-sensor.entity';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([PresenceSensorDailyEntity])],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([
|
||||
PresenceSensorDailyDeviceEntity,
|
||||
PresenceSensorDailySpaceEntity,
|
||||
]),
|
||||
],
|
||||
})
|
||||
export class PresenceSensorRepositoryModule {}
|
||||
|
@ -1,10 +1,19 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PresenceSensorDailyEntity } from '../entities';
|
||||
import {
|
||||
PresenceSensorDailyDeviceEntity,
|
||||
PresenceSensorDailySpaceEntity,
|
||||
} from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class PresenceSensorDailyRepository extends Repository<PresenceSensorDailyEntity> {
|
||||
export class PresenceSensorDailyDeviceRepository extends Repository<PresenceSensorDailyDeviceEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(PresenceSensorDailyEntity, dataSource.createEntityManager());
|
||||
super(PresenceSensorDailyDeviceEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@Injectable()
|
||||
export class PresenceSensorDailySpaceRepository extends Repository<PresenceSensorDailySpaceEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(PresenceSensorDailySpaceEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import { SpaceModelEntity } from '../../space-model';
|
||||
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
||||
import { SpaceProductAllocationEntity } from './space-product-allocation.entity';
|
||||
import { SubspaceEntity } from './subspace/subspace.entity';
|
||||
import { PresenceSensorDailySpaceEntity } from '../../presence-sensor/entities';
|
||||
|
||||
@Entity({ name: 'space' })
|
||||
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||
@ -111,6 +112,9 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||
)
|
||||
public productAllocations: SpaceProductAllocationEntity[];
|
||||
|
||||
@OneToMany(() => PresenceSensorDailySpaceEntity, (sensor) => sensor.space)
|
||||
presenceSensorDaily: PresenceSensorDailySpaceEntity[];
|
||||
|
||||
constructor(partial: Partial<SpaceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
@ -94,7 +94,7 @@ daily_aggregates AS (
|
||||
GROUP BY device_id, event_date
|
||||
)
|
||||
|
||||
INSERT INTO public."presence-sensor-daily-detection" (
|
||||
INSERT INTO public."presence-sensor-daily-device-detection" (
|
||||
device_uuid,
|
||||
event_date,
|
||||
count_motion_detected,
|
||||
|
@ -11,7 +11,7 @@ WITH params AS (
|
||||
A.count_motion_detected,
|
||||
A.count_presence_detected,
|
||||
A.count_total_presence_detected
|
||||
FROM public."presence-sensor-daily-detection" AS A
|
||||
FROM public."presence-sensor-daily-device-detection" AS A
|
||||
JOIN params P ON TRUE
|
||||
WHERE A.device_uuid::text = ANY(P.device_ids)
|
||||
AND (P.month IS NULL
|
||||
|
@ -85,7 +85,7 @@ daily_aggregate AS (
|
||||
GROUP BY device_id, event_date
|
||||
)
|
||||
|
||||
INSERT INTO public."presence-sensor-daily-detection" (
|
||||
INSERT INTO public."presence-sensor-daily-device-detection" (
|
||||
device_uuid,
|
||||
event_date,
|
||||
count_motion_detected,
|
||||
|
Reference in New Issue
Block a user