add: migration
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { EntityManager } from "@mikro-orm/postgresql";
|
||||
import { InjectQueue } from "@nestjs/bullmq";
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import { Queue } from "bullmq";
|
||||
import dayjs from "dayjs";
|
||||
import Decimal from "decimal.js";
|
||||
import { Workbook } from "exceljs";
|
||||
|
||||
import { IFile } from "../utils/interfaces/IFile";
|
||||
|
||||
import { BillListQueryDto } from "./dto/bill-list-query.dto";
|
||||
import { CreateChargeBillDto } from "./dto/create-charge-bill.dto";
|
||||
import { CreateWaterBillDto, CreateWaterBillFromExcelDto } from "./dto/create-water-bill.dto";
|
||||
@@ -16,13 +16,11 @@ import { CompanyMessage } from "../../common/enums/message.enum";
|
||||
import { Business } from "../businesses/entities/business.entity";
|
||||
import { Company } from "../companies/entities/company.entity";
|
||||
import { CompaniesService } from "../companies/services/companies.service";
|
||||
import { INVOICE } from "../invoices/constants";
|
||||
import { InvoiceItem } from "../invoices/entities/invoice-item.entity";
|
||||
import { Invoice } from "../invoices/entities/invoice.entity";
|
||||
import { NotificationQueue } from "../notifications/queue/notification.queue";
|
||||
import { InjectQueue } from "@nestjs/bullmq";
|
||||
import { INVOICE } from "../invoices/constants";
|
||||
import { Queue } from "bullmq";
|
||||
|
||||
import { IFile } from "../utils/interfaces/IFile";
|
||||
|
||||
@Injectable()
|
||||
export class BillsService {
|
||||
@@ -33,8 +31,7 @@ export class BillsService {
|
||||
@InjectQueue(INVOICE.QUEUE_NAME)
|
||||
private readonly invoiceQueue: Queue,
|
||||
private readonly notificationQueue: NotificationQueue,
|
||||
|
||||
) { }
|
||||
) {}
|
||||
|
||||
async createWaterBill(dto: CreateWaterBillDto, business: Business) {
|
||||
const { values, waterRate, dueDays } = dto;
|
||||
@@ -95,8 +92,8 @@ export class BillsService {
|
||||
}
|
||||
}
|
||||
|
||||
private async addInvoiceReminderJobs(billId: string) {
|
||||
const invoices = await this.em.find(Invoice, { bill: { id: billId } }, { populate: ["items", "company","company.user"] });
|
||||
private async addInvoiceReminderJobs(billId: string) {
|
||||
const invoices = await this.em.find(Invoice, { bill: { id: billId } }, { populate: ["items", "company", "company.user"] });
|
||||
|
||||
for (const invoice of invoices) {
|
||||
await this.notificationQueue.addInvoiceCreationNotification(invoice.company.user.id, {
|
||||
@@ -196,7 +193,7 @@ export class BillsService {
|
||||
await em.flush();
|
||||
await em.commit();
|
||||
|
||||
await this.addInvoiceReminderJobs(bill.id)
|
||||
await this.addInvoiceReminderJobs(bill.id);
|
||||
|
||||
return bill;
|
||||
} catch (error) {
|
||||
@@ -223,10 +220,7 @@ export class BillsService {
|
||||
}
|
||||
|
||||
async remove(id: string, businessId: string) {
|
||||
const bill = await this.billRepository.findOne(
|
||||
{ id, business: { id: businessId } },
|
||||
{ populate: ["invoices"] },
|
||||
);
|
||||
const bill = await this.billRepository.findOne({ id, business: { id: businessId } }, { populate: ["invoices"] });
|
||||
if (!bill) {
|
||||
throw new BadRequestException("Bill not found");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user