feat: implemented property format

main
adriano 2025-09-23 06:59:15 -03:00
parent 0895d42fe4
commit a7847185fd
2 changed files with 38 additions and 29 deletions

View File

@ -15,7 +15,7 @@ const API_Usage_Whatsapp = require("../models/API_Usage_Whatsapp.js")
const setApiPricing = async (req, res) => {
const { provider, product, currency, price, billingBy, billingUnit, type, clientPrice } = req.body
const { provider, product, currency, price, billingBy, billingUnit, type, clientPrice, format } = req.body
mustContainProperties(req, ['provider',
'product',
@ -40,7 +40,8 @@ const setApiPricing = async (req, res) => {
billingBy,
billingUnit,
type,
clientPrice
clientPrice,
format
}
const options = { new: true, upsert: true }
@ -196,6 +197,7 @@ const registerUsage = async (req, res) => {
callerId,
sessionId,
companyId,
format
} = req.body
@ -227,7 +229,8 @@ const registerUsage = async (req, res) => {
billingBy,
billingUnit,
companyId,
total_cost: calculateApiUsage(price, billingUnit, usage)
total_cost: calculateApiUsage(price, billingUnit, usage),
format
})
return res.status(StatusCodes.OK).json({ apiUsage })

View File

@ -1,43 +1,49 @@
const mongoose = require('../db/connect')
const mongoose = require("../db/connect");
const { Schema } = mongoose
const { Schema } = mongoose;
const apiPricing = new Schema({
const apiPricing = new Schema(
{
provider: {
type: String,
required: true,
type: String,
required: true,
},
product: {
type: String,
required: true,
type: String,
required: true,
},
currency: {
type: String,
enum: ['dollar', 'real',],
default: 'dollar'
type: String,
enum: ["dollar", "real"],
default: "dollar",
},
price: {
type: String,
required: true
type: String,
required: true,
},
clientPrice: {
type: String,
type: String,
},
billingBy:{
type: String,
enum: ['minute', 'character', 'token', 'second', 'hour'],
required: true,
billingBy: {
type: String,
enum: ["minute", "character", "token", "second", "hour"],
required: true,
},
billingUnit:{
type: Number,
required: true
billingUnit: {
type: Number,
required: true,
},
type: {
type: String,
}
type: String,
},
format: {
type: String,
enum: ["text", "audio", "image", "video"],
},
},
{ timestamps: true }
);
}, { timestamps: true })
const API_Pricing = mongoose.model('API_Pricing', apiPricing)
const API_Pricing = mongoose.model("API_Pricing", apiPricing);
module.exports = API_Pricing
module.exports = API_Pricing;