community controller

This commit is contained in:
hannathkadher
2024-10-15 11:01:56 +04:00
parent a157444897
commit 2292c01220
23 changed files with 822 additions and 259 deletions

View 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;
}

View File

@ -0,0 +1 @@
export * from './community.dto';

View File

@ -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[];
}

View File

@ -0,0 +1 @@
export * from './community.entity';

View File

@ -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());
}
}

View File

@ -0,0 +1 @@
export * from './community.repository';