Skip to main content
Version: 1.0.0

Contatori_Brand

Purpose​

The Contatori_Brand collection tracks and monitors bandwidth consumption and usage metrics for different services within the ARShades ecosystem. Each document represents a brand's or client's consumption data, storing monthly bandwidth usage, API call counts, and usage limits across various ARShades services including 3D viewer, web VTO (Virtual Try-On), and other platform services. This collection is essential for billing calculations, usage monitoring, quota enforcement, and analytics reporting.

Document schema​

{
"bandwidth_3dviewer": [
{
"bandwidth_month": "number",
"calls_number": "number",
"month": "number",
"year": "number"
}
],
"bandwidth_array": [
{
"bandwidth_month": "number",
"calls_number": "number",
"month": "number",
"year": "number"
}
],
"bandwidth_limit_month": "number",
"bandwidth_webVto": [
{
"bandwidth_month": "number",
"calls_number": "number",
"month": "number",
"year": "number"
}
]
}

Indexes​

This collection does not have external indexes.

Query examples​

// Get the Document ID from the Catalogue Reference Doc
const catalogRefSnap = await getDoc(catalogRefDoc);
const dataDoc = catalogRefSnap.data()?.dataConsumption;

if (dataDoc) {
// Fetch the Contatori_Brand document using the ID (dataDoc)
const countersRef = doc(db, "Contatori_Brand", dataDoc);

// Retrieve the Document Snapshot from the Contatori_Brand reference
const countersRefSnap = await getDoc(countersRef);
}

// --------------------------------------------------------------------------

// Atomically update bandwidth usage using Firebase Transactions (e.g., for the 3D Viewer)
const countersRef = doc(db, "Contatori_Brand", dataDoc);
try {
await runTransaction(db, async (transaction) => {
// Get the Document Snapshot from the reference
const countersRefSnap = await transaction.get(countersRef);

// Check if the document exists
if (!countersRefSnap.exists()) {
console.error("Error: dataConsumption not found!");
return; // Exit the transaction
}

// Check for the presence of the bandwidth_3dviewer field
const currentData = countersRefSnap.data();
if (!currentData.bandwidth_3dviewer) {
console.error("Error: bandwidth_3dviewer field not found!");
return; // Exit the transaction
}

// Find the data for the current month and year,
// and increment bandwidth_month and calls_number accordingly
const updatedBandwidth = currentData.bandwidth_3dviewer.map((ele) => {
if (currentMonth === ele.month && year === ele.year) {
return {
bandwidth_month: ele.bandwidth_month + consumedBandwidth,
calls_number: ele.calls_number + 1,
month: ele.month,
year: ele.year,
};
}
return ele;
});

// Atomically update the counters
transaction.update(countersRef, {
bandwidth_3dviewer: updatedBandwidth,
});
});
} catch (error) {
console.error(error);
}