feat: add endpoint product detail
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { HttpException, HttpStatus } from '@nestjs/common';
|
||||
import { EntityNotFoundError, IsNull, Repository } from 'typeorm';
|
||||
import { EntityNotFoundError, Repository } from 'typeorm';
|
||||
import { Product } from './entities/product.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { CreateProductDto } from './dto/product/create-product.dto';
|
||||
@@ -357,6 +357,29 @@ export class ProductService {
|
||||
}
|
||||
}
|
||||
|
||||
async findOneById(id: string) {
|
||||
try {
|
||||
return await this.productRepository.findOneOrFail({
|
||||
relations: ['supplier'],
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Product not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async update(id: string, updateProductDto: UpdateProductDto) {
|
||||
try {
|
||||
await this.productRepository.findOneOrFail(id);
|
||||
|
||||
Reference in New Issue
Block a user