@blackcode_sa/metaestetics-api 1.5.11 → 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.
package/dist/index.js CHANGED
@@ -6456,8 +6456,6 @@ var ProcedureService = class extends BaseService {
6456
6456
  ),
6457
6457
  this.technologyService.getById(validatedData.technologyId),
6458
6458
  this.productService.getById(
6459
- validatedData.categoryId,
6460
- validatedData.subcategoryId,
6461
6459
  validatedData.technologyId,
6462
6460
  validatedData.productId
6463
6461
  )
@@ -9573,9 +9571,15 @@ var BRANDS_COLLECTION = "brands";
9573
9571
 
9574
9572
  // src/backoffice/services/brand.service.ts
9575
9573
  var BrandService = class extends BaseService {
9576
- get brandsRef() {
9574
+ /**
9575
+ * Gets reference to brands collection
9576
+ */
9577
+ getBrandsRef() {
9577
9578
  return (0, import_firestore34.collection)(this.db, BRANDS_COLLECTION);
9578
9579
  }
9580
+ /**
9581
+ * Creates a new brand
9582
+ */
9579
9583
  async create(brand) {
9580
9584
  const now = /* @__PURE__ */ new Date();
9581
9585
  const newBrand = {
@@ -9584,11 +9588,14 @@ var BrandService = class extends BaseService {
9584
9588
  updatedAt: now,
9585
9589
  isActive: true
9586
9590
  };
9587
- const docRef = await (0, import_firestore34.addDoc)(this.brandsRef, newBrand);
9591
+ const docRef = await (0, import_firestore34.addDoc)(this.getBrandsRef(), newBrand);
9588
9592
  return { id: docRef.id, ...newBrand };
9589
9593
  }
9594
+ /**
9595
+ * Gets all active brands
9596
+ */
9590
9597
  async getAll() {
9591
- const q = (0, import_firestore34.query)(this.brandsRef, (0, import_firestore34.where)("isActive", "==", true));
9598
+ const q = (0, import_firestore34.query)(this.getBrandsRef(), (0, import_firestore34.where)("isActive", "==", true));
9592
9599
  const snapshot = await (0, import_firestore34.getDocs)(q);
9593
9600
  return snapshot.docs.map(
9594
9601
  (doc26) => ({
@@ -9597,20 +9604,31 @@ var BrandService = class extends BaseService {
9597
9604
  })
9598
9605
  );
9599
9606
  }
9600
- async update(id, brand) {
9607
+ /**
9608
+ * Updates a brand
9609
+ */
9610
+ async update(brandId, brand) {
9601
9611
  const updateData = {
9602
9612
  ...brand,
9603
9613
  updatedAt: /* @__PURE__ */ new Date()
9604
9614
  };
9605
- const docRef = (0, import_firestore34.doc)(this.brandsRef, id);
9615
+ const docRef = (0, import_firestore34.doc)(this.getBrandsRef(), brandId);
9606
9616
  await (0, import_firestore34.updateDoc)(docRef, updateData);
9607
- return this.getById(id);
9617
+ return this.getById(brandId);
9608
9618
  }
9609
- async delete(id) {
9610
- await this.update(id, { isActive: false });
9619
+ /**
9620
+ * Soft deletes a brand
9621
+ */
9622
+ async delete(brandId) {
9623
+ await this.update(brandId, {
9624
+ isActive: false
9625
+ });
9611
9626
  }
9612
- async getById(id) {
9613
- const docRef = (0, import_firestore34.doc)(this.brandsRef, id);
9627
+ /**
9628
+ * Gets a brand by ID
9629
+ */
9630
+ async getById(brandId) {
9631
+ const docRef = (0, import_firestore34.doc)(this.getBrandsRef(), brandId);
9614
9632
  const docSnap = await (0, import_firestore34.getDoc)(docRef);
9615
9633
  if (!docSnap.exists()) return null;
9616
9634
  return {
@@ -10253,22 +10271,23 @@ var PRODUCTS_COLLECTION = "products";
10253
10271
 
10254
10272
  // src/backoffice/services/product.service.ts
10255
10273
  var ProductService = class extends BaseService {
10256
- getProductsRefByTechnology(categoryId, subcategoryId, technologyId) {
10274
+ /**
10275
+ * Gets reference to products collection under a technology
10276
+ * @param technologyId - ID of the technology
10277
+ * @returns Firestore collection reference
10278
+ */
10279
+ getProductsRef(technologyId) {
10257
10280
  return (0, import_firestore38.collection)(
10258
10281
  this.db,
10259
- CATEGORIES_COLLECTION,
10260
- categoryId,
10261
- SUBCATEGORIES_COLLECTION,
10262
- subcategoryId,
10263
10282
  TECHNOLOGIES_COLLECTION,
10264
10283
  technologyId,
10265
10284
  PRODUCTS_COLLECTION
10266
10285
  );
10267
10286
  }
10268
- getProductsRefByBrand(brandId) {
10269
- return (0, import_firestore38.collection)(this.db, BRANDS_COLLECTION, brandId, PRODUCTS_COLLECTION);
10270
- }
10271
- async create(categoryId, subcategoryId, technologyId, brandId, product) {
10287
+ /**
10288
+ * Creates a new product under technology
10289
+ */
10290
+ async create(technologyId, brandId, product) {
10272
10291
  const now = /* @__PURE__ */ new Date();
10273
10292
  const newProduct = {
10274
10293
  ...product,
@@ -10278,23 +10297,18 @@ var ProductService = class extends BaseService {
10278
10297
  updatedAt: now,
10279
10298
  isActive: true
10280
10299
  };
10281
- const techProductRef = await (0, import_firestore38.addDoc)(
10282
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10300
+ const productRef = await (0, import_firestore38.addDoc)(
10301
+ this.getProductsRef(technologyId),
10283
10302
  newProduct
10284
10303
  );
10285
- await (0, import_firestore38.addDoc)(this.getProductsRefByBrand(brandId), {
10286
- ...newProduct,
10287
- id: techProductRef.id,
10288
- // Store the original ID for reference
10289
- categoryId,
10290
- subcategoryId,
10291
- technologyId
10292
- });
10293
- return { id: techProductRef.id, ...newProduct };
10304
+ return { id: productRef.id, ...newProduct };
10294
10305
  }
10295
- async getAllByTechnology(categoryId, subcategoryId, technologyId) {
10306
+ /**
10307
+ * Gets all products for a technology
10308
+ */
10309
+ async getAllByTechnology(technologyId) {
10296
10310
  const q = (0, import_firestore38.query)(
10297
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10311
+ this.getProductsRef(technologyId),
10298
10312
  (0, import_firestore38.where)("isActive", "==", true)
10299
10313
  );
10300
10314
  const snapshot = await (0, import_firestore38.getDocs)(q);
@@ -10305,49 +10319,56 @@ var ProductService = class extends BaseService {
10305
10319
  })
10306
10320
  );
10307
10321
  }
10322
+ /**
10323
+ * Gets all products for a brand by filtering through all technologies
10324
+ */
10308
10325
  async getAllByBrand(brandId) {
10309
- const q = (0, import_firestore38.query)(
10310
- this.getProductsRefByBrand(brandId),
10311
- (0, import_firestore38.where)("isActive", "==", true)
10312
- );
10313
- const snapshot = await (0, import_firestore38.getDocs)(q);
10314
- return snapshot.docs.map(
10315
- (doc26) => ({
10316
- id: doc26.id,
10317
- ...doc26.data()
10318
- })
10319
- );
10326
+ const allTechnologiesRef = (0, import_firestore38.collection)(this.db, TECHNOLOGIES_COLLECTION);
10327
+ const technologiesSnapshot = await (0, import_firestore38.getDocs)(allTechnologiesRef);
10328
+ const products = [];
10329
+ for (const techDoc of technologiesSnapshot.docs) {
10330
+ const q = (0, import_firestore38.query)(
10331
+ this.getProductsRef(techDoc.id),
10332
+ (0, import_firestore38.where)("brandId", "==", brandId),
10333
+ (0, import_firestore38.where)("isActive", "==", true)
10334
+ );
10335
+ const snapshot = await (0, import_firestore38.getDocs)(q);
10336
+ products.push(
10337
+ ...snapshot.docs.map(
10338
+ (doc26) => ({
10339
+ id: doc26.id,
10340
+ ...doc26.data()
10341
+ })
10342
+ )
10343
+ );
10344
+ }
10345
+ return products;
10320
10346
  }
10321
- async update(categoryId, subcategoryId, technologyId, productId, product) {
10347
+ /**
10348
+ * Updates a product
10349
+ */
10350
+ async update(technologyId, productId, product) {
10322
10351
  const updateData = {
10323
10352
  ...product,
10324
10353
  updatedAt: /* @__PURE__ */ new Date()
10325
10354
  };
10326
- const techDocRef = (0, import_firestore38.doc)(
10327
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10328
- productId
10329
- );
10330
- await (0, import_firestore38.updateDoc)(techDocRef, updateData);
10331
- const brandProductsQuery = (0, import_firestore38.query)(
10332
- (0, import_firestore38.collectionGroup)(this.db, PRODUCTS_COLLECTION),
10333
- (0, import_firestore38.where)("id", "==", productId)
10334
- );
10335
- const brandProductsSnapshot = await (0, import_firestore38.getDocs)(brandProductsQuery);
10336
- for (const doc26 of brandProductsSnapshot.docs) {
10337
- await (0, import_firestore38.updateDoc)(doc26.ref, updateData);
10338
- }
10339
- return this.getById(categoryId, subcategoryId, technologyId, productId);
10355
+ const docRef = (0, import_firestore38.doc)(this.getProductsRef(technologyId), productId);
10356
+ await (0, import_firestore38.updateDoc)(docRef, updateData);
10357
+ return this.getById(technologyId, productId);
10340
10358
  }
10341
- async delete(categoryId, subcategoryId, technologyId, productId) {
10342
- await this.update(categoryId, subcategoryId, technologyId, productId, {
10359
+ /**
10360
+ * Soft deletes a product
10361
+ */
10362
+ async delete(technologyId, productId) {
10363
+ await this.update(technologyId, productId, {
10343
10364
  isActive: false
10344
10365
  });
10345
10366
  }
10346
- async getById(categoryId, subcategoryId, technologyId, productId) {
10347
- const docRef = (0, import_firestore38.doc)(
10348
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10349
- productId
10350
- );
10367
+ /**
10368
+ * Gets a product by ID
10369
+ */
10370
+ async getById(technologyId, productId) {
10371
+ const docRef = (0, import_firestore38.doc)(this.getProductsRef(technologyId), productId);
10351
10372
  const docSnap = await (0, import_firestore38.getDoc)(docRef);
10352
10373
  if (!docSnap.exists()) return null;
10353
10374
  return {
package/dist/index.mjs CHANGED
@@ -6421,8 +6421,6 @@ var ProcedureService = class extends BaseService {
6421
6421
  ),
6422
6422
  this.technologyService.getById(validatedData.technologyId),
6423
6423
  this.productService.getById(
6424
- validatedData.categoryId,
6425
- validatedData.subcategoryId,
6426
6424
  validatedData.technologyId,
6427
6425
  validatedData.productId
6428
6426
  )
@@ -9629,9 +9627,15 @@ var BRANDS_COLLECTION = "brands";
9629
9627
 
9630
9628
  // src/backoffice/services/brand.service.ts
9631
9629
  var BrandService = class extends BaseService {
9632
- get brandsRef() {
9630
+ /**
9631
+ * Gets reference to brands collection
9632
+ */
9633
+ getBrandsRef() {
9633
9634
  return collection19(this.db, BRANDS_COLLECTION);
9634
9635
  }
9636
+ /**
9637
+ * Creates a new brand
9638
+ */
9635
9639
  async create(brand) {
9636
9640
  const now = /* @__PURE__ */ new Date();
9637
9641
  const newBrand = {
@@ -9640,11 +9644,14 @@ var BrandService = class extends BaseService {
9640
9644
  updatedAt: now,
9641
9645
  isActive: true
9642
9646
  };
9643
- const docRef = await addDoc4(this.brandsRef, newBrand);
9647
+ const docRef = await addDoc4(this.getBrandsRef(), newBrand);
9644
9648
  return { id: docRef.id, ...newBrand };
9645
9649
  }
9650
+ /**
9651
+ * Gets all active brands
9652
+ */
9646
9653
  async getAll() {
9647
- const q = query18(this.brandsRef, where18("isActive", "==", true));
9654
+ const q = query18(this.getBrandsRef(), where18("isActive", "==", true));
9648
9655
  const snapshot = await getDocs18(q);
9649
9656
  return snapshot.docs.map(
9650
9657
  (doc26) => ({
@@ -9653,20 +9660,31 @@ var BrandService = class extends BaseService {
9653
9660
  })
9654
9661
  );
9655
9662
  }
9656
- async update(id, brand) {
9663
+ /**
9664
+ * Updates a brand
9665
+ */
9666
+ async update(brandId, brand) {
9657
9667
  const updateData = {
9658
9668
  ...brand,
9659
9669
  updatedAt: /* @__PURE__ */ new Date()
9660
9670
  };
9661
- const docRef = doc21(this.brandsRef, id);
9671
+ const docRef = doc21(this.getBrandsRef(), brandId);
9662
9672
  await updateDoc22(docRef, updateData);
9663
- return this.getById(id);
9673
+ return this.getById(brandId);
9664
9674
  }
9665
- async delete(id) {
9666
- await this.update(id, { isActive: false });
9675
+ /**
9676
+ * Soft deletes a brand
9677
+ */
9678
+ async delete(brandId) {
9679
+ await this.update(brandId, {
9680
+ isActive: false
9681
+ });
9667
9682
  }
9668
- async getById(id) {
9669
- const docRef = doc21(this.brandsRef, id);
9683
+ /**
9684
+ * Gets a brand by ID
9685
+ */
9686
+ async getById(brandId) {
9687
+ const docRef = doc21(this.getBrandsRef(), brandId);
9670
9688
  const docSnap = await getDoc24(docRef);
9671
9689
  if (!docSnap.exists()) return null;
9672
9690
  return {
@@ -10334,7 +10352,6 @@ var TechnologyService = class extends BaseService {
10334
10352
  import {
10335
10353
  addDoc as addDoc8,
10336
10354
  collection as collection23,
10337
- collectionGroup,
10338
10355
  doc as doc25,
10339
10356
  getDoc as getDoc28,
10340
10357
  getDocs as getDocs22,
@@ -10348,22 +10365,23 @@ var PRODUCTS_COLLECTION = "products";
10348
10365
 
10349
10366
  // src/backoffice/services/product.service.ts
10350
10367
  var ProductService = class extends BaseService {
10351
- getProductsRefByTechnology(categoryId, subcategoryId, technologyId) {
10368
+ /**
10369
+ * Gets reference to products collection under a technology
10370
+ * @param technologyId - ID of the technology
10371
+ * @returns Firestore collection reference
10372
+ */
10373
+ getProductsRef(technologyId) {
10352
10374
  return collection23(
10353
10375
  this.db,
10354
- CATEGORIES_COLLECTION,
10355
- categoryId,
10356
- SUBCATEGORIES_COLLECTION,
10357
- subcategoryId,
10358
10376
  TECHNOLOGIES_COLLECTION,
10359
10377
  technologyId,
10360
10378
  PRODUCTS_COLLECTION
10361
10379
  );
10362
10380
  }
10363
- getProductsRefByBrand(brandId) {
10364
- return collection23(this.db, BRANDS_COLLECTION, brandId, PRODUCTS_COLLECTION);
10365
- }
10366
- async create(categoryId, subcategoryId, technologyId, brandId, product) {
10381
+ /**
10382
+ * Creates a new product under technology
10383
+ */
10384
+ async create(technologyId, brandId, product) {
10367
10385
  const now = /* @__PURE__ */ new Date();
10368
10386
  const newProduct = {
10369
10387
  ...product,
@@ -10373,23 +10391,18 @@ var ProductService = class extends BaseService {
10373
10391
  updatedAt: now,
10374
10392
  isActive: true
10375
10393
  };
10376
- const techProductRef = await addDoc8(
10377
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10394
+ const productRef = await addDoc8(
10395
+ this.getProductsRef(technologyId),
10378
10396
  newProduct
10379
10397
  );
10380
- await addDoc8(this.getProductsRefByBrand(brandId), {
10381
- ...newProduct,
10382
- id: techProductRef.id,
10383
- // Store the original ID for reference
10384
- categoryId,
10385
- subcategoryId,
10386
- technologyId
10387
- });
10388
- return { id: techProductRef.id, ...newProduct };
10398
+ return { id: productRef.id, ...newProduct };
10389
10399
  }
10390
- async getAllByTechnology(categoryId, subcategoryId, technologyId) {
10400
+ /**
10401
+ * Gets all products for a technology
10402
+ */
10403
+ async getAllByTechnology(technologyId) {
10391
10404
  const q = query22(
10392
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10405
+ this.getProductsRef(technologyId),
10393
10406
  where22("isActive", "==", true)
10394
10407
  );
10395
10408
  const snapshot = await getDocs22(q);
@@ -10400,49 +10413,56 @@ var ProductService = class extends BaseService {
10400
10413
  })
10401
10414
  );
10402
10415
  }
10416
+ /**
10417
+ * Gets all products for a brand by filtering through all technologies
10418
+ */
10403
10419
  async getAllByBrand(brandId) {
10404
- const q = query22(
10405
- this.getProductsRefByBrand(brandId),
10406
- where22("isActive", "==", true)
10407
- );
10408
- const snapshot = await getDocs22(q);
10409
- return snapshot.docs.map(
10410
- (doc26) => ({
10411
- id: doc26.id,
10412
- ...doc26.data()
10413
- })
10414
- );
10420
+ const allTechnologiesRef = collection23(this.db, TECHNOLOGIES_COLLECTION);
10421
+ const technologiesSnapshot = await getDocs22(allTechnologiesRef);
10422
+ const products = [];
10423
+ for (const techDoc of technologiesSnapshot.docs) {
10424
+ const q = query22(
10425
+ this.getProductsRef(techDoc.id),
10426
+ where22("brandId", "==", brandId),
10427
+ where22("isActive", "==", true)
10428
+ );
10429
+ const snapshot = await getDocs22(q);
10430
+ products.push(
10431
+ ...snapshot.docs.map(
10432
+ (doc26) => ({
10433
+ id: doc26.id,
10434
+ ...doc26.data()
10435
+ })
10436
+ )
10437
+ );
10438
+ }
10439
+ return products;
10415
10440
  }
10416
- async update(categoryId, subcategoryId, technologyId, productId, product) {
10441
+ /**
10442
+ * Updates a product
10443
+ */
10444
+ async update(technologyId, productId, product) {
10417
10445
  const updateData = {
10418
10446
  ...product,
10419
10447
  updatedAt: /* @__PURE__ */ new Date()
10420
10448
  };
10421
- const techDocRef = doc25(
10422
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10423
- productId
10424
- );
10425
- await updateDoc26(techDocRef, updateData);
10426
- const brandProductsQuery = query22(
10427
- collectionGroup(this.db, PRODUCTS_COLLECTION),
10428
- where22("id", "==", productId)
10429
- );
10430
- const brandProductsSnapshot = await getDocs22(brandProductsQuery);
10431
- for (const doc26 of brandProductsSnapshot.docs) {
10432
- await updateDoc26(doc26.ref, updateData);
10433
- }
10434
- return this.getById(categoryId, subcategoryId, technologyId, productId);
10449
+ const docRef = doc25(this.getProductsRef(technologyId), productId);
10450
+ await updateDoc26(docRef, updateData);
10451
+ return this.getById(technologyId, productId);
10435
10452
  }
10436
- async delete(categoryId, subcategoryId, technologyId, productId) {
10437
- await this.update(categoryId, subcategoryId, technologyId, productId, {
10453
+ /**
10454
+ * Soft deletes a product
10455
+ */
10456
+ async delete(technologyId, productId) {
10457
+ await this.update(technologyId, productId, {
10438
10458
  isActive: false
10439
10459
  });
10440
10460
  }
10441
- async getById(categoryId, subcategoryId, technologyId, productId) {
10442
- const docRef = doc25(
10443
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10444
- productId
10445
- );
10461
+ /**
10462
+ * Gets a product by ID
10463
+ */
10464
+ async getById(technologyId, productId) {
10465
+ const docRef = doc25(this.getProductsRef(technologyId), productId);
10446
10466
  const docSnap = await getDoc28(docRef);
10447
10467
  if (!docSnap.exists()) return null;
10448
10468
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.5.11",
4
+ "version": "1.5.13",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -12,10 +12,16 @@ import { Brand, BRANDS_COLLECTION } from "../types/brand.types";
12
12
  import { BaseService } from "../../services/base.service";
13
13
 
14
14
  export class BrandService extends BaseService {
15
- private get brandsRef() {
15
+ /**
16
+ * Gets reference to brands collection
17
+ */
18
+ private getBrandsRef() {
16
19
  return collection(this.db, BRANDS_COLLECTION);
17
20
  }
18
21
 
22
+ /**
23
+ * Creates a new brand
24
+ */
19
25
  async create(brand: Omit<Brand, "id" | "createdAt" | "updatedAt">) {
20
26
  const now = new Date();
21
27
  const newBrand: Omit<Brand, "id"> = {
@@ -25,12 +31,15 @@ export class BrandService extends BaseService {
25
31
  isActive: true,
26
32
  };
27
33
 
28
- const docRef = await addDoc(this.brandsRef, newBrand);
34
+ const docRef = await addDoc(this.getBrandsRef(), newBrand);
29
35
  return { id: docRef.id, ...newBrand };
30
36
  }
31
37
 
38
+ /**
39
+ * Gets all active brands
40
+ */
32
41
  async getAll() {
33
- const q = query(this.brandsRef, where("isActive", "==", true));
42
+ const q = query(this.getBrandsRef(), where("isActive", "==", true));
34
43
  const snapshot = await getDocs(q);
35
44
  return snapshot.docs.map(
36
45
  (doc) =>
@@ -41,23 +50,37 @@ export class BrandService extends BaseService {
41
50
  );
42
51
  }
43
52
 
44
- async update(id: string, brand: Partial<Omit<Brand, "id" | "createdAt">>) {
53
+ /**
54
+ * Updates a brand
55
+ */
56
+ async update(
57
+ brandId: string,
58
+ brand: Partial<Omit<Brand, "id" | "createdAt">>
59
+ ) {
45
60
  const updateData = {
46
61
  ...brand,
47
62
  updatedAt: new Date(),
48
63
  };
49
64
 
50
- const docRef = doc(this.brandsRef, id);
65
+ const docRef = doc(this.getBrandsRef(), brandId);
51
66
  await updateDoc(docRef, updateData);
52
- return this.getById(id);
67
+ return this.getById(brandId);
53
68
  }
54
69
 
55
- async delete(id: string) {
56
- await this.update(id, { isActive: false });
70
+ /**
71
+ * Soft deletes a brand
72
+ */
73
+ async delete(brandId: string) {
74
+ await this.update(brandId, {
75
+ isActive: false,
76
+ });
57
77
  }
58
78
 
59
- async getById(id: string) {
60
- const docRef = doc(this.brandsRef, id);
79
+ /**
80
+ * Gets a brand by ID
81
+ */
82
+ async getById(brandId: string): Promise<Brand | null> {
83
+ const docRef = doc(this.getBrandsRef(), brandId);
61
84
  const docSnap = await getDoc(docRef);
62
85
  if (!docSnap.exists()) return null;
63
86
  return {