Merge branch 'development' into 'devops-staging'
fix: add code in categories and subcategories See merge request empatnusabangsa/ppob/ppob-backend!30
This commit is contained in:
commit
b85f0843ad
|
@ -3,4 +3,7 @@ import { IsNotEmpty, IsUUID } from 'class-validator';
|
||||||
export class CreateCategoriesProductDto {
|
export class CreateCategoriesProductDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
code: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,9 @@ export class CreateSubCategoriesProductDto extends CreateCategoriesProductDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
code: string;
|
||||||
|
|
||||||
@IsUUID()
|
@IsUUID()
|
||||||
categoryId: string;
|
categoryId: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,9 @@ export class ProductCategories extends BaseModel {
|
||||||
@Column()
|
@Column()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
code: string;
|
||||||
|
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
() => ProductSubCategories,
|
() => ProductSubCategories,
|
||||||
(subCategories) => subCategories.category,
|
(subCategories) => subCategories.category,
|
||||||
|
|
|
@ -17,6 +17,9 @@ export class ProductSubCategories extends BaseModel {
|
||||||
@Column()
|
@Column()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
code: string;
|
||||||
|
|
||||||
@ManyToOne(() => ProductCategories, (categories) => categories.sub_categories)
|
@ManyToOne(() => ProductCategories, (categories) => categories.sub_categories)
|
||||||
category: ProductCategories;
|
category: ProductCategories;
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,20 @@ export class ProductCategoriesService {
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async create(CreateCategoriesProductDto: CreateCategoriesProductDto) {
|
async create(CreateCategoriesProductDto: CreateCategoriesProductDto) {
|
||||||
|
const check = await this.productCategoriesRepository.findOne({
|
||||||
|
code: CreateCategoriesProductDto.code,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (check) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_ACCEPTABLE,
|
||||||
|
error: 'Category Already Exist',
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const result = await this.productCategoriesRepository.insert(
|
const result = await this.productCategoriesRepository.insert(
|
||||||
CreateCategoriesProductDto,
|
CreateCategoriesProductDto,
|
||||||
);
|
);
|
||||||
|
@ -50,6 +64,28 @@ export class ProductCategoriesService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findByCode(code: string) {
|
||||||
|
try {
|
||||||
|
return await this.productCategoriesRepository.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
code: code,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
|
error: 'Data not found',
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async update(
|
async update(
|
||||||
id: string,
|
id: string,
|
||||||
updateCategoriesProductDto: UpdateCategoriesProductDto,
|
updateCategoriesProductDto: UpdateCategoriesProductDto,
|
||||||
|
|
|
@ -15,12 +15,27 @@ export class ProductSubCategoriesService {
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async create(createSubCategoriesProductDto: CreateSubCategoriesProductDto) {
|
async create(createSubCategoriesProductDto: CreateSubCategoriesProductDto) {
|
||||||
|
const check = await this.productSubCategoriesRepository.findOne({
|
||||||
|
code: createSubCategoriesProductDto.code,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (check) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_ACCEPTABLE,
|
||||||
|
error: 'Sub Category Already Exist',
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const categories = await this.productCategoriesService.findOne(
|
const categories = await this.productCategoriesService.findOne(
|
||||||
createSubCategoriesProductDto.categoryId,
|
createSubCategoriesProductDto.categoryId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const result = await this.productSubCategoriesRepository.insert({
|
const result = await this.productSubCategoriesRepository.insert({
|
||||||
name: createSubCategoriesProductDto.name,
|
name: createSubCategoriesProductDto.name,
|
||||||
|
code: createSubCategoriesProductDto.code,
|
||||||
category: categories,
|
category: categories,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user