mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 10:24:53 +00:00
Add space DTO, entity, repository, and module
This commit is contained in:
1
libs/common/src/modules/space/dtos/index.ts
Normal file
1
libs/common/src/modules/space/dtos/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './space.dto';
|
||||||
19
libs/common/src/modules/space/dtos/space.dto.ts
Normal file
19
libs/common/src/modules/space/dtos/space.dto.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { IsNotEmpty, IsString } from 'class-validator';
|
||||||
|
|
||||||
|
export class SpaceDto {
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public uuid: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public parentUuid: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public spaceName: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public spaceTypeUuid: string;
|
||||||
|
}
|
||||||
1
libs/common/src/modules/space/entities/index.ts
Normal file
1
libs/common/src/modules/space/entities/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './space.entity';
|
||||||
36
libs/common/src/modules/space/entities/space.entity.ts
Normal file
36
libs/common/src/modules/space/entities/space.entity.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
|
||||||
|
import { SpaceDto } from '../dtos';
|
||||||
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
|
import { SpaceTypeEntity } from '../../space-type/entities';
|
||||||
|
|
||||||
|
@Entity({ name: 'space' })
|
||||||
|
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||||
|
@Column({
|
||||||
|
type: 'uuid',
|
||||||
|
default: () => 'gen_random_uuid()', // Use gen_random_uuid() for default value
|
||||||
|
nullable: false,
|
||||||
|
})
|
||||||
|
public uuid: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: false,
|
||||||
|
})
|
||||||
|
parentUuid: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: false,
|
||||||
|
})
|
||||||
|
public spaceName: string;
|
||||||
|
@ManyToOne(() => SpaceEntity, (space) => space.children, { nullable: true })
|
||||||
|
parent: SpaceEntity;
|
||||||
|
|
||||||
|
@OneToMany(() => SpaceEntity, (space) => space.parent)
|
||||||
|
children: SpaceEntity[];
|
||||||
|
@ManyToOne(() => SpaceTypeEntity, (spaceType) => spaceType.spaces)
|
||||||
|
spaceType: SpaceTypeEntity;
|
||||||
|
|
||||||
|
constructor(partial: Partial<SpaceEntity>) {
|
||||||
|
super();
|
||||||
|
Object.assign(this, partial);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
libs/common/src/modules/space/repositories/index.ts
Normal file
1
libs/common/src/modules/space/repositories/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './space.repository';
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
import { DataSource, Repository } from 'typeorm';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { SpaceEntity } from '../entities/space.entity';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class SpaceRepository extends Repository<SpaceEntity> {
|
||||||
|
constructor(private dataSource: DataSource) {
|
||||||
|
super(SpaceEntity, dataSource.createEntityManager());
|
||||||
|
}
|
||||||
|
}
|
||||||
11
libs/common/src/modules/space/space.repository.module.ts
Normal file
11
libs/common/src/modules/space/space.repository.module.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { SpaceEntity } from './entities/space.entity';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
providers: [],
|
||||||
|
exports: [],
|
||||||
|
controllers: [],
|
||||||
|
imports: [TypeOrmModule.forFeature([SpaceEntity])],
|
||||||
|
})
|
||||||
|
export class SpaceRepositoryModule {}
|
||||||
Reference in New Issue
Block a user