Add product DTO, entity, repository, and module

This commit is contained in:
faris Aljohari
2024-03-25 13:36:00 +03:00
parent 4d6c4ed787
commit 22bcd37de7
7 changed files with 70 additions and 0 deletions

View File

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

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

View File

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

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

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

View File

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

View File

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