feat: added routes to insert all informations
parent
14c0303c78
commit
f26045a038
|
@ -47,16 +47,14 @@ const registerUsage = async (req, res) => {
|
|||
usage,
|
||||
callerId,
|
||||
sessionId,
|
||||
companyId,
|
||||
quantityOfOperationAttempts,
|
||||
companyId,
|
||||
|
||||
} = req.body
|
||||
|
||||
mustContainProperties(req, [
|
||||
'companyId',
|
||||
'callerId',
|
||||
'sessionId',
|
||||
'quantityOfOperationAttempts',
|
||||
'sessionId',
|
||||
'provider',
|
||||
'product',
|
||||
'usage',
|
||||
|
@ -75,8 +73,7 @@ const registerUsage = async (req, res) => {
|
|||
provider: provider.trim().toLowerCase(),
|
||||
product: product.trim().toLowerCase(),
|
||||
callerId,
|
||||
sessionId,
|
||||
quantityOfOperationAttempts,
|
||||
sessionId,
|
||||
usage,
|
||||
price,
|
||||
billingBy,
|
||||
|
@ -130,25 +127,105 @@ const registerOperation = async (req, res) => {
|
|||
companyId,
|
||||
sessionId,
|
||||
operation,
|
||||
quantityOfOperationAttempts: quantityOfAttempts,
|
||||
} = req.body
|
||||
|
||||
|
||||
mustContainProperties(req, [
|
||||
'companyId',
|
||||
'callerId',
|
||||
'sessionId',
|
||||
'operation'
|
||||
'operation',
|
||||
])
|
||||
|
||||
const apiOperation = await API_Operation.create({
|
||||
callerId,
|
||||
companyId,
|
||||
sessionId,
|
||||
operation
|
||||
operation,
|
||||
quantityOfAttempts
|
||||
})
|
||||
|
||||
res.status(StatusCodes.OK).json({ apiOperation })
|
||||
}
|
||||
|
||||
const registerAll = async (req, res) => {
|
||||
const {
|
||||
callerId,
|
||||
companyId,
|
||||
sessionId,
|
||||
lstUsage,
|
||||
lstRequest,
|
||||
lstOperation,
|
||||
} = req.body
|
||||
|
||||
if (lstUsage) {
|
||||
for (const used of lstUsage) {
|
||||
|
||||
const { product, provider, usage } = used
|
||||
|
||||
const apiPricing = await API_Pricing.findOne({
|
||||
provider: provider.trim().toLowerCase(),
|
||||
product: product.trim().toLowerCase(),
|
||||
})
|
||||
|
||||
if (apiPricing) {
|
||||
|
||||
const { price, billingBy, billingUnit } = apiPricing
|
||||
|
||||
const apiUsage = await API_Usage.create({
|
||||
provider: provider.trim().toLowerCase(),
|
||||
product: product.trim().toLowerCase(),
|
||||
callerId,
|
||||
sessionId,
|
||||
usage,
|
||||
price,
|
||||
billingBy,
|
||||
billingUnit,
|
||||
companyId,
|
||||
total_cost: calculateApiUsage(price, billingUnit, usage, billingBy)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (lstRequest) {
|
||||
for (const request of lstRequest) {
|
||||
|
||||
const { type,
|
||||
requestLogs,
|
||||
responseError,
|
||||
quantityOfAPICall } = request
|
||||
|
||||
const apiCall = await API_Call.create({
|
||||
callerId,
|
||||
companyId,
|
||||
sessionId,
|
||||
type,
|
||||
requestLogs,
|
||||
responseError,
|
||||
quantityOfAPICall
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
if (lstOperation) {
|
||||
for (const op of lstOperation) {
|
||||
const { operation, quantityOfOperationAttempts: quantityOfAttempts } = op
|
||||
|
||||
const apiOperation = await API_Operation.create({
|
||||
callerId,
|
||||
companyId,
|
||||
sessionId,
|
||||
operation,
|
||||
quantityOfAttempts
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
res.send(StatusCodes.OK)
|
||||
}
|
||||
|
||||
const getUsage = async (req, res) => {
|
||||
|
||||
const { startDate, endDate, companyId, } = req.body
|
||||
|
@ -177,5 +254,6 @@ module.exports = {
|
|||
registerUsage,
|
||||
registerAPICall,
|
||||
registerOperation,
|
||||
getUsage
|
||||
getUsage,
|
||||
registerAll
|
||||
}
|
|
@ -19,6 +19,10 @@ const apiOperation = new Schema({
|
|||
type: String,
|
||||
required: true,
|
||||
},
|
||||
quantityOfAttempts: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
|
||||
}, { timestamps: true })
|
||||
|
||||
|
|
|
@ -15,10 +15,10 @@ const apiUsage = new Schema({
|
|||
type: String,
|
||||
required: true,
|
||||
},
|
||||
quantityOfOperationAttempts: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
// quantityOfOperationAttempts: {
|
||||
// type: String,
|
||||
// required: true,
|
||||
// },
|
||||
// chosenOperation: {
|
||||
// type: String,
|
||||
// required: true,
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
const express = require('express')
|
||||
const router = express.Router()
|
||||
const { authorization, } = require('../middleware/authentication')
|
||||
const { setApiPricing, registerUsage, getUsage, registerAPICall, registerOperation} = require('../controllers/apiUsagePricing')
|
||||
const { setApiPricing, registerUsage, getUsage, registerAPICall, registerOperation, registerAll} = require('../controllers/apiUsagePricing')
|
||||
|
||||
router.route('/create').post(authorization, setApiPricing)
|
||||
router.route('/usage').post(authorization, registerUsage)
|
||||
router.route('/report').post(authorization, getUsage)
|
||||
router.route('/api-call').post(authorization, registerAPICall)
|
||||
router.route('/api-operation').post(authorization, registerOperation)
|
||||
router.route('/api-register-all').post(authorization, registerAll)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue