Compare commits
5 Commits
a7847185fd
...
990c6457fe
| Author | SHA1 | Date |
|---|---|---|
|
|
990c6457fe | |
|
|
6b9100fd2e | |
|
|
71f626af98 | |
|
|
1e0f7e0a7d | |
|
|
5e6e5cd8a7 |
|
|
@ -28,6 +28,10 @@ const setApiPricing = async (req, res) => {
|
|||
|
||||
let filter = { provider: normalizedProvider, product: normalizedProduct }
|
||||
|
||||
if(format){
|
||||
filter = {...filter, format}
|
||||
}
|
||||
|
||||
if (type) {
|
||||
filter = { ...filter, type }
|
||||
}
|
||||
|
|
@ -197,7 +201,8 @@ const registerUsage = async (req, res) => {
|
|||
callerId,
|
||||
sessionId,
|
||||
companyId,
|
||||
format
|
||||
format,
|
||||
usedTo
|
||||
|
||||
} = req.body
|
||||
|
||||
|
|
@ -213,6 +218,7 @@ const registerUsage = async (req, res) => {
|
|||
const apiPricing = await API_Pricing.findOne({
|
||||
provider: provider.trim().toLowerCase(),
|
||||
product: product.trim().toLowerCase(),
|
||||
format: format?.trim().toLowerCase()
|
||||
})
|
||||
|
||||
if (apiPricing) {
|
||||
|
|
@ -230,7 +236,8 @@ const registerUsage = async (req, res) => {
|
|||
billingUnit,
|
||||
companyId,
|
||||
total_cost: calculateApiUsage(price, billingUnit, usage),
|
||||
format
|
||||
format,
|
||||
usedTo
|
||||
})
|
||||
|
||||
return res.status(StatusCodes.OK).json({ apiUsage })
|
||||
|
|
|
|||
|
|
@ -1,51 +1,61 @@
|
|||
const mongoose = require('../db/connect')
|
||||
const mongoose = require("../db/connect");
|
||||
|
||||
const { Schema } = mongoose
|
||||
const { Schema } = mongoose;
|
||||
|
||||
const apiUsage = new Schema({
|
||||
const apiUsage = new Schema(
|
||||
{
|
||||
companyId: {
|
||||
type: String,
|
||||
required: true,
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
callerId: {
|
||||
type: String,
|
||||
required: true,
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
sessionId: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
provider: {
|
||||
type: String,
|
||||
required: true,
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
product: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
usage: {
|
||||
type: String,
|
||||
required: true
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
price: {
|
||||
type: String,
|
||||
required: true
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
billingBy: {
|
||||
type: String,
|
||||
required: true,
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
billingUnit: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
total_cost: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
format: {
|
||||
type: String,
|
||||
enum: ["text", "audio", "image", "video"],
|
||||
},
|
||||
usedTo: {
|
||||
type: String,
|
||||
enum: ["stt", "llm", "tts"],
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
}, { timestamps: true })
|
||||
|
||||
const API_Usage = mongoose.model('API_Usage', apiUsage)
|
||||
const API_Usage = mongoose.model("API_Usage", apiUsage);
|
||||
|
||||
module.exports = API_Usage
|
||||
module.exports = API_Usage;
|
||||
|
|
|
|||
Loading…
Reference in New Issue