import { Injectable, NotFoundException } from '@nestjs/common'; import { InjectModel } from '@nestjs/sequelize'; import { Product } from '../shop/entities/product.entity'; import { CreateProductDto } from './dto/create-product.dto'; import { UpdateProductDto } from './dto/update-product.dto'; @Injectable() export class ProductsService { constructor( @InjectModel(Product) private readonly productModel: typeof Product, ) {} async create(createProductDto: CreateProductDto) { return this.productModel.create(createProductDto); } async findAll() { return this.productModel.findAll(); } async findOne(id: number) { const product = await this.productModel.findByPk(id); if (!product) { throw new NotFoundException(`Product with ID ${id} not found`); } return product; } async update(id: number, updateProductDto: UpdateProductDto) { const product = await this.findOne(id); await product.update(updateProductDto); return product; } async remove(id: number) { const product = await this.findOne(id); await product.destroy(); return { message: 'Product deleted successfully' }; } }