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

View File

@ -1,8 +1,9 @@
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: { provider: {
type: String, type: String,
required: true, required: true,
@ -13,31 +14,36 @@ const apiPricing = new Schema({
}, },
currency: { currency: {
type: String, type: String,
enum: ['dollar', 'real',], enum: ["dollar", "real"],
default: 'dollar' default: "dollar",
}, },
price: { price: {
type: String, type: String,
required: true required: true,
}, },
clientPrice: { clientPrice: {
type: String, type: String,
}, },
billingBy: { billingBy: {
type: String, type: String,
enum: ['minute', 'character', 'token', 'second', 'hour'], enum: ["minute", "character", "token", "second", "hour"],
required: true, required: true,
}, },
billingUnit: { billingUnit: {
type: Number, type: Number,
required: true required: true,
}, },
type: { 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