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