You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

34 lines
914 B

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;
}
}