chore: implenet the external invoice 2

This commit is contained in:
mahyargdz
2025-07-14 12:29:00 +03:30
parent 1794b36758
commit 9d46c4f20b
12 changed files with 409 additions and 21 deletions
@@ -1,7 +1,10 @@
import { EntityManager } from "@mikro-orm/postgresql";
import { BadRequestException, Injectable } from "@nestjs/common";
import { QuotaPurchaseService } from "./quota-purchase.service";
import { BusinessMessage } from "../../../common/enums/message.enum";
import { QUOTA_CONSTANTS } from "../constant";
import { PurchaseQuotaDto } from "../DTO/purchase-quota.dto";
import { UpdateBusinessSettingsDto } from "../DTO/update-business-settings.dto";
import { BusinessStaff } from "../entities/business-staff.entity";
import { BusinessRepository } from "../repositories/business.repository";
@@ -11,6 +14,7 @@ export class BusinessesService {
constructor(
private readonly businessRepository: BusinessRepository,
private readonly em: EntityManager,
private readonly quotaPurchaseService: QuotaPurchaseService,
) {}
async getBusinessByDanakSubscriptionId(danakSubscriptionId: string) {
@@ -93,6 +97,7 @@ export class BusinessesService {
return {
quota: {
quotaPricePerGB: QUOTA_CONSTANTS.QUOTA_PRICE_PER_GB,
total: Number(business.quota),
used: Number(business.usedQuota),
remaining: Number(business.remainingQuota),
@@ -106,4 +111,12 @@ export class BusinessesService {
},
};
}
//************************************************** */
async purchaseQuota(businessId: string, purchaseDto: PurchaseQuotaDto) {
const business = await this.businessRepository.findOne({ id: businessId, deletedAt: null });
if (!business) throw new BadRequestException(BusinessMessage.NOT_FOUND);
return this.quotaPurchaseService.purchaseQuota(business, purchaseDto);
}
}