mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-12 16:27:34 +00:00
create home entity
This commit is contained in:
@ -5,6 +5,7 @@ import { SnakeNamingStrategy } from './strategies';
|
||||
import { UserEntity } from '../modules/user/entities/user.entity';
|
||||
import { UserSessionEntity } from '../modules/session/entities/session.entity';
|
||||
import { UserOtpEntity } from '../modules/user-otp/entities';
|
||||
import { HomeEntity } from '../modules/home/entities';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@ -19,7 +20,7 @@ import { UserOtpEntity } from '../modules/user-otp/entities';
|
||||
username: configService.get('DB_USER'),
|
||||
password: configService.get('DB_PASSWORD'),
|
||||
database: configService.get('DB_NAME'),
|
||||
entities: [UserEntity, UserSessionEntity, UserOtpEntity],
|
||||
entities: [UserEntity, UserSessionEntity, UserOtpEntity, HomeEntity],
|
||||
namingStrategy: new SnakeNamingStrategy(),
|
||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
||||
logging: true,
|
||||
|
15
libs/common/src/modules/home/dtos/home.dto.ts
Normal file
15
libs/common/src/modules/home/dtos/home.dto.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class HomeDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public homeId: string;
|
||||
}
|
1
libs/common/src/modules/home/dtos/index.ts
Normal file
1
libs/common/src/modules/home/dtos/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './home.dto';
|
29
libs/common/src/modules/home/entities/home.entity.ts
Normal file
29
libs/common/src/modules/home/entities/home.entity.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { HomeDto } from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
|
||||
@Entity({ name: 'home' })
|
||||
export class HomeEntity extends AbstractEntity<HomeDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()', // Use gen_random_uuid() for default value
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
userUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
unique: true,
|
||||
})
|
||||
public homeId: string;
|
||||
|
||||
constructor(partial: Partial<HomeEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
1
libs/common/src/modules/home/entities/index.ts
Normal file
1
libs/common/src/modules/home/entities/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './home.entity';
|
11
libs/common/src/modules/home/home.repository.module.ts
Normal file
11
libs/common/src/modules/home/home.repository.module.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { HomeEntity } from './entities/home.entity';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([HomeEntity])],
|
||||
})
|
||||
export class HomeRepositoryModule {}
|
10
libs/common/src/modules/home/repositories/home.repository.ts
Normal file
10
libs/common/src/modules/home/repositories/home.repository.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { HomeEntity } from '../entities/home.entity';
|
||||
|
||||
@Injectable()
|
||||
export class HomeRepository extends Repository<HomeEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(HomeEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
1
libs/common/src/modules/home/repositories/index.ts
Normal file
1
libs/common/src/modules/home/repositories/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './home.repository';
|
Reference in New Issue
Block a user