Compare commits
No commits in common. "54a4f837ce6e4b12c5ca97c24a408f0fb4cd56a2" and "5c81ae25139ca193f7e5d58bd41805499a700f63" have entirely different histories.
54a4f837ce
...
5c81ae2513
|
@ -9,7 +9,6 @@ const billingSumUsage = require("../utils/billingSumUsage.js")
|
||||||
const moment = require('moment')
|
const moment = require('moment')
|
||||||
const API_Call = require("../models/API_Call.js")
|
const API_Call = require("../models/API_Call.js")
|
||||||
const API_Operation = require("../models/API_Operation.js")
|
const API_Operation = require("../models/API_Operation.js")
|
||||||
const API_Usage_Whatsapp = require("../models/API_Usage_Whatsapp.js")
|
|
||||||
|
|
||||||
const setApiPricing = async (req, res) => {
|
const setApiPricing = async (req, res) => {
|
||||||
|
|
||||||
|
@ -24,12 +23,7 @@ const setApiPricing = async (req, res) => {
|
||||||
const normalizedProvider = provider.trim().toLowerCase()
|
const normalizedProvider = provider.trim().toLowerCase()
|
||||||
const normalizedProduct = product.trim().toLowerCase()
|
const normalizedProduct = product.trim().toLowerCase()
|
||||||
|
|
||||||
let filter = { provider: normalizedProvider, product: normalizedProduct }
|
const filter = { provider: normalizedProvider, product: normalizedProduct }
|
||||||
|
|
||||||
if (type) {
|
|
||||||
filter = { ...filter, type }
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = {
|
const update = {
|
||||||
provider: normalizedProvider,
|
provider: normalizedProvider,
|
||||||
product: normalizedProduct,
|
product: normalizedProduct,
|
||||||
|
@ -53,14 +47,14 @@ const registerUsage = async (req, res) => {
|
||||||
usage,
|
usage,
|
||||||
callerId,
|
callerId,
|
||||||
sessionId,
|
sessionId,
|
||||||
companyId,
|
companyId,
|
||||||
|
|
||||||
} = req.body
|
} = req.body
|
||||||
|
|
||||||
mustContainProperties(req, [
|
mustContainProperties(req, [
|
||||||
'companyId',
|
'companyId',
|
||||||
'callerId',
|
'callerId',
|
||||||
'sessionId',
|
'sessionId',
|
||||||
'provider',
|
'provider',
|
||||||
'product',
|
'product',
|
||||||
'usage',
|
'usage',
|
||||||
|
@ -79,7 +73,7 @@ const registerUsage = async (req, res) => {
|
||||||
provider: provider.trim().toLowerCase(),
|
provider: provider.trim().toLowerCase(),
|
||||||
product: product.trim().toLowerCase(),
|
product: product.trim().toLowerCase(),
|
||||||
callerId,
|
callerId,
|
||||||
sessionId,
|
sessionId,
|
||||||
usage,
|
usage,
|
||||||
price,
|
price,
|
||||||
billingBy,
|
billingBy,
|
||||||
|
@ -96,60 +90,6 @@ const registerUsage = async (req, res) => {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const registerWhatsappUsage = async (req, res) => {
|
|
||||||
const {
|
|
||||||
companyId,
|
|
||||||
provider,
|
|
||||||
product,
|
|
||||||
type,
|
|
||||||
msgId,
|
|
||||||
ticketId,
|
|
||||||
billable,
|
|
||||||
pricing_model,
|
|
||||||
} = req.body
|
|
||||||
|
|
||||||
mustContainProperties(req, [
|
|
||||||
'companyId',
|
|
||||||
'provider',
|
|
||||||
'product',
|
|
||||||
'type',
|
|
||||||
'msgId',
|
|
||||||
'ticketId',
|
|
||||||
'billable',
|
|
||||||
'pricing_model'
|
|
||||||
])
|
|
||||||
|
|
||||||
const apiPricing = await API_Pricing.findOne({
|
|
||||||
provider: provider.trim().toLowerCase(),
|
|
||||||
product: product.trim().toLowerCase(),
|
|
||||||
type: type.trim().toLowerCase(),
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
if (apiPricing) {
|
|
||||||
|
|
||||||
const { price } = apiPricing
|
|
||||||
|
|
||||||
const apiUsageWhatsapp = await API_Usage_Whatsapp.create({
|
|
||||||
companyId,
|
|
||||||
provider: provider.trim().toLowerCase(),
|
|
||||||
product: product.trim().toLowerCase(),
|
|
||||||
price,
|
|
||||||
msgId,
|
|
||||||
ticketId,
|
|
||||||
billable,
|
|
||||||
pricing_model,
|
|
||||||
type
|
|
||||||
})
|
|
||||||
|
|
||||||
return res.status(StatusCodes.OK).json({ apiUsageWhatsapp })
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
res.status(StatusCodes.NOT_FOUND).json({ msg: `Price not found for ${product} in the API Pricing table` })
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const registerAPICall = async (req, res) => {
|
const registerAPICall = async (req, res) => {
|
||||||
const {
|
const {
|
||||||
callerId,
|
callerId,
|
||||||
|
@ -189,12 +129,12 @@ const registerOperation = async (req, res) => {
|
||||||
operation,
|
operation,
|
||||||
quantityOfOperationAttempts: quantityOfAttempts,
|
quantityOfOperationAttempts: quantityOfAttempts,
|
||||||
} = req.body
|
} = req.body
|
||||||
|
|
||||||
mustContainProperties(req, [
|
mustContainProperties(req, [
|
||||||
'companyId',
|
'companyId',
|
||||||
'callerId',
|
'callerId',
|
||||||
'sessionId',
|
'sessionId',
|
||||||
'operation',
|
'operation',
|
||||||
])
|
])
|
||||||
|
|
||||||
const apiOperation = await API_Operation.create({
|
const apiOperation = await API_Operation.create({
|
||||||
|
@ -236,7 +176,7 @@ const registerAll = async (req, res) => {
|
||||||
provider: provider.trim().toLowerCase(),
|
provider: provider.trim().toLowerCase(),
|
||||||
product: product.trim().toLowerCase(),
|
product: product.trim().toLowerCase(),
|
||||||
callerId,
|
callerId,
|
||||||
sessionId,
|
sessionId,
|
||||||
usage,
|
usage,
|
||||||
price,
|
price,
|
||||||
billingBy,
|
billingBy,
|
||||||
|
@ -283,7 +223,7 @@ const registerAll = async (req, res) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res.send(StatusCodes.OK)
|
res.send(StatusCodes.OK)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getUsage = async (req, res) => {
|
const getUsage = async (req, res) => {
|
||||||
|
@ -315,6 +255,5 @@ module.exports = {
|
||||||
registerAPICall,
|
registerAPICall,
|
||||||
registerOperation,
|
registerOperation,
|
||||||
getUsage,
|
getUsage,
|
||||||
registerAll,
|
registerAll
|
||||||
registerWhatsappUsage
|
|
||||||
}
|
}
|
|
@ -19,10 +19,10 @@ const apiPricing = new Schema({
|
||||||
price: {
|
price: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
billingBy:{
|
billingBy:{
|
||||||
type: String,
|
type: String,
|
||||||
enum: ['minute', 'character', 'token', 'second', 'hour'],
|
enum: ['minute', 'character', 'token', 'second'],
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
billingUnit:{
|
billingUnit:{
|
||||||
|
@ -30,7 +30,8 @@ const apiPricing = new Schema({
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
|
enum: ['input', 'output',],
|
||||||
}
|
}
|
||||||
|
|
||||||
}, { timestamps: true })
|
}, { timestamps: true })
|
||||||
|
|
|
@ -14,7 +14,34 @@ const apiUsage = new Schema({
|
||||||
sessionId: {
|
sessionId: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
// quantityOfOperationAttempts: {
|
||||||
|
// type: String,
|
||||||
|
// required: true,
|
||||||
|
// },
|
||||||
|
// chosenOperation: {
|
||||||
|
// type: String,
|
||||||
|
// required: true,
|
||||||
|
// },
|
||||||
|
// requestLogsOpenAI: {
|
||||||
|
// type: String,
|
||||||
|
// required: true,
|
||||||
|
// },
|
||||||
|
// responseErrorLogsOpenAI: {
|
||||||
|
// type: String,
|
||||||
|
// },
|
||||||
|
// quantityOfCallsToFalconFlowAPI: {
|
||||||
|
// type: String,
|
||||||
|
// required: true,
|
||||||
|
// },
|
||||||
|
// requestLogsFalconFlowAPI: {
|
||||||
|
// type: String,
|
||||||
|
// required: true,
|
||||||
|
// },
|
||||||
|
// responseErrorLogsFalconFlowAPI: {
|
||||||
|
// type: String,
|
||||||
|
// required: true,
|
||||||
|
// },
|
||||||
provider: {
|
provider: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
const mongoose = require('../db/connect')
|
|
||||||
|
|
||||||
const { Schema } = mongoose
|
|
||||||
|
|
||||||
const apiUsageWhatsapp = new Schema({
|
|
||||||
companyId: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
msgId: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
ticketId: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
provider: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
product: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
price: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
billable: {
|
|
||||||
type: String,
|
|
||||||
require: true
|
|
||||||
},
|
|
||||||
pricing_model: {
|
|
||||||
type: String,
|
|
||||||
default: true
|
|
||||||
},
|
|
||||||
type: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
|
|
||||||
}, { timestamps: true })
|
|
||||||
|
|
||||||
const API_Usage_Whatsapp = mongoose.model('API_Usage_Whatsapp', apiUsageWhatsapp)
|
|
||||||
|
|
||||||
module.exports = API_Usage_Whatsapp
|
|
|
@ -1,17 +1,10 @@
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
const { authorization, } = require('../middleware/authentication')
|
const { authorization, } = require('../middleware/authentication')
|
||||||
const { setApiPricing,
|
const { setApiPricing, registerUsage, getUsage, registerAPICall, registerOperation, registerAll} = require('../controllers/apiUsagePricing')
|
||||||
registerUsage,
|
|
||||||
getUsage,
|
|
||||||
registerAPICall,
|
|
||||||
registerOperation,
|
|
||||||
registerAll,
|
|
||||||
registerWhatsappUsage} = require('../controllers/apiUsagePricing')
|
|
||||||
|
|
||||||
router.route('/create').post(authorization, setApiPricing)
|
router.route('/create').post(authorization, setApiPricing)
|
||||||
router.route('/usage').post(authorization, registerUsage)
|
router.route('/usage').post(authorization, registerUsage)
|
||||||
router.route('/usage-whatsapp').post(authorization, registerWhatsappUsage)
|
|
||||||
router.route('/report').post(authorization, getUsage)
|
router.route('/report').post(authorization, getUsage)
|
||||||
router.route('/api-call').post(authorization, registerAPICall)
|
router.route('/api-call').post(authorization, registerAPICall)
|
||||||
router.route('/api-operation').post(authorization, registerOperation)
|
router.route('/api-operation').post(authorization, registerOperation)
|
||||||
|
|
Loading…
Reference in New Issue