Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore:removed await from non async function #1350

Closed
wants to merge 9 commits into from
8 changes: 4 additions & 4 deletions src/modules/auth/strategies/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { ConfigService } from '@nestjs/config';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(private configService: ConfigService) {
const secret = configService.get<string>('auth.jwtSecret');
console.log('JWT Secret is set:', !!secret);
constructor(private readonly configService: ConfigService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: secret,
secretOrKey: configService.get<string>('auth.jwtSecret'),
});

console.log('JWT Secret is set:', !!this.configService.get<string>('auth.jwtSecret'));
}

async validate(payload: any) {
Expand Down
2 changes: 0 additions & 2 deletions src/modules/billing-plans/billing-plan.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
Injectable,
HttpStatus,
HttpException,
BadRequestException,
NotFoundException,
InternalServerErrorException,
} from '@nestjs/common';
import { Repository } from 'typeorm';
import { BillingPlan } from './entities/billing-plan.entity';
Expand Down
2 changes: 2 additions & 0 deletions src/modules/flutterwave/flutterwave.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getRepositoryToken } from '@nestjs/typeorm';
import { of } from 'rxjs';
import { AxiosResponse } from 'axios';
import { CreateFlutterwavePaymentDto } from './dto/create-flutterwave-payment.dto';
import axios from 'axios';

describe('FlutterwaveService', () => {
let service: FlutterwaveService;
Expand All @@ -21,6 +22,7 @@ describe('FlutterwaveService', () => {
{
provide: HttpService,
useValue: {
axiosRef: axios,
get: jest.fn(),
post: jest.fn(),
},
Expand Down
57 changes: 37 additions & 20 deletions src/modules/flutterwave/flutterwave.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
import { firstValueFrom } from 'rxjs';
import { CreateFlutterwavePaymentDto } from './dto/create-flutterwave-payment.dto';
import { CreatePaymentDto } from './dto/create-payment.dto';
import { ConfigService } from '@nestjs/config';
Expand All @@ -12,35 +13,40 @@ import { PAYMENT_NOTFOUND } from '@shared/constants/SystemMessages';

@Injectable()
export class FlutterwaveService {
private readonly secretkey: string;
private readonly secretKey: string;
private readonly baseUrl: string;

constructor(
private readonly httpService: HttpService,
private readonly configService: ConfigService,
@InjectRepository(Payment)
private readonly paymentRepo: Repository<Payment>
) {
this.secretkey = configService.get<string>('FLUTTERWAVE_SECRET_KEY');
this.baseUrl = configService.get<string>('FLUTTERWAVE_BASE_URL');
this.secretKey = this.configService.get<string>('FLUTTERWAVE_SECRET_KEY');
this.baseUrl = this.configService.get<string>('FLUTTERWAVE_BASE_URL');
}

async initiatePayment(createFlutterwavePaymentDto: CreateFlutterwavePaymentDto, userId: string) {
const headers = {
Authorization: `Bearer ${this.secretkey}`,
Authorization: `Bearer ${this.secretKey}`,
'Content-Type': 'application/json',
};
const payment_plan = await this.httpService
.get(`${this.baseUrl}/payment-plans/${createFlutterwavePaymentDto.plan_id}`, { headers })
.toPromise();
if (!payment_plan) {

const paymentPlanObs = this.httpService.get(
`${this.baseUrl}/payment-plans/${createFlutterwavePaymentDto.plan_id}`,
{ headers }
);
const paymentPlan = await firstValueFrom(paymentPlanObs).catch(() => null);
if (!paymentPlan || !paymentPlan.data?.data) {
throw new CustomHttpException(PAYMENT_NOTFOUND, 404);
}
const { amount, currency } = payment_plan.data.data;

const { amount, currency } = paymentPlan.data.data;
const { email, first_name, last_name } = createFlutterwavePaymentDto;
const paymentData = {
tx_ref: uuid4(),
amount: amount,
currency: currency,
amount,
currency,
redirect_url: createFlutterwavePaymentDto.redirect_url,
customer: {
email: email,
Expand All @@ -56,41 +62,52 @@ export class FlutterwaveService {
billing_option: createFlutterwavePaymentDto.billing_option,
},
};
const response = await this.httpService.post(`${this.baseUrl}/payments`, paymentData, { headers }).toPromise();

const paymentInitObs = this.httpService.post(`${this.baseUrl}/payments`, paymentData, { headers });
const response = await firstValueFrom(paymentInitObs);

const createPaymentDto: CreatePaymentDto = {
user_id: userId,
transaction_id: uuid4(),
gateway_id: '',
amount: paymentData.amount,
status: PaymentStatus.PENDING,
};
const newPayment = await this.paymentRepo.create(createPaymentDto);
const newPayment = this.paymentRepo.create(createPaymentDto);
await this.paymentRepo.save(newPayment);

return {
status: 200,
message: 'Payment initiated successfully',
data: {
payment_url: response.data.data.link,
payment_url: response.data?.data?.link,
},
};
}

async verifyPayment(transactionId: string): Promise<any> {
const headers = {
Authorization: `Bearer ${this.secretkey}`,
Authorization: `Bearer ${this.secretKey}`,
'Content-Type': 'application/json',
};
const response = await this.httpService
.get(`${this.baseUrl}/transactions/${transactionId}/verify`, { headers })
.toPromise();
const payment = await this.paymentRepo.findOne({ where: { transaction_id: transactionId } });

const verifyObs = this.httpService.get(`${this.baseUrl}/transactions/${transactionId}/verify`, { headers });
const response = await firstValueFrom(verifyObs);

const payment = await this.paymentRepo.findOne({
where: { transaction_id: transactionId },
});
if (!payment) {
throw new CustomHttpException(PAYMENT_NOTFOUND, 404);
}
payment.status = PaymentStatus.APPROVED;
await this.paymentRepo.save(payment);

return {
status: 200,
message: 'Payment verified successfully',
data: {
paymentStatus: response.data.data,
paymentStatus: response.data?.data,
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/invite/invite.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class InviteService {

const token = uuidv4();

const invite = await this.inviteRepository.create({
const invite = this.inviteRepository.create({
token,
organisation: organisation,
isGeneric: true,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/notifications/notifications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class NotificationsService {
}
}

async markNotificationAsRead(options: MarkNotificationAsReadDto, notificationId: string, userId: string) {
async markNotificationAsRead(options: MarkNotificationAsReadDto, notificationId: string, _userId: string) {
try {
if (!notificationId || !options) {
throw new BadRequestException({
Expand Down
2 changes: 1 addition & 1 deletion src/modules/profile/dto/file.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class FileValidator implements PipeTransform {
}

private async validateFileType(buffer: Buffer) {
const response = await fileType.parse(buffer);
const response = fileType.parse(buffer);
if (!response || !this.options.mimeTypes.includes(response.mime)) {
throw new CustomHttpException(INVALID_FILE_TYPE(this.options.mimeTypes.join(', ')), HttpStatus.BAD_REQUEST);
}
Expand Down
8 changes: 7 additions & 1 deletion src/modules/testimonials/testimonials.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { TestimonialResponse } from './interfaces/testimonial-response.interface
import { UpdateTestimonialDto } from './dto/update-testimonial.dto';
import { TextService } from '@modules/translation/translation.service';
import UserService from '@modules/user/user.service';
import { User } from '@modules/user/entities/user.entity';
import UserInterface from '@modules/user/interfaces/UserInterface';

@Injectable()
export class TestimonialsService {
Expand All @@ -31,7 +33,11 @@ export class TestimonialsService {
return this.textService.translateText(content, lang);
}

async createTestimonial(createTestimonialDto: CreateTestimonialDto, user, language?: string) {
async createTestimonial(
createTestimonialDto: CreateTestimonialDto,
user: User | Partial<UserInterface>,
language?: string
) {
try {
const { content, name } = createTestimonialDto;

Expand Down
3 changes: 1 addition & 2 deletions src/modules/timezones/timezones.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Controller, Post, Body, Get, Res, HttpStatus, Patch, Param, Delete } from '@nestjs/common';
import { Controller, Post, Body, Get, Patch, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiBody, ApiBearerAuth } from '@nestjs/swagger';
import { CreateTimezoneDto } from './dto/create-timezone.dto';
import { UpdateTimezoneDto } from './dto/update-timezone.dto';
import { TimezonesService } from './timezones.service';
import { Response } from 'express';

@ApiTags('Timezones')
@Controller('timezones')
Expand Down
4 changes: 2 additions & 2 deletions src/modules/translation/translation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class TextService {
const prompt = `Please provide a direct translation of the following text to ${targetLanguage}, without any additional context or explanations:\n\n"${text}"`;

const result = await this.model.generateContent(prompt);
const response = await result.response;
let translatedText = await response.text();
const response = result.response;
let translatedText = response.text();
translatedText = translatedText.replace(/^"|"$/g, '').trim();

return translatedText;
Expand Down