From a7847185fd084126306e4eed4dc0fc13e87690ac Mon Sep 17 00:00:00 2001 From: adriano Date: Tue, 23 Sep 2025 06:59:15 -0300 Subject: [PATCH] feat: implemented property format --- controllers/apiUsagePricing.js | 9 ++++-- models/API_Pricing.js | 58 +++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/controllers/apiUsagePricing.js b/controllers/apiUsagePricing.js index 3e258d5..b62f202 100644 --- a/controllers/apiUsagePricing.js +++ b/controllers/apiUsagePricing.js @@ -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 }) diff --git a/models/API_Pricing.js b/models/API_Pricing.js index 9c9e521..c3e1cad 100644 --- a/models/API_Pricing.js +++ b/models/API_Pricing.js @@ -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;