import { Inject, Injectable } from '@nestjs/common'; import { CreateReceiptDto, UpdateReceiptDto } from './dto'; import { RECEIPT_REPOSITORY } from 'src/core/constants'; import { Receipt } from './entities/receipt.entity'; @Injectable() export class ReceiptsService { constructor( @Inject(RECEIPT_REPOSITORY) private readonly receiptRepository: typeof Receipt, ) {} async create(createReceiptDto: CreateReceiptDto) { return await this.receiptRepository.create(createReceiptDto); } async findAll() { return await this.receiptRepository.findAll(); } async findByUser(id: number) { return await this.receiptRepository.findAll({ where: { userId: id } }); } async remove(id: number) { const deletedReceipt = await this.receiptRepository.findAll({ where: { id }, }); await this.receiptRepository.destroy({ where: { id } }); return deletedReceipt; } }