mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
community controller
This commit is contained in:
19
libs/common/src/modules/community/dtos/community.dto.ts
Normal file
19
libs/common/src/modules/community/dtos/community.dto.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';
|
||||
|
||||
export class CommunityDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public name: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
public description?: string;
|
||||
|
||||
@IsUUID()
|
||||
@IsNotEmpty()
|
||||
public regionId: string;
|
||||
}
|
1
libs/common/src/modules/community/dtos/index.ts
Normal file
1
libs/common/src/modules/community/dtos/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './community.dto';
|
@ -0,0 +1,38 @@
|
||||
import { Column, Entity, ManyToOne, OneToMany, Unique } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { CommunityDto } from '../dtos';
|
||||
import { RegionEntity } from '../../region/entities';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { RoleEntity } from '../../role/entities';
|
||||
|
||||
@Entity({ name: 'community' })
|
||||
@Unique(['name'])
|
||||
export class CommunityEntity extends AbstractEntity<CommunityDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column({
|
||||
length: 255,
|
||||
nullable: false,
|
||||
})
|
||||
name: string;
|
||||
|
||||
@Column({ length: 255, nullable: true })
|
||||
description: string;
|
||||
|
||||
@ManyToOne(() => RegionEntity, (region) => region.communities, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
region: RegionEntity;
|
||||
|
||||
@OneToMany(() => SpaceEntity, (space) => space.community)
|
||||
spaces: SpaceEntity[];
|
||||
|
||||
@OneToMany(() => RoleEntity, (role) => role.community)
|
||||
roles: RoleEntity[];
|
||||
}
|
1
libs/common/src/modules/community/entities/index.ts
Normal file
1
libs/common/src/modules/community/entities/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './community.entity';
|
@ -0,0 +1,10 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CommunityEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class CommunityRepository extends Repository<CommunityEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(CommunityEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
1
libs/common/src/modules/community/repositories/index.ts
Normal file
1
libs/common/src/modules/community/repositories/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './community.repository';
|
Reference in New Issue
Block a user