@blackcode_sa/metaestetics-api 1.12.42 → 1.12.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/index.d.mts +6 -12
- package/dist/admin/index.d.ts +6 -12
- package/dist/backoffice/index.d.mts +18 -182
- package/dist/backoffice/index.d.ts +18 -182
- package/dist/backoffice/index.js +14 -302
- package/dist/backoffice/index.mjs +27 -318
- package/dist/index.d.mts +10 -174
- package/dist/index.d.ts +10 -174
- package/dist/index.js +32 -309
- package/dist/index.mjs +40 -320
- package/package.json +1 -1
- package/src/backoffice/services/product.service.ts +18 -216
- package/src/backoffice/services/technology.service.ts +0 -169
- package/src/backoffice/types/product.types.ts +6 -116
- package/src/services/appointment/utils/zone-management.utils.ts +17 -3
- package/src/backoffice/services/migrate-products.ts +0 -116
package/dist/backoffice/index.js
CHANGED
|
@@ -1193,14 +1193,7 @@ var TECHNOLOGIES_COLLECTION = "technologies";
|
|
|
1193
1193
|
// src/backoffice/services/product.service.ts
|
|
1194
1194
|
var ProductService = class extends BaseService {
|
|
1195
1195
|
/**
|
|
1196
|
-
* Gets reference to
|
|
1197
|
-
* @returns Firestore collection reference
|
|
1198
|
-
*/
|
|
1199
|
-
getTopLevelProductsRef() {
|
|
1200
|
-
return (0, import_firestore8.collection)(this.db, PRODUCTS_COLLECTION);
|
|
1201
|
-
}
|
|
1202
|
-
/**
|
|
1203
|
-
* Gets reference to products collection under a technology (backward compatibility)
|
|
1196
|
+
* Gets reference to products collection under a technology
|
|
1204
1197
|
* @param technologyId - ID of the technology
|
|
1205
1198
|
* @returns Firestore collection reference
|
|
1206
1199
|
*/
|
|
@@ -1216,7 +1209,6 @@ var ProductService = class extends BaseService {
|
|
|
1216
1209
|
...product,
|
|
1217
1210
|
brandId,
|
|
1218
1211
|
technologyId,
|
|
1219
|
-
// Required for old subcollection structure
|
|
1220
1212
|
createdAt: now,
|
|
1221
1213
|
updatedAt: now,
|
|
1222
1214
|
isActive: true
|
|
@@ -1276,26 +1268,30 @@ var ProductService = class extends BaseService {
|
|
|
1276
1268
|
}
|
|
1277
1269
|
/**
|
|
1278
1270
|
* Gets counts of active products grouped by category, subcategory, and technology.
|
|
1279
|
-
*
|
|
1271
|
+
* This uses a single collectionGroup query for efficiency.
|
|
1280
1272
|
*/
|
|
1281
1273
|
async getProductCounts() {
|
|
1274
|
+
const q = (0, import_firestore8.query)((0, import_firestore8.collectionGroup)(this.db, PRODUCTS_COLLECTION), (0, import_firestore8.where)("isActive", "==", true));
|
|
1275
|
+
const snapshot = await (0, import_firestore8.getDocs)(q);
|
|
1282
1276
|
const counts = {
|
|
1283
1277
|
byCategory: {},
|
|
1284
1278
|
bySubcategory: {},
|
|
1285
1279
|
byTechnology: {}
|
|
1286
1280
|
};
|
|
1287
|
-
|
|
1288
|
-
|
|
1281
|
+
if (snapshot.empty) {
|
|
1282
|
+
return counts;
|
|
1283
|
+
}
|
|
1289
1284
|
snapshot.docs.forEach((doc11) => {
|
|
1290
1285
|
const product = doc11.data();
|
|
1291
|
-
|
|
1292
|
-
|
|
1286
|
+
const { categoryId, subcategoryId, technologyId } = product;
|
|
1287
|
+
if (categoryId) {
|
|
1288
|
+
counts.byCategory[categoryId] = (counts.byCategory[categoryId] || 0) + 1;
|
|
1293
1289
|
}
|
|
1294
|
-
if (
|
|
1295
|
-
counts.bySubcategory[
|
|
1290
|
+
if (subcategoryId) {
|
|
1291
|
+
counts.bySubcategory[subcategoryId] = (counts.bySubcategory[subcategoryId] || 0) + 1;
|
|
1296
1292
|
}
|
|
1297
|
-
if (
|
|
1298
|
-
counts.byTechnology[
|
|
1293
|
+
if (technologyId) {
|
|
1294
|
+
counts.byTechnology[technologyId] = (counts.byTechnology[technologyId] || 0) + 1;
|
|
1299
1295
|
}
|
|
1300
1296
|
});
|
|
1301
1297
|
return counts;
|
|
@@ -1374,160 +1370,6 @@ var ProductService = class extends BaseService {
|
|
|
1374
1370
|
...docSnap.data()
|
|
1375
1371
|
};
|
|
1376
1372
|
}
|
|
1377
|
-
// ==========================================
|
|
1378
|
-
// NEW METHODS: Top-level collection (preferred)
|
|
1379
|
-
// ==========================================
|
|
1380
|
-
/**
|
|
1381
|
-
* Creates a new product in the top-level collection
|
|
1382
|
-
*/
|
|
1383
|
-
async createTopLevel(brandId, product, technologyIds = []) {
|
|
1384
|
-
const now = /* @__PURE__ */ new Date();
|
|
1385
|
-
const newProduct = {
|
|
1386
|
-
...product,
|
|
1387
|
-
brandId,
|
|
1388
|
-
assignedTechnologyIds: technologyIds,
|
|
1389
|
-
createdAt: now,
|
|
1390
|
-
updatedAt: now,
|
|
1391
|
-
isActive: true
|
|
1392
|
-
};
|
|
1393
|
-
const productRef = await (0, import_firestore8.addDoc)(this.getTopLevelProductsRef(), newProduct);
|
|
1394
|
-
return { id: productRef.id, ...newProduct };
|
|
1395
|
-
}
|
|
1396
|
-
/**
|
|
1397
|
-
* Gets all products from the top-level collection
|
|
1398
|
-
*/
|
|
1399
|
-
async getAllTopLevel(options) {
|
|
1400
|
-
const { rowsPerPage, lastVisible, brandId } = options;
|
|
1401
|
-
const constraints = [(0, import_firestore8.where)("isActive", "==", true), (0, import_firestore8.orderBy)("name")];
|
|
1402
|
-
if (brandId) {
|
|
1403
|
-
constraints.push((0, import_firestore8.where)("brandId", "==", brandId));
|
|
1404
|
-
}
|
|
1405
|
-
if (lastVisible) {
|
|
1406
|
-
constraints.push((0, import_firestore8.startAfter)(lastVisible));
|
|
1407
|
-
}
|
|
1408
|
-
constraints.push((0, import_firestore8.limit)(rowsPerPage));
|
|
1409
|
-
const q = (0, import_firestore8.query)(this.getTopLevelProductsRef(), ...constraints);
|
|
1410
|
-
const snapshot = await (0, import_firestore8.getDocs)(q);
|
|
1411
|
-
const products = snapshot.docs.map(
|
|
1412
|
-
(doc11) => ({
|
|
1413
|
-
id: doc11.id,
|
|
1414
|
-
...doc11.data()
|
|
1415
|
-
})
|
|
1416
|
-
);
|
|
1417
|
-
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
1418
|
-
return { products, lastVisible: newLastVisible };
|
|
1419
|
-
}
|
|
1420
|
-
/**
|
|
1421
|
-
* Gets a product by ID from the top-level collection
|
|
1422
|
-
*/
|
|
1423
|
-
async getByIdTopLevel(productId) {
|
|
1424
|
-
const docRef = (0, import_firestore8.doc)(this.getTopLevelProductsRef(), productId);
|
|
1425
|
-
const docSnap = await (0, import_firestore8.getDoc)(docRef);
|
|
1426
|
-
if (!docSnap.exists()) return null;
|
|
1427
|
-
return {
|
|
1428
|
-
id: docSnap.id,
|
|
1429
|
-
...docSnap.data()
|
|
1430
|
-
};
|
|
1431
|
-
}
|
|
1432
|
-
/**
|
|
1433
|
-
* Updates a product in the top-level collection
|
|
1434
|
-
*/
|
|
1435
|
-
async updateTopLevel(productId, product) {
|
|
1436
|
-
const updateData = {
|
|
1437
|
-
...product,
|
|
1438
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
1439
|
-
};
|
|
1440
|
-
const docRef = (0, import_firestore8.doc)(this.getTopLevelProductsRef(), productId);
|
|
1441
|
-
await (0, import_firestore8.updateDoc)(docRef, updateData);
|
|
1442
|
-
return this.getByIdTopLevel(productId);
|
|
1443
|
-
}
|
|
1444
|
-
/**
|
|
1445
|
-
* Deletes a product from the top-level collection (soft delete)
|
|
1446
|
-
*/
|
|
1447
|
-
async deleteTopLevel(productId) {
|
|
1448
|
-
await this.updateTopLevel(productId, {
|
|
1449
|
-
isActive: false
|
|
1450
|
-
});
|
|
1451
|
-
}
|
|
1452
|
-
/**
|
|
1453
|
-
* Assigns a product to a technology
|
|
1454
|
-
*/
|
|
1455
|
-
async assignToTechnology(productId, technologyId) {
|
|
1456
|
-
const docRef = (0, import_firestore8.doc)(this.getTopLevelProductsRef(), productId);
|
|
1457
|
-
await (0, import_firestore8.updateDoc)(docRef, {
|
|
1458
|
-
assignedTechnologyIds: (0, import_firestore8.arrayUnion)(technologyId),
|
|
1459
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
1460
|
-
});
|
|
1461
|
-
}
|
|
1462
|
-
/**
|
|
1463
|
-
* Unassigns a product from a technology
|
|
1464
|
-
*/
|
|
1465
|
-
async unassignFromTechnology(productId, technologyId) {
|
|
1466
|
-
const docRef = (0, import_firestore8.doc)(this.getTopLevelProductsRef(), productId);
|
|
1467
|
-
await (0, import_firestore8.updateDoc)(docRef, {
|
|
1468
|
-
assignedTechnologyIds: (0, import_firestore8.arrayRemove)(technologyId),
|
|
1469
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
1470
|
-
});
|
|
1471
|
-
}
|
|
1472
|
-
/**
|
|
1473
|
-
* Gets products assigned to a specific technology
|
|
1474
|
-
*/
|
|
1475
|
-
async getAssignedProducts(technologyId) {
|
|
1476
|
-
const q = (0, import_firestore8.query)(
|
|
1477
|
-
this.getTopLevelProductsRef(),
|
|
1478
|
-
(0, import_firestore8.where)("assignedTechnologyIds", "array-contains", technologyId),
|
|
1479
|
-
(0, import_firestore8.where)("isActive", "==", true),
|
|
1480
|
-
(0, import_firestore8.orderBy)("name")
|
|
1481
|
-
);
|
|
1482
|
-
const snapshot = await (0, import_firestore8.getDocs)(q);
|
|
1483
|
-
return snapshot.docs.map(
|
|
1484
|
-
(doc11) => ({
|
|
1485
|
-
id: doc11.id,
|
|
1486
|
-
...doc11.data()
|
|
1487
|
-
})
|
|
1488
|
-
);
|
|
1489
|
-
}
|
|
1490
|
-
/**
|
|
1491
|
-
* Gets products NOT assigned to a specific technology
|
|
1492
|
-
*/
|
|
1493
|
-
async getUnassignedProducts(technologyId) {
|
|
1494
|
-
const q = (0, import_firestore8.query)(
|
|
1495
|
-
this.getTopLevelProductsRef(),
|
|
1496
|
-
(0, import_firestore8.where)("isActive", "==", true),
|
|
1497
|
-
(0, import_firestore8.orderBy)("name")
|
|
1498
|
-
);
|
|
1499
|
-
const snapshot = await (0, import_firestore8.getDocs)(q);
|
|
1500
|
-
const allProducts = snapshot.docs.map(
|
|
1501
|
-
(doc11) => ({
|
|
1502
|
-
id: doc11.id,
|
|
1503
|
-
...doc11.data()
|
|
1504
|
-
})
|
|
1505
|
-
);
|
|
1506
|
-
return allProducts.filter(
|
|
1507
|
-
(product) => {
|
|
1508
|
-
var _a;
|
|
1509
|
-
return !((_a = product.assignedTechnologyIds) == null ? void 0 : _a.includes(technologyId));
|
|
1510
|
-
}
|
|
1511
|
-
);
|
|
1512
|
-
}
|
|
1513
|
-
/**
|
|
1514
|
-
* Gets all products for a brand (from top-level collection)
|
|
1515
|
-
*/
|
|
1516
|
-
async getByBrand(brandId) {
|
|
1517
|
-
const q = (0, import_firestore8.query)(
|
|
1518
|
-
this.getTopLevelProductsRef(),
|
|
1519
|
-
(0, import_firestore8.where)("brandId", "==", brandId),
|
|
1520
|
-
(0, import_firestore8.where)("isActive", "==", true),
|
|
1521
|
-
(0, import_firestore8.orderBy)("name")
|
|
1522
|
-
);
|
|
1523
|
-
const snapshot = await (0, import_firestore8.getDocs)(q);
|
|
1524
|
-
return snapshot.docs.map(
|
|
1525
|
-
(doc11) => ({
|
|
1526
|
-
id: doc11.id,
|
|
1527
|
-
...doc11.data()
|
|
1528
|
-
})
|
|
1529
|
-
);
|
|
1530
|
-
}
|
|
1531
1373
|
};
|
|
1532
1374
|
|
|
1533
1375
|
// src/backoffice/services/requirement.service.ts
|
|
@@ -2069,18 +1911,7 @@ var TechnologyService = class extends BaseService {
|
|
|
2069
1911
|
});
|
|
2070
1912
|
updateData.updatedAt = /* @__PURE__ */ new Date();
|
|
2071
1913
|
const docRef = (0, import_firestore11.doc)(this.technologiesRef, id);
|
|
2072
|
-
const beforeTech = await this.getById(id);
|
|
2073
1914
|
await (0, import_firestore11.updateDoc)(docRef, updateData);
|
|
2074
|
-
const categoryChanged = beforeTech && updateData.categoryId && beforeTech.categoryId !== updateData.categoryId;
|
|
2075
|
-
const subcategoryChanged = beforeTech && updateData.subcategoryId && beforeTech.subcategoryId !== updateData.subcategoryId;
|
|
2076
|
-
const nameChanged = beforeTech && updateData.name && beforeTech.name !== updateData.name;
|
|
2077
|
-
if (categoryChanged || subcategoryChanged || nameChanged) {
|
|
2078
|
-
await this.updateProductsInSubcollection(id, {
|
|
2079
|
-
categoryId: updateData.categoryId,
|
|
2080
|
-
subcategoryId: updateData.subcategoryId,
|
|
2081
|
-
technologyName: updateData.name
|
|
2082
|
-
});
|
|
2083
|
-
}
|
|
2084
1915
|
return this.getById(id);
|
|
2085
1916
|
}
|
|
2086
1917
|
/**
|
|
@@ -2516,125 +2347,6 @@ var TechnologyService = class extends BaseService {
|
|
|
2516
2347
|
})
|
|
2517
2348
|
);
|
|
2518
2349
|
}
|
|
2519
|
-
// ==========================================
|
|
2520
|
-
// NEW METHODS: Product assignment management
|
|
2521
|
-
// ==========================================
|
|
2522
|
-
/**
|
|
2523
|
-
* Assigns multiple products to a technology
|
|
2524
|
-
* Updates each product's assignedTechnologyIds array
|
|
2525
|
-
*/
|
|
2526
|
-
async assignProducts(technologyId, productIds) {
|
|
2527
|
-
const batch = (0, import_firestore11.writeBatch)(this.db);
|
|
2528
|
-
for (const productId of productIds) {
|
|
2529
|
-
const productRef = (0, import_firestore11.doc)(this.db, PRODUCTS_COLLECTION, productId);
|
|
2530
|
-
batch.update(productRef, {
|
|
2531
|
-
assignedTechnologyIds: (0, import_firestore11.arrayUnion)(technologyId),
|
|
2532
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
2533
|
-
});
|
|
2534
|
-
}
|
|
2535
|
-
await batch.commit();
|
|
2536
|
-
}
|
|
2537
|
-
/**
|
|
2538
|
-
* Unassigns multiple products from a technology
|
|
2539
|
-
* Updates each product's assignedTechnologyIds array
|
|
2540
|
-
*/
|
|
2541
|
-
async unassignProducts(technologyId, productIds) {
|
|
2542
|
-
const batch = (0, import_firestore11.writeBatch)(this.db);
|
|
2543
|
-
for (const productId of productIds) {
|
|
2544
|
-
const productRef = (0, import_firestore11.doc)(this.db, PRODUCTS_COLLECTION, productId);
|
|
2545
|
-
batch.update(productRef, {
|
|
2546
|
-
assignedTechnologyIds: (0, import_firestore11.arrayRemove)(technologyId),
|
|
2547
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
2548
|
-
});
|
|
2549
|
-
}
|
|
2550
|
-
await batch.commit();
|
|
2551
|
-
}
|
|
2552
|
-
/**
|
|
2553
|
-
* Gets products assigned to a specific technology
|
|
2554
|
-
* Reads from top-level collection for immediate consistency (Cloud Functions may lag)
|
|
2555
|
-
*/
|
|
2556
|
-
async getAssignedProducts(technologyId) {
|
|
2557
|
-
const q = (0, import_firestore11.query)(
|
|
2558
|
-
(0, import_firestore11.collection)(this.db, PRODUCTS_COLLECTION),
|
|
2559
|
-
(0, import_firestore11.where)("assignedTechnologyIds", "array-contains", technologyId),
|
|
2560
|
-
(0, import_firestore11.where)("isActive", "==", true),
|
|
2561
|
-
(0, import_firestore11.orderBy)("name")
|
|
2562
|
-
);
|
|
2563
|
-
const snapshot = await (0, import_firestore11.getDocs)(q);
|
|
2564
|
-
return snapshot.docs.map(
|
|
2565
|
-
(doc11) => ({
|
|
2566
|
-
id: doc11.id,
|
|
2567
|
-
...doc11.data()
|
|
2568
|
-
})
|
|
2569
|
-
);
|
|
2570
|
-
}
|
|
2571
|
-
/**
|
|
2572
|
-
* Gets products NOT assigned to a specific technology
|
|
2573
|
-
*/
|
|
2574
|
-
async getUnassignedProducts(technologyId) {
|
|
2575
|
-
const q = (0, import_firestore11.query)(
|
|
2576
|
-
(0, import_firestore11.collection)(this.db, PRODUCTS_COLLECTION),
|
|
2577
|
-
(0, import_firestore11.where)("isActive", "==", true),
|
|
2578
|
-
(0, import_firestore11.orderBy)("name")
|
|
2579
|
-
);
|
|
2580
|
-
const snapshot = await (0, import_firestore11.getDocs)(q);
|
|
2581
|
-
const allProducts = snapshot.docs.map(
|
|
2582
|
-
(doc11) => ({
|
|
2583
|
-
id: doc11.id,
|
|
2584
|
-
...doc11.data()
|
|
2585
|
-
})
|
|
2586
|
-
);
|
|
2587
|
-
return allProducts.filter(
|
|
2588
|
-
(product) => {
|
|
2589
|
-
var _a;
|
|
2590
|
-
return !((_a = product.assignedTechnologyIds) == null ? void 0 : _a.includes(technologyId));
|
|
2591
|
-
}
|
|
2592
|
-
);
|
|
2593
|
-
}
|
|
2594
|
-
/**
|
|
2595
|
-
* Gets product assignment statistics for a technology
|
|
2596
|
-
*/
|
|
2597
|
-
async getProductStats(technologyId) {
|
|
2598
|
-
const products = await this.getAssignedProducts(technologyId);
|
|
2599
|
-
const byBrand = {};
|
|
2600
|
-
products.forEach((product) => {
|
|
2601
|
-
byBrand[product.brandName] = (byBrand[product.brandName] || 0) + 1;
|
|
2602
|
-
});
|
|
2603
|
-
return {
|
|
2604
|
-
totalAssigned: products.length,
|
|
2605
|
-
byBrand
|
|
2606
|
-
};
|
|
2607
|
-
}
|
|
2608
|
-
/**
|
|
2609
|
-
* Updates products in technology subcollection when technology metadata changes
|
|
2610
|
-
* @param technologyId - ID of the technology
|
|
2611
|
-
* @param updates - Fields to update (categoryId, subcategoryId, technologyName)
|
|
2612
|
-
*/
|
|
2613
|
-
async updateProductsInSubcollection(technologyId, updates) {
|
|
2614
|
-
const productsRef = (0, import_firestore11.collection)(this.db, TECHNOLOGIES_COLLECTION, technologyId, PRODUCTS_COLLECTION);
|
|
2615
|
-
const productsSnapshot = await (0, import_firestore11.getDocs)(productsRef);
|
|
2616
|
-
if (productsSnapshot.empty) {
|
|
2617
|
-
return;
|
|
2618
|
-
}
|
|
2619
|
-
const batch = (0, import_firestore11.writeBatch)(this.db);
|
|
2620
|
-
for (const productDoc of productsSnapshot.docs) {
|
|
2621
|
-
const productRef = productDoc.ref;
|
|
2622
|
-
const updateFields = {};
|
|
2623
|
-
if (updates.categoryId !== void 0) {
|
|
2624
|
-
updateFields.categoryId = updates.categoryId;
|
|
2625
|
-
}
|
|
2626
|
-
if (updates.subcategoryId !== void 0) {
|
|
2627
|
-
updateFields.subcategoryId = updates.subcategoryId;
|
|
2628
|
-
}
|
|
2629
|
-
if (updates.technologyName !== void 0) {
|
|
2630
|
-
updateFields.technologyName = updates.technologyName;
|
|
2631
|
-
}
|
|
2632
|
-
if (Object.keys(updateFields).length > 0) {
|
|
2633
|
-
batch.update(productRef, updateFields);
|
|
2634
|
-
}
|
|
2635
|
-
}
|
|
2636
|
-
await batch.commit();
|
|
2637
|
-
}
|
|
2638
2350
|
};
|
|
2639
2351
|
|
|
2640
2352
|
// src/backoffice/services/constants.service.ts
|