Skip to content

Commit

Permalink
Update helper.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed May 18, 2024
1 parent 49c702d commit e51906d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 42 deletions.
1 change: 0 additions & 1 deletion api/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const babel = (api) => {
{
alias: {
':movinin-types': '../packages/movinin-types',
':movinin-helper': '../packages/movinin-helper',
},
},
],
Expand Down
41 changes: 0 additions & 41 deletions api/src/common/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import mongoose from 'mongoose'
import validator from 'validator'
import Stripe from 'stripe'
import { v1 as uuid } from 'uuid'
import * as movininTypes from ':movinin-types'

/**
* Convert string to boolean.
Expand Down Expand Up @@ -212,43 +211,3 @@ export const getStripeLocale = (locale: string): Stripe.Checkout.SessionCreatePa

return 'auto'
}

/**
* Get number of days in a month.
*
* @param {number} month
* @param {number} year
* @returns {number}
*/
export const daysInMonth = (month: number, year: number) => new Date(year, month, 0).getDate()

/**
* Get number of days in a year.
*
* @param {number} year
* @returns {(366 | 365)}
*/
export const daysInYear = (year: number) => (((year % 4 === 0 && year % 100 > 0) || year % 400 === 0) ? 366 : 365)

/**
* Return daily price.
*
* @param price
* @param rentalTerm
* @returns {number}
*/
export const getDailyPrice = (price: number, rentalTerm: movininTypes.RentalTerm) => {
let res = 0
const now = new Date()
if (rentalTerm === movininTypes.RentalTerm.Monthly) {
res = price / daysInMonth(now.getMonth(), now.getFullYear())
} else if (rentalTerm === movininTypes.RentalTerm.Weekly) {
res = price / 7
} else if (rentalTerm === movininTypes.RentalTerm.Daily) {
res = price
} else if (rentalTerm === movininTypes.RentalTerm.Yearly) {
res = price / daysInYear(now.getFullYear())
}

return res
}

0 comments on commit e51906d

Please sign in to comment.