Skip to content

Commit

Permalink
Fix: async condition handling in api
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Feb 13, 2025
1 parent b449a05 commit 0abe4c7
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion api/src/common/databaseHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export const initialize = async (): Promise<boolean> => {
//
// Initialize collections
//
const res = await initializeLocations() && await initializeCountries()
const res = (await initializeLocations()) && (await initializeCountries())

return res
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions api/src/controllers/bookingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export const checkout = async (req: Request, res: Response) => {
await notify(user, booking.id, agency, message)

// Notify admin
const admin = !!env.ADMIN_EMAIL && await User.findOne({ email: env.ADMIN_EMAIL, type: movininTypes.UserType.Admin })
const admin = !!env.ADMIN_EMAIL && (await User.findOne({ email: env.ADMIN_EMAIL, type: movininTypes.UserType.Admin }))
if (admin) {
i18n.locale = admin.language
message = body.payLater ? i18n.t('BOOKING_PAY_LATER_NOTIFICATION') : i18n.t('BOOKING_PAID_NOTIFICATION')
Expand Down Expand Up @@ -896,7 +896,7 @@ export const cancelBooking = async (req: Request, res: Response) => {
await notify(booking.renter, booking.id.toString(), agency, i18n.t('CANCEL_BOOKING_NOTIFICATION'))

// Notify admin
const admin = !!env.ADMIN_EMAIL && await User.findOne({ email: env.ADMIN_EMAIL, type: movininTypes.UserType.Admin })
const admin = !!env.ADMIN_EMAIL && (await User.findOne({ email: env.ADMIN_EMAIL, type: movininTypes.UserType.Admin }))
if (admin) {
i18n.locale = admin.language
await notify(booking.renter, booking.id.toString(), admin, i18n.t('CANCEL_BOOKING_NOTIFICATION'))
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/paypalController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const checkPayPalOrder = async (req: Request, res: Response) => {
await bookingController.notify(user, booking.id, agency, message)

// Notify admin
const admin = !!env.ADMIN_EMAIL && await User.findOne({ email: env.ADMIN_EMAIL, type: movininTypes.UserType.Admin })
const admin = !!env.ADMIN_EMAIL && (await User.findOne({ email: env.ADMIN_EMAIL, type: movininTypes.UserType.Admin }))
if (admin) {
i18n.locale = admin.language
message = i18n.t('BOOKING_PAID_NOTIFICATION')
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/stripeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const checkCheckoutSession = async (req: Request, res: Response) => {
await bookingController.notify(user, booking.id, agency, message)

// Notify admin
const admin = !!env.ADMIN_EMAIL && await User.findOne({ email: env.ADMIN_EMAIL, type: movininTypes.UserType.Admin })
const admin = !!env.ADMIN_EMAIL && (await User.findOne({ email: env.ADMIN_EMAIL, type: movininTypes.UserType.Admin }))
if (admin) {
i18n.locale = admin.language
message = i18n.t('BOOKING_PAID_NOTIFICATION')
Expand Down
4 changes: 1 addition & 3 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import * as databaseHelper from './common/databaseHelper'
import * as env from './config/env.config'
import * as logger from './common/logger'

if (
await databaseHelper.connect(env.DB_URI, env.DB_SSL, env.DB_DEBUG) && await databaseHelper.initialize()
) {
if ((await databaseHelper.connect(env.DB_URI, env.DB_SSL, env.DB_DEBUG)) && (await databaseHelper.initialize())) {
let server: http.Server | https.Server

if (env.HTTPS) {
Expand Down

0 comments on commit 0abe4c7

Please sign in to comment.