setup dpage account
This commit is contained in:
@@ -9,7 +9,7 @@ import { AdminRoute } from '../../common/decorators/admin.decorator';
|
|||||||
import { PermissionsDec } from '../../common/decorators/permission.decorator';
|
import { PermissionsDec } from '../../common/decorators/permission.decorator';
|
||||||
import { PermissionEnum } from '../users/enums/permission.enum';
|
import { PermissionEnum } from '../users/enums/permission.enum';
|
||||||
|
|
||||||
@Controller('dpage')
|
@Controller()
|
||||||
@ApiTags('d-page')
|
@ApiTags('d-page')
|
||||||
@AuthGuards()
|
@AuthGuards()
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@@ -18,7 +18,7 @@ export class DpageController {
|
|||||||
|
|
||||||
//----------- user routes ------------------
|
//----------- user routes ------------------
|
||||||
|
|
||||||
@Post('login')
|
@Post('dpage/login')
|
||||||
@ApiOperation({ summary: 'direct login' })
|
@ApiOperation({ summary: 'direct login' })
|
||||||
login(@Body() dto: LoginDto, @UserDec("id") userId: string) {
|
login(@Body() dto: LoginDto, @UserDec("id") userId: string) {
|
||||||
return this.dpageService.loginToDpage(dto, userId);
|
return this.dpageService.loginToDpage(dto, userId);
|
||||||
@@ -26,7 +26,7 @@ export class DpageController {
|
|||||||
|
|
||||||
//------------------admin routes ------------------
|
//------------------admin routes ------------------
|
||||||
|
|
||||||
@Get('business/list')
|
@Get('admin/business/list')
|
||||||
@AdminRoute()
|
@AdminRoute()
|
||||||
@PermissionsDec(PermissionEnum.DMENU)
|
@PermissionsDec(PermissionEnum.DMENU)
|
||||||
findAll(@Query() dto: FindBusinessesDto) {
|
findAll(@Query() dto: FindBusinessesDto) {
|
||||||
|
|||||||
@@ -15,5 +15,6 @@ import { dpageConfig } from '../../configs/dpage.config';
|
|||||||
inject: dpageConfig().inject,
|
inject: dpageConfig().inject,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
exports:[DPageService]
|
||||||
})
|
})
|
||||||
export class DpageModule { }
|
export class DpageModule { }
|
||||||
|
|||||||
@@ -63,8 +63,35 @@ export class DPageService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(id: number) {
|
async setupDpageAccount(dto: SetupAccountDto) {
|
||||||
return `This action returns a #${id} dpage`;
|
try {
|
||||||
|
// 2. Login with userSubscriptionId
|
||||||
|
const { data } = await firstValueFrom(
|
||||||
|
this.httpService
|
||||||
|
.post(`${this.config.baseUrl}/super-admin/business/setup`, dto,
|
||||||
|
{
|
||||||
|
headers: this.getHeaders(),
|
||||||
|
})
|
||||||
|
.pipe(
|
||||||
|
catchError((err: AxiosError) => {
|
||||||
|
this.logger.error(`Failed to perform setup account: ${err.message}`, err.stack);
|
||||||
|
return throwError(() => err);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof AxiosError && error.response) {
|
||||||
|
this.logger.error(`External API error response:`, error.response.data);
|
||||||
|
const errorResponse = {
|
||||||
|
...error.response.data,
|
||||||
|
message: error.response.data.error?.message || error.message,
|
||||||
|
};
|
||||||
|
throw new HttpException(errorResponse, error.response.status);
|
||||||
|
}
|
||||||
|
this.logger.error(`Error performing direct login: ${error instanceof Error ? error.message : "Unknown error"}`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update(id: number, updateDpageDto: UpdateDpageDto) {
|
// update(id: number, updateDpageDto: UpdateDpageDto) {
|
||||||
@@ -116,3 +143,13 @@ export class DPageService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export class SetupAccountDto {
|
||||||
|
danakSubscriptionId: string;
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
phone: string;
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { UsersModule } from "../users/users.module";
|
|||||||
import { UtilsModule } from "../utils/utils.module";
|
import { UtilsModule } from "../utils/utils.module";
|
||||||
import { WalletsModule } from "../wallets/wallets.module";
|
import { WalletsModule } from "../wallets/wallets.module";
|
||||||
import { DkalaModule } from "../dkala/dkala.module";
|
import { DkalaModule } from "../dkala/dkala.module";
|
||||||
|
import { DpageModule } from "../dpage/dpage.module";
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
LoggerModule,
|
LoggerModule,
|
||||||
@@ -50,6 +51,7 @@ import { DkalaModule } from "../dkala/dkala.module";
|
|||||||
AccessLogsModule,
|
AccessLogsModule,
|
||||||
forwardRef(() => DmenuModule),
|
forwardRef(() => DmenuModule),
|
||||||
forwardRef(() => DkalaModule),
|
forwardRef(() => DkalaModule),
|
||||||
|
forwardRef(() => DpageModule),
|
||||||
],
|
],
|
||||||
providers: [InvoicesService, InvoicesRepository, InvoiceItemsRepository, DiscountRepository, UsageDiscountRepository, InvoiceProcessor],
|
providers: [InvoicesService, InvoicesRepository, InvoiceItemsRepository, DiscountRepository, UsageDiscountRepository, InvoiceProcessor],
|
||||||
controllers: [InvoicesController],
|
controllers: [InvoicesController],
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ import { IExternalInvoiceJob, InvoicePurpose } from "../interfaces/external-invo
|
|||||||
import { InvoiceItemsRepository } from "../repositories/invoice-items.repository";
|
import { InvoiceItemsRepository } from "../repositories/invoice-items.repository";
|
||||||
import { InvoicesRepository } from "../repositories/invoices.repository";
|
import { InvoicesRepository } from "../repositories/invoices.repository";
|
||||||
import { DkalaService } from "../../dkala/providers/dkala.service";
|
import { DkalaService } from "../../dkala/providers/dkala.service";
|
||||||
|
import { DPageService } from "../../dpage/dpage.service";
|
||||||
|
import { randomInt } from "crypto";
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InvoicesService {
|
export class InvoicesService {
|
||||||
private readonly logger = new Logger(InvoicesService.name);
|
private readonly logger = new Logger(InvoicesService.name);
|
||||||
@@ -57,6 +59,7 @@ export class InvoicesService {
|
|||||||
private readonly accessLogService: AccessLogService,
|
private readonly accessLogService: AccessLogService,
|
||||||
private readonly restaurantService: RestaurantService,
|
private readonly restaurantService: RestaurantService,
|
||||||
private readonly dkalaService: DkalaService,
|
private readonly dkalaService: DkalaService,
|
||||||
|
private readonly dpageService: DPageService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
///********************************** */
|
///********************************** */
|
||||||
@@ -901,7 +904,23 @@ export class InvoicesService {
|
|||||||
userSubscription.status = SubscriptionStatus.ACTIVE;
|
userSubscription.status = SubscriptionStatus.ACTIVE;
|
||||||
await this.scheduleNextRenewalJob(userSubscription);
|
await this.scheduleNextRenewalJob(userSubscription);
|
||||||
this.logger.log(`Subscription ${userSubscription.id} activated `);
|
this.logger.log(`Subscription ${userSubscription.id} activated `);
|
||||||
|
if (userSubscription.plan.service.slug?.toLowerCase().includes('dpage')) {
|
||||||
|
try {
|
||||||
|
this.logger.log(`Calling external API for dpage setup: subscription ${userSubscription.id}`);
|
||||||
|
await this.dpageService.setupDpageAccount({
|
||||||
|
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
|
||||||
|
} );
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// if serivce is dmenu for renew or upgrade it must call dmenu api
|
// if serivce is dmenu for renew or upgrade it must call dmenu api
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user