@blackcode_sa/metaestetics-api 1.5.12 → 1.5.13

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.
@@ -1327,9 +1327,15 @@ var RequirementService = class extends BaseService {
1327
1327
  // src/backoffice/services/brand.service.ts
1328
1328
  var import_firestore5 = require("firebase/firestore");
1329
1329
  var BrandService = class extends BaseService {
1330
- get brandsRef() {
1330
+ /**
1331
+ * Gets reference to brands collection
1332
+ */
1333
+ getBrandsRef() {
1331
1334
  return (0, import_firestore5.collection)(this.db, BRANDS_COLLECTION);
1332
1335
  }
1336
+ /**
1337
+ * Creates a new brand
1338
+ */
1333
1339
  async create(brand) {
1334
1340
  const now = /* @__PURE__ */ new Date();
1335
1341
  const newBrand = {
@@ -1338,11 +1344,14 @@ var BrandService = class extends BaseService {
1338
1344
  updatedAt: now,
1339
1345
  isActive: true
1340
1346
  };
1341
- const docRef = await (0, import_firestore5.addDoc)(this.brandsRef, newBrand);
1347
+ const docRef = await (0, import_firestore5.addDoc)(this.getBrandsRef(), newBrand);
1342
1348
  return { id: docRef.id, ...newBrand };
1343
1349
  }
1350
+ /**
1351
+ * Gets all active brands
1352
+ */
1344
1353
  async getAll() {
1345
- const q = (0, import_firestore5.query)(this.brandsRef, (0, import_firestore5.where)("isActive", "==", true));
1354
+ const q = (0, import_firestore5.query)(this.getBrandsRef(), (0, import_firestore5.where)("isActive", "==", true));
1346
1355
  const snapshot = await (0, import_firestore5.getDocs)(q);
1347
1356
  return snapshot.docs.map(
1348
1357
  (doc9) => ({
@@ -1351,20 +1360,31 @@ var BrandService = class extends BaseService {
1351
1360
  })
1352
1361
  );
1353
1362
  }
1354
- async update(id, brand) {
1363
+ /**
1364
+ * Updates a brand
1365
+ */
1366
+ async update(brandId, brand) {
1355
1367
  const updateData = {
1356
1368
  ...brand,
1357
1369
  updatedAt: /* @__PURE__ */ new Date()
1358
1370
  };
1359
- const docRef = (0, import_firestore5.doc)(this.brandsRef, id);
1371
+ const docRef = (0, import_firestore5.doc)(this.getBrandsRef(), brandId);
1360
1372
  await (0, import_firestore5.updateDoc)(docRef, updateData);
1361
- return this.getById(id);
1373
+ return this.getById(brandId);
1362
1374
  }
1363
- async delete(id) {
1364
- await this.update(id, { isActive: false });
1375
+ /**
1376
+ * Soft deletes a brand
1377
+ */
1378
+ async delete(brandId) {
1379
+ await this.update(brandId, {
1380
+ isActive: false
1381
+ });
1365
1382
  }
1366
- async getById(id) {
1367
- const docRef = (0, import_firestore5.doc)(this.brandsRef, id);
1383
+ /**
1384
+ * Gets a brand by ID
1385
+ */
1386
+ async getById(brandId) {
1387
+ const docRef = (0, import_firestore5.doc)(this.getBrandsRef(), brandId);
1368
1388
  const docSnap = await (0, import_firestore5.getDoc)(docRef);
1369
1389
  if (!docSnap.exists()) return null;
1370
1390
  return {
@@ -1377,22 +1397,23 @@ var BrandService = class extends BaseService {
1377
1397
  // src/backoffice/services/product.service.ts
1378
1398
  var import_firestore6 = require("firebase/firestore");
1379
1399
  var ProductService = class extends BaseService {
1380
- getProductsRefByTechnology(categoryId, subcategoryId, technologyId) {
1400
+ /**
1401
+ * Gets reference to products collection under a technology
1402
+ * @param technologyId - ID of the technology
1403
+ * @returns Firestore collection reference
1404
+ */
1405
+ getProductsRef(technologyId) {
1381
1406
  return (0, import_firestore6.collection)(
1382
1407
  this.db,
1383
- CATEGORIES_COLLECTION,
1384
- categoryId,
1385
- SUBCATEGORIES_COLLECTION,
1386
- subcategoryId,
1387
1408
  TECHNOLOGIES_COLLECTION,
1388
1409
  technologyId,
1389
1410
  PRODUCTS_COLLECTION
1390
1411
  );
1391
1412
  }
1392
- getProductsRefByBrand(brandId) {
1393
- return (0, import_firestore6.collection)(this.db, BRANDS_COLLECTION, brandId, PRODUCTS_COLLECTION);
1394
- }
1395
- async create(categoryId, subcategoryId, technologyId, brandId, product) {
1413
+ /**
1414
+ * Creates a new product under technology
1415
+ */
1416
+ async create(technologyId, brandId, product) {
1396
1417
  const now = /* @__PURE__ */ new Date();
1397
1418
  const newProduct = {
1398
1419
  ...product,
@@ -1402,23 +1423,18 @@ var ProductService = class extends BaseService {
1402
1423
  updatedAt: now,
1403
1424
  isActive: true
1404
1425
  };
1405
- const techProductRef = await (0, import_firestore6.addDoc)(
1406
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
1426
+ const productRef = await (0, import_firestore6.addDoc)(
1427
+ this.getProductsRef(technologyId),
1407
1428
  newProduct
1408
1429
  );
1409
- await (0, import_firestore6.addDoc)(this.getProductsRefByBrand(brandId), {
1410
- ...newProduct,
1411
- id: techProductRef.id,
1412
- // Store the original ID for reference
1413
- categoryId,
1414
- subcategoryId,
1415
- technologyId
1416
- });
1417
- return { id: techProductRef.id, ...newProduct };
1430
+ return { id: productRef.id, ...newProduct };
1418
1431
  }
1419
- async getAllByTechnology(categoryId, subcategoryId, technologyId) {
1432
+ /**
1433
+ * Gets all products for a technology
1434
+ */
1435
+ async getAllByTechnology(technologyId) {
1420
1436
  const q = (0, import_firestore6.query)(
1421
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
1437
+ this.getProductsRef(technologyId),
1422
1438
  (0, import_firestore6.where)("isActive", "==", true)
1423
1439
  );
1424
1440
  const snapshot = await (0, import_firestore6.getDocs)(q);
@@ -1429,49 +1445,56 @@ var ProductService = class extends BaseService {
1429
1445
  })
1430
1446
  );
1431
1447
  }
1448
+ /**
1449
+ * Gets all products for a brand by filtering through all technologies
1450
+ */
1432
1451
  async getAllByBrand(brandId) {
1433
- const q = (0, import_firestore6.query)(
1434
- this.getProductsRefByBrand(brandId),
1435
- (0, import_firestore6.where)("isActive", "==", true)
1436
- );
1437
- const snapshot = await (0, import_firestore6.getDocs)(q);
1438
- return snapshot.docs.map(
1439
- (doc9) => ({
1440
- id: doc9.id,
1441
- ...doc9.data()
1442
- })
1443
- );
1452
+ const allTechnologiesRef = (0, import_firestore6.collection)(this.db, TECHNOLOGIES_COLLECTION);
1453
+ const technologiesSnapshot = await (0, import_firestore6.getDocs)(allTechnologiesRef);
1454
+ const products = [];
1455
+ for (const techDoc of technologiesSnapshot.docs) {
1456
+ const q = (0, import_firestore6.query)(
1457
+ this.getProductsRef(techDoc.id),
1458
+ (0, import_firestore6.where)("brandId", "==", brandId),
1459
+ (0, import_firestore6.where)("isActive", "==", true)
1460
+ );
1461
+ const snapshot = await (0, import_firestore6.getDocs)(q);
1462
+ products.push(
1463
+ ...snapshot.docs.map(
1464
+ (doc9) => ({
1465
+ id: doc9.id,
1466
+ ...doc9.data()
1467
+ })
1468
+ )
1469
+ );
1470
+ }
1471
+ return products;
1444
1472
  }
1445
- async update(categoryId, subcategoryId, technologyId, productId, product) {
1473
+ /**
1474
+ * Updates a product
1475
+ */
1476
+ async update(technologyId, productId, product) {
1446
1477
  const updateData = {
1447
1478
  ...product,
1448
1479
  updatedAt: /* @__PURE__ */ new Date()
1449
1480
  };
1450
- const techDocRef = (0, import_firestore6.doc)(
1451
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
1452
- productId
1453
- );
1454
- await (0, import_firestore6.updateDoc)(techDocRef, updateData);
1455
- const brandProductsQuery = (0, import_firestore6.query)(
1456
- (0, import_firestore6.collectionGroup)(this.db, PRODUCTS_COLLECTION),
1457
- (0, import_firestore6.where)("id", "==", productId)
1458
- );
1459
- const brandProductsSnapshot = await (0, import_firestore6.getDocs)(brandProductsQuery);
1460
- for (const doc9 of brandProductsSnapshot.docs) {
1461
- await (0, import_firestore6.updateDoc)(doc9.ref, updateData);
1462
- }
1463
- return this.getById(categoryId, subcategoryId, technologyId, productId);
1481
+ const docRef = (0, import_firestore6.doc)(this.getProductsRef(technologyId), productId);
1482
+ await (0, import_firestore6.updateDoc)(docRef, updateData);
1483
+ return this.getById(technologyId, productId);
1464
1484
  }
1465
- async delete(categoryId, subcategoryId, technologyId, productId) {
1466
- await this.update(categoryId, subcategoryId, technologyId, productId, {
1485
+ /**
1486
+ * Soft deletes a product
1487
+ */
1488
+ async delete(technologyId, productId) {
1489
+ await this.update(technologyId, productId, {
1467
1490
  isActive: false
1468
1491
  });
1469
1492
  }
1470
- async getById(categoryId, subcategoryId, technologyId, productId) {
1471
- const docRef = (0, import_firestore6.doc)(
1472
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
1473
- productId
1474
- );
1493
+ /**
1494
+ * Gets a product by ID
1495
+ */
1496
+ async getById(technologyId, productId) {
1497
+ const docRef = (0, import_firestore6.doc)(this.getProductsRef(technologyId), productId);
1475
1498
  const docSnap = await (0, import_firestore6.getDoc)(docRef);
1476
1499
  if (!docSnap.exists()) return null;
1477
1500
  return {
@@ -1282,9 +1282,15 @@ import {
1282
1282
  where as where5
1283
1283
  } from "firebase/firestore";
1284
1284
  var BrandService = class extends BaseService {
1285
- get brandsRef() {
1285
+ /**
1286
+ * Gets reference to brands collection
1287
+ */
1288
+ getBrandsRef() {
1286
1289
  return collection5(this.db, BRANDS_COLLECTION);
1287
1290
  }
1291
+ /**
1292
+ * Creates a new brand
1293
+ */
1288
1294
  async create(brand) {
1289
1295
  const now = /* @__PURE__ */ new Date();
1290
1296
  const newBrand = {
@@ -1293,11 +1299,14 @@ var BrandService = class extends BaseService {
1293
1299
  updatedAt: now,
1294
1300
  isActive: true
1295
1301
  };
1296
- const docRef = await addDoc5(this.brandsRef, newBrand);
1302
+ const docRef = await addDoc5(this.getBrandsRef(), newBrand);
1297
1303
  return { id: docRef.id, ...newBrand };
1298
1304
  }
1305
+ /**
1306
+ * Gets all active brands
1307
+ */
1299
1308
  async getAll() {
1300
- const q = query5(this.brandsRef, where5("isActive", "==", true));
1309
+ const q = query5(this.getBrandsRef(), where5("isActive", "==", true));
1301
1310
  const snapshot = await getDocs5(q);
1302
1311
  return snapshot.docs.map(
1303
1312
  (doc9) => ({
@@ -1306,20 +1315,31 @@ var BrandService = class extends BaseService {
1306
1315
  })
1307
1316
  );
1308
1317
  }
1309
- async update(id, brand) {
1318
+ /**
1319
+ * Updates a brand
1320
+ */
1321
+ async update(brandId, brand) {
1310
1322
  const updateData = {
1311
1323
  ...brand,
1312
1324
  updatedAt: /* @__PURE__ */ new Date()
1313
1325
  };
1314
- const docRef = doc5(this.brandsRef, id);
1326
+ const docRef = doc5(this.getBrandsRef(), brandId);
1315
1327
  await updateDoc5(docRef, updateData);
1316
- return this.getById(id);
1328
+ return this.getById(brandId);
1317
1329
  }
1318
- async delete(id) {
1319
- await this.update(id, { isActive: false });
1330
+ /**
1331
+ * Soft deletes a brand
1332
+ */
1333
+ async delete(brandId) {
1334
+ await this.update(brandId, {
1335
+ isActive: false
1336
+ });
1320
1337
  }
1321
- async getById(id) {
1322
- const docRef = doc5(this.brandsRef, id);
1338
+ /**
1339
+ * Gets a brand by ID
1340
+ */
1341
+ async getById(brandId) {
1342
+ const docRef = doc5(this.getBrandsRef(), brandId);
1323
1343
  const docSnap = await getDoc5(docRef);
1324
1344
  if (!docSnap.exists()) return null;
1325
1345
  return {
@@ -1333,7 +1353,6 @@ var BrandService = class extends BaseService {
1333
1353
  import {
1334
1354
  addDoc as addDoc6,
1335
1355
  collection as collection6,
1336
- collectionGroup,
1337
1356
  doc as doc6,
1338
1357
  getDoc as getDoc6,
1339
1358
  getDocs as getDocs6,
@@ -1342,22 +1361,23 @@ import {
1342
1361
  where as where6
1343
1362
  } from "firebase/firestore";
1344
1363
  var ProductService = class extends BaseService {
1345
- getProductsRefByTechnology(categoryId, subcategoryId, technologyId) {
1364
+ /**
1365
+ * Gets reference to products collection under a technology
1366
+ * @param technologyId - ID of the technology
1367
+ * @returns Firestore collection reference
1368
+ */
1369
+ getProductsRef(technologyId) {
1346
1370
  return collection6(
1347
1371
  this.db,
1348
- CATEGORIES_COLLECTION,
1349
- categoryId,
1350
- SUBCATEGORIES_COLLECTION,
1351
- subcategoryId,
1352
1372
  TECHNOLOGIES_COLLECTION,
1353
1373
  technologyId,
1354
1374
  PRODUCTS_COLLECTION
1355
1375
  );
1356
1376
  }
1357
- getProductsRefByBrand(brandId) {
1358
- return collection6(this.db, BRANDS_COLLECTION, brandId, PRODUCTS_COLLECTION);
1359
- }
1360
- async create(categoryId, subcategoryId, technologyId, brandId, product) {
1377
+ /**
1378
+ * Creates a new product under technology
1379
+ */
1380
+ async create(technologyId, brandId, product) {
1361
1381
  const now = /* @__PURE__ */ new Date();
1362
1382
  const newProduct = {
1363
1383
  ...product,
@@ -1367,23 +1387,18 @@ var ProductService = class extends BaseService {
1367
1387
  updatedAt: now,
1368
1388
  isActive: true
1369
1389
  };
1370
- const techProductRef = await addDoc6(
1371
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
1390
+ const productRef = await addDoc6(
1391
+ this.getProductsRef(technologyId),
1372
1392
  newProduct
1373
1393
  );
1374
- await addDoc6(this.getProductsRefByBrand(brandId), {
1375
- ...newProduct,
1376
- id: techProductRef.id,
1377
- // Store the original ID for reference
1378
- categoryId,
1379
- subcategoryId,
1380
- technologyId
1381
- });
1382
- return { id: techProductRef.id, ...newProduct };
1394
+ return { id: productRef.id, ...newProduct };
1383
1395
  }
1384
- async getAllByTechnology(categoryId, subcategoryId, technologyId) {
1396
+ /**
1397
+ * Gets all products for a technology
1398
+ */
1399
+ async getAllByTechnology(technologyId) {
1385
1400
  const q = query6(
1386
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
1401
+ this.getProductsRef(technologyId),
1387
1402
  where6("isActive", "==", true)
1388
1403
  );
1389
1404
  const snapshot = await getDocs6(q);
@@ -1394,49 +1409,56 @@ var ProductService = class extends BaseService {
1394
1409
  })
1395
1410
  );
1396
1411
  }
1412
+ /**
1413
+ * Gets all products for a brand by filtering through all technologies
1414
+ */
1397
1415
  async getAllByBrand(brandId) {
1398
- const q = query6(
1399
- this.getProductsRefByBrand(brandId),
1400
- where6("isActive", "==", true)
1401
- );
1402
- const snapshot = await getDocs6(q);
1403
- return snapshot.docs.map(
1404
- (doc9) => ({
1405
- id: doc9.id,
1406
- ...doc9.data()
1407
- })
1408
- );
1416
+ const allTechnologiesRef = collection6(this.db, TECHNOLOGIES_COLLECTION);
1417
+ const technologiesSnapshot = await getDocs6(allTechnologiesRef);
1418
+ const products = [];
1419
+ for (const techDoc of technologiesSnapshot.docs) {
1420
+ const q = query6(
1421
+ this.getProductsRef(techDoc.id),
1422
+ where6("brandId", "==", brandId),
1423
+ where6("isActive", "==", true)
1424
+ );
1425
+ const snapshot = await getDocs6(q);
1426
+ products.push(
1427
+ ...snapshot.docs.map(
1428
+ (doc9) => ({
1429
+ id: doc9.id,
1430
+ ...doc9.data()
1431
+ })
1432
+ )
1433
+ );
1434
+ }
1435
+ return products;
1409
1436
  }
1410
- async update(categoryId, subcategoryId, technologyId, productId, product) {
1437
+ /**
1438
+ * Updates a product
1439
+ */
1440
+ async update(technologyId, productId, product) {
1411
1441
  const updateData = {
1412
1442
  ...product,
1413
1443
  updatedAt: /* @__PURE__ */ new Date()
1414
1444
  };
1415
- const techDocRef = doc6(
1416
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
1417
- productId
1418
- );
1419
- await updateDoc6(techDocRef, updateData);
1420
- const brandProductsQuery = query6(
1421
- collectionGroup(this.db, PRODUCTS_COLLECTION),
1422
- where6("id", "==", productId)
1423
- );
1424
- const brandProductsSnapshot = await getDocs6(brandProductsQuery);
1425
- for (const doc9 of brandProductsSnapshot.docs) {
1426
- await updateDoc6(doc9.ref, updateData);
1427
- }
1428
- return this.getById(categoryId, subcategoryId, technologyId, productId);
1445
+ const docRef = doc6(this.getProductsRef(technologyId), productId);
1446
+ await updateDoc6(docRef, updateData);
1447
+ return this.getById(technologyId, productId);
1429
1448
  }
1430
- async delete(categoryId, subcategoryId, technologyId, productId) {
1431
- await this.update(categoryId, subcategoryId, technologyId, productId, {
1449
+ /**
1450
+ * Soft deletes a product
1451
+ */
1452
+ async delete(technologyId, productId) {
1453
+ await this.update(technologyId, productId, {
1432
1454
  isActive: false
1433
1455
  });
1434
1456
  }
1435
- async getById(categoryId, subcategoryId, technologyId, productId) {
1436
- const docRef = doc6(
1437
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
1438
- productId
1439
- );
1457
+ /**
1458
+ * Gets a product by ID
1459
+ */
1460
+ async getById(technologyId, productId) {
1461
+ const docRef = doc6(this.getProductsRef(technologyId), productId);
1440
1462
  const docSnap = await getDoc6(docRef);
1441
1463
  if (!docSnap.exists()) return null;
1442
1464
  return {