feat: add 'second' option to enum billingBy in API_Pricing model and update API usage calculation function
parent
f26045a038
commit
5c81ae2513
|
@ -79,7 +79,7 @@ const registerUsage = async (req, res) => {
|
|||
billingBy,
|
||||
billingUnit,
|
||||
companyId,
|
||||
total_cost: calculateApiUsage(price, billingUnit, usage, billingBy)
|
||||
total_cost: calculateApiUsage(price, billingUnit, usage)
|
||||
})
|
||||
|
||||
return res.status(StatusCodes.OK).json({ apiUsage })
|
||||
|
@ -182,7 +182,7 @@ const registerAll = async (req, res) => {
|
|||
billingBy,
|
||||
billingUnit,
|
||||
companyId,
|
||||
total_cost: calculateApiUsage(price, billingUnit, usage, billingBy)
|
||||
total_cost: calculateApiUsage(price, billingUnit, usage)
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ const apiPricing = new Schema({
|
|||
},
|
||||
billingBy:{
|
||||
type: String,
|
||||
enum: ['minute', 'character', 'token'],
|
||||
enum: ['minute', 'character', 'token', 'second'],
|
||||
required: true,
|
||||
},
|
||||
billingUnit:{
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
|
||||
|
||||
function calculateApiUsage(price, billingUnit, usage, billingBy) {
|
||||
let _billingUnit = +billingUnit
|
||||
|
||||
if (billingBy == 'minute')
|
||||
_billingUnit = 60 * _billingUnit
|
||||
|
||||
const total_cost = (+usage / _billingUnit) * parseFloat(price)
|
||||
|
||||
|
||||
const total_cost = (+usage / +billingUnit) * parseFloat(price)
|
||||
|
||||
return total_cost.toFixed(10)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue