mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 21:44:54 +00:00
Add product DTO, entity, repository, and module
This commit is contained in:
1
libs/common/src/modules/product/dtos/index.ts
Normal file
1
libs/common/src/modules/product/dtos/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './product.dto';
|
||||||
19
libs/common/src/modules/product/dtos/product.dto.ts
Normal file
19
libs/common/src/modules/product/dtos/product.dto.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { IsNotEmpty, IsString } from 'class-validator';
|
||||||
|
|
||||||
|
export class ProductDto {
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public uuid: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public catName: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public prodId: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public prodType: string;
|
||||||
|
}
|
||||||
1
libs/common/src/modules/product/entities/index.ts
Normal file
1
libs/common/src/modules/product/entities/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './product.entity';
|
||||||
27
libs/common/src/modules/product/entities/product.entity.ts
Normal file
27
libs/common/src/modules/product/entities/product.entity.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { Column, Entity } from 'typeorm';
|
||||||
|
import { ProductDto } from '../dtos';
|
||||||
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
|
|
||||||
|
@Entity({ name: 'product' })
|
||||||
|
export class ProductEntity extends AbstractEntity<ProductDto> {
|
||||||
|
@Column({
|
||||||
|
nullable: false,
|
||||||
|
})
|
||||||
|
catName: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: false,
|
||||||
|
unique: true,
|
||||||
|
})
|
||||||
|
public prodId: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: false,
|
||||||
|
})
|
||||||
|
public prodType: string;
|
||||||
|
|
||||||
|
constructor(partial: Partial<ProductEntity>) {
|
||||||
|
super();
|
||||||
|
Object.assign(this, partial);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
libs/common/src/modules/product/product.repository.module.ts
Normal file
11
libs/common/src/modules/product/product.repository.module.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { ProductEntity } from './entities/product.entity';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
providers: [],
|
||||||
|
exports: [],
|
||||||
|
controllers: [],
|
||||||
|
imports: [TypeOrmModule.forFeature([ProductEntity])],
|
||||||
|
})
|
||||||
|
export class ProductRepositoryModule {}
|
||||||
1
libs/common/src/modules/product/repositories/index.ts
Normal file
1
libs/common/src/modules/product/repositories/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './product.repository';
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
import { DataSource, Repository } from 'typeorm';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { ProductEntity } from '../entities/product.entity';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ProductRepository extends Repository<ProductEntity> {
|
||||||
|
constructor(private dataSource: DataSource) {
|
||||||
|
super(ProductEntity, dataSource.createEntityManager());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user