import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { DeleteResult, Repository, UpdateResult } from 'typeorm'; import { CreateProductDto } from './dto/create-product.dto'; import { UpdateProductDto } from './dto/update-product.dto'; import { Product } from './entities/product.entity'; @Injectable() export class ProductsService { constructor( @InjectRepository(Product) private readonly productsRepository: Repository, ) {} async create(createProductDto: CreateProductDto): Promise { return await this.productsRepository.save(createProductDto); } async findAll(): Promise { return await this.productsRepository.find(); } async findOne(id: string): Promise { return await this.productsRepository.findOne(id); } async update( id: string, updateProductDto: UpdateProductDto, ): Promise { return await this.productsRepository.update(id, updateProductDto); } async remove(id: string): Promise { return await this.productsRepository.softDelete(id); } async checkIfProductsExist(productIds: string[]): Promise { return await this.productsRepository.findByIds(productIds); } }