add maxCataloguesCount
This commit is contained in:
@@ -8,8 +8,7 @@ import { IDPageConfig } from "../../configs/dpage.config";
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
import { DPAGE_CONFIG } from "./constants";
|
||||
import { FindBusinessesDto } from "./dto/find-businesses.dto";
|
||||
// import { UsersService } from "../users/providers/users.service";
|
||||
// import { UpdateDpageDto } from './dto/update-dpage.dto';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class DPageService {
|
||||
@@ -18,8 +17,7 @@ export class DPageService {
|
||||
@Inject(DPAGE_CONFIG) private readonly config: IDPageConfig,
|
||||
private readonly httpService: HttpService,
|
||||
private readonly subscriptionService: SubscriptionsService,
|
||||
// private readonly usersService: UsersService,
|
||||
) { }
|
||||
) { }
|
||||
|
||||
private getHeaders(): Record<string, string> {
|
||||
const credentials = Buffer.from(`${this.config.username}:${this.config.password}`).toString("base64");
|
||||
@@ -65,7 +63,6 @@ export class DPageService {
|
||||
|
||||
async setupDpageAccount(dto: SetupAccountDto) {
|
||||
try {
|
||||
// 2. Login with userSubscriptionId
|
||||
const { data } = await firstValueFrom(
|
||||
this.httpService
|
||||
.post(`${this.config.baseUrl}/super-admin/business/setup`, dto,
|
||||
@@ -89,15 +86,11 @@ export class DPageService {
|
||||
};
|
||||
throw new HttpException(errorResponse, error.response.status);
|
||||
}
|
||||
this.logger.error(`Error performing direct login: ${error instanceof Error ? error.message : "Unknown error"}`);
|
||||
this.logger.error(`Error performing setup account: ${error instanceof Error ? error.message : "Unknown error"}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// update(id: number, updateDpageDto: UpdateDpageDto) {
|
||||
// return `This action updates a #${id} dpage`;
|
||||
// }
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} dpage`;
|
||||
}
|
||||
@@ -152,4 +145,5 @@ export class SetupAccountDto {
|
||||
phone: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
maxCataloguesCount: number
|
||||
}
|
||||
|
||||
@@ -778,8 +778,7 @@ export class InvoicesService {
|
||||
queryRunner = this.dataSource.createQueryRunner(),
|
||||
) {
|
||||
let transactionStarted = false;
|
||||
|
||||
try {
|
||||
try {
|
||||
if (!queryRunner.isTransactionActive) {
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
@@ -805,23 +804,22 @@ export class InvoicesService {
|
||||
const userSubscription = invoice.items[0].subscriptionPlan;
|
||||
const invoiceItem = invoice.items[0];
|
||||
|
||||
// Check if this is an upgrade (subscription is ACTIVE and plan in invoice differs from current plan)
|
||||
const purpose = invoice.purpose
|
||||
|
||||
|
||||
|
||||
if (purpose == InvoicePurpose.UPGRADE) {
|
||||
// This is an upgrade - update subscription with the new plan
|
||||
const upgradePlan = invoiceItem.plan!;
|
||||
|
||||
const diffrence = upgradePlan.duration - userSubscription.plan.duration
|
||||
|
||||
|
||||
if (diffrence > 0) {
|
||||
userSubscription.endDate = dayjs(userSubscription.endDate).add(diffrence, "day").toDate();
|
||||
}
|
||||
this.logger.log(`Subscription ${userSubscription.id} upgraded to plan ${upgradePlan.name}`);
|
||||
|
||||
userSubscription.plan = upgradePlan;
|
||||
|
||||
|
||||
await this.scheduleNextRenewalJob(userSubscription);
|
||||
|
||||
// Call external API for dmenu service upgrades
|
||||
@@ -901,29 +899,31 @@ export class InvoicesService {
|
||||
}
|
||||
|
||||
} else if (purpose == InvoicePurpose.NEW) {
|
||||
userSubscription.status = SubscriptionStatus.ACTIVE;
|
||||
await this.scheduleNextRenewalJob(userSubscription);
|
||||
this.logger.log(`Subscription ${userSubscription.id} activated `);
|
||||
console.log('hi-1')
|
||||
if (userSubscription.plan.service.slug?.toLowerCase().includes('dpage')) {
|
||||
try {
|
||||
this.logger.log(`Calling external API for dpage setup: subscription ${userSubscription.id}`);
|
||||
console.log('userSubscription.plan.count',userSubscription.plan.count)
|
||||
await this.dpageService.setupDpageAccount({
|
||||
danakSubscriptionId:userSubscription.id,
|
||||
danakSubscriptionId: userSubscription.id,
|
||||
name: userSubscription.businessName,
|
||||
slug: randomInt(100_000,1_000_000).toString(),
|
||||
phone: userSubscription.user.phone,
|
||||
firstName: userSubscription.user.firstName,
|
||||
lastName: userSubscription.user.lastName
|
||||
} );
|
||||
slug: randomInt(100_000, 1_000_000).toString(),
|
||||
phone: user.phone,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName,
|
||||
maxCataloguesCount: userSubscription.plan.count ?? 0
|
||||
});
|
||||
this.logger.log(`External API call completed for dpage setup account: subscription ${userSubscription.id}`);
|
||||
} catch (error) {
|
||||
this.logger.error(`Failed to call external API for dpage setup account: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
// Don't fail the transaction if external API call fails
|
||||
}
|
||||
}
|
||||
userSubscription.status = SubscriptionStatus.ACTIVE;
|
||||
await this.scheduleNextRenewalJob(userSubscription);
|
||||
this.logger.log(`Subscription ${userSubscription.id} activated `);
|
||||
}
|
||||
// if serivce is dmenu for renew or upgrade it must call dmenu api
|
||||
//
|
||||
|
||||
await queryRunner.manager.save(UserSubscription, userSubscription);
|
||||
await this.walletsService.createSubscriptionTransaction(invoice.totalPrice, userWallet.id, queryRunner);
|
||||
await this.addNotifyForWalletDeduction(invoice, user, userWallet, WalletMessage.SUBSCRIPTION_WALLET_TRANSFER);
|
||||
@@ -1021,7 +1021,9 @@ export class InvoicesService {
|
||||
relations: {
|
||||
items: {
|
||||
subscriptionPlan: {
|
||||
plan: true,
|
||||
plan: {
|
||||
service: true
|
||||
}
|
||||
},
|
||||
plan: {
|
||||
service: true
|
||||
|
||||
Reference in New Issue
Block a user