mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
Add region module
This commit is contained in:
1
libs/common/src/modules/region/dtos/index.ts
Normal file
1
libs/common/src/modules/region/dtos/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './region.dto';
|
11
libs/common/src/modules/region/dtos/region.dto.ts
Normal file
11
libs/common/src/modules/region/dtos/region.dto.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class RegionDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public regionName: string;
|
||||
}
|
1
libs/common/src/modules/region/entities/index.ts
Normal file
1
libs/common/src/modules/region/entities/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './region.entity';
|
20
libs/common/src/modules/region/entities/region.entity.ts
Normal file
20
libs/common/src/modules/region/entities/region.entity.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { Column, Entity, OneToMany } from 'typeorm';
|
||||
import { RegionDto } from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
|
||||
@Entity({ name: 'region' })
|
||||
export class RegionEntity extends AbstractEntity<RegionDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
regionName: string;
|
||||
|
||||
@OneToMany(() => UserEntity, (user) => user.region)
|
||||
users: UserEntity[];
|
||||
|
||||
constructor(partial: Partial<RegionEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
11
libs/common/src/modules/region/region.repository.module.ts
Normal file
11
libs/common/src/modules/region/region.repository.module.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { RegionEntity } from './entities/region.entity';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([RegionEntity])],
|
||||
})
|
||||
export class RegionRepositoryModule {}
|
1
libs/common/src/modules/region/repositories/index.ts
Normal file
1
libs/common/src/modules/region/repositories/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './region.repository';
|
@ -0,0 +1,10 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { RegionEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class RegionRepository extends Repository<RegionEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(RegionEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user