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 { PermissionEnum } from '../users/enums/permission.enum';
|
||||
|
||||
@Controller('dpage')
|
||||
@Controller()
|
||||
@ApiTags('d-page')
|
||||
@AuthGuards()
|
||||
@ApiBearerAuth()
|
||||
@@ -18,7 +18,7 @@ export class DpageController {
|
||||
|
||||
//----------- user routes ------------------
|
||||
|
||||
@Post('login')
|
||||
@Post('dpage/login')
|
||||
@ApiOperation({ summary: 'direct login' })
|
||||
login(@Body() dto: LoginDto, @UserDec("id") userId: string) {
|
||||
return this.dpageService.loginToDpage(dto, userId);
|
||||
@@ -26,7 +26,7 @@ export class DpageController {
|
||||
|
||||
//------------------admin routes ------------------
|
||||
|
||||
@Get('business/list')
|
||||
@Get('admin/business/list')
|
||||
@AdminRoute()
|
||||
@PermissionsDec(PermissionEnum.DMENU)
|
||||
findAll(@Query() dto: FindBusinessesDto) {
|
||||
|
||||
@@ -15,5 +15,6 @@ import { dpageConfig } from '../../configs/dpage.config';
|
||||
inject: dpageConfig().inject,
|
||||
},
|
||||
],
|
||||
exports:[DPageService]
|
||||
})
|
||||
export class DpageModule { }
|
||||
|
||||
@@ -63,8 +63,35 @@ export class DPageService {
|
||||
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} dpage`;
|
||||
async setupDpageAccount(dto: SetupAccountDto) {
|
||||
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) {
|
||||
@@ -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 { WalletsModule } from "../wallets/wallets.module";
|
||||
import { DkalaModule } from "../dkala/dkala.module";
|
||||
import { DpageModule } from "../dpage/dpage.module";
|
||||
@Module({
|
||||
imports: [
|
||||
LoggerModule,
|
||||
@@ -50,6 +51,7 @@ import { DkalaModule } from "../dkala/dkala.module";
|
||||
AccessLogsModule,
|
||||
forwardRef(() => DmenuModule),
|
||||
forwardRef(() => DkalaModule),
|
||||
forwardRef(() => DpageModule),
|
||||
],
|
||||
providers: [InvoicesService, InvoicesRepository, InvoiceItemsRepository, DiscountRepository, UsageDiscountRepository, InvoiceProcessor],
|
||||
controllers: [InvoicesController],
|
||||
|
||||
@@ -39,6 +39,8 @@ import { IExternalInvoiceJob, InvoicePurpose } from "../interfaces/external-invo
|
||||
import { InvoiceItemsRepository } from "../repositories/invoice-items.repository";
|
||||
import { InvoicesRepository } from "../repositories/invoices.repository";
|
||||
import { DkalaService } from "../../dkala/providers/dkala.service";
|
||||
import { DPageService } from "../../dpage/dpage.service";
|
||||
import { randomInt } from "crypto";
|
||||
@Injectable()
|
||||
export class InvoicesService {
|
||||
private readonly logger = new Logger(InvoicesService.name);
|
||||
@@ -57,6 +59,7 @@ export class InvoicesService {
|
||||
private readonly accessLogService: AccessLogService,
|
||||
private readonly restaurantService: RestaurantService,
|
||||
private readonly dkalaService: DkalaService,
|
||||
private readonly dpageService: DPageService,
|
||||
) { }
|
||||
|
||||
///********************************** */
|
||||
@@ -901,7 +904,23 @@ export class InvoicesService {
|
||||
userSubscription.status = SubscriptionStatus.ACTIVE;
|
||||
await this.scheduleNextRenewalJob(userSubscription);
|
||||
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
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user