@blackcode_sa/metaestetics-api 1.5.12 → 1.5.14

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
@@ -3617,7 +3617,7 @@ var PractitionerService = class extends BaseService {
3617
3617
  return querySnapshot.docs[0].data();
3618
3618
  }
3619
3619
  /**
3620
- * Dohvata sve zdravstvene radnike za određenu kliniku
3620
+ * Dohvata sve zdravstvene radnike za određenu kliniku sa statusom ACTIVE
3621
3621
  */
3622
3622
  async getPractitionersByClinic(clinicId) {
3623
3623
  const q = (0, import_firestore13.query)(
@@ -3630,7 +3630,19 @@ var PractitionerService = class extends BaseService {
3630
3630
  return querySnapshot.docs.map((doc26) => doc26.data());
3631
3631
  }
3632
3632
  /**
3633
- * Dohvata sve draft zdravstvene radnike za određenu kliniku
3633
+ * Dohvata sve zdravstvene radnike za određenu kliniku
3634
+ */
3635
+ async getAllPractitionersByClinic(clinicId) {
3636
+ const q = (0, import_firestore13.query)(
3637
+ (0, import_firestore13.collection)(this.db, PRACTITIONERS_COLLECTION),
3638
+ (0, import_firestore13.where)("clinics", "array-contains", clinicId),
3639
+ (0, import_firestore13.where)("isActive", "==", true)
3640
+ );
3641
+ const querySnapshot = await (0, import_firestore13.getDocs)(q);
3642
+ return querySnapshot.docs.map((doc26) => doc26.data());
3643
+ }
3644
+ /**
3645
+ * Dohvata sve draft zdravstvene radnike za određenu kliniku sa statusom DRAFT
3634
3646
  */
3635
3647
  async getDraftPractitionersByClinic(clinicId) {
3636
3648
  const q = (0, import_firestore13.query)(
@@ -6456,8 +6468,6 @@ var ProcedureService = class extends BaseService {
6456
6468
  ),
6457
6469
  this.technologyService.getById(validatedData.technologyId),
6458
6470
  this.productService.getById(
6459
- validatedData.categoryId,
6460
- validatedData.subcategoryId,
6461
6471
  validatedData.technologyId,
6462
6472
  validatedData.productId
6463
6473
  )
@@ -9573,9 +9583,15 @@ var BRANDS_COLLECTION = "brands";
9573
9583
 
9574
9584
  // src/backoffice/services/brand.service.ts
9575
9585
  var BrandService = class extends BaseService {
9576
- get brandsRef() {
9586
+ /**
9587
+ * Gets reference to brands collection
9588
+ */
9589
+ getBrandsRef() {
9577
9590
  return (0, import_firestore34.collection)(this.db, BRANDS_COLLECTION);
9578
9591
  }
9592
+ /**
9593
+ * Creates a new brand
9594
+ */
9579
9595
  async create(brand) {
9580
9596
  const now = /* @__PURE__ */ new Date();
9581
9597
  const newBrand = {
@@ -9584,11 +9600,14 @@ var BrandService = class extends BaseService {
9584
9600
  updatedAt: now,
9585
9601
  isActive: true
9586
9602
  };
9587
- const docRef = await (0, import_firestore34.addDoc)(this.brandsRef, newBrand);
9603
+ const docRef = await (0, import_firestore34.addDoc)(this.getBrandsRef(), newBrand);
9588
9604
  return { id: docRef.id, ...newBrand };
9589
9605
  }
9606
+ /**
9607
+ * Gets all active brands
9608
+ */
9590
9609
  async getAll() {
9591
- const q = (0, import_firestore34.query)(this.brandsRef, (0, import_firestore34.where)("isActive", "==", true));
9610
+ const q = (0, import_firestore34.query)(this.getBrandsRef(), (0, import_firestore34.where)("isActive", "==", true));
9592
9611
  const snapshot = await (0, import_firestore34.getDocs)(q);
9593
9612
  return snapshot.docs.map(
9594
9613
  (doc26) => ({
@@ -9597,20 +9616,31 @@ var BrandService = class extends BaseService {
9597
9616
  })
9598
9617
  );
9599
9618
  }
9600
- async update(id, brand) {
9619
+ /**
9620
+ * Updates a brand
9621
+ */
9622
+ async update(brandId, brand) {
9601
9623
  const updateData = {
9602
9624
  ...brand,
9603
9625
  updatedAt: /* @__PURE__ */ new Date()
9604
9626
  };
9605
- const docRef = (0, import_firestore34.doc)(this.brandsRef, id);
9627
+ const docRef = (0, import_firestore34.doc)(this.getBrandsRef(), brandId);
9606
9628
  await (0, import_firestore34.updateDoc)(docRef, updateData);
9607
- return this.getById(id);
9629
+ return this.getById(brandId);
9608
9630
  }
9609
- async delete(id) {
9610
- await this.update(id, { isActive: false });
9631
+ /**
9632
+ * Soft deletes a brand
9633
+ */
9634
+ async delete(brandId) {
9635
+ await this.update(brandId, {
9636
+ isActive: false
9637
+ });
9611
9638
  }
9612
- async getById(id) {
9613
- const docRef = (0, import_firestore34.doc)(this.brandsRef, id);
9639
+ /**
9640
+ * Gets a brand by ID
9641
+ */
9642
+ async getById(brandId) {
9643
+ const docRef = (0, import_firestore34.doc)(this.getBrandsRef(), brandId);
9614
9644
  const docSnap = await (0, import_firestore34.getDoc)(docRef);
9615
9645
  if (!docSnap.exists()) return null;
9616
9646
  return {
@@ -10253,22 +10283,23 @@ var PRODUCTS_COLLECTION = "products";
10253
10283
 
10254
10284
  // src/backoffice/services/product.service.ts
10255
10285
  var ProductService = class extends BaseService {
10256
- getProductsRefByTechnology(categoryId, subcategoryId, technologyId) {
10286
+ /**
10287
+ * Gets reference to products collection under a technology
10288
+ * @param technologyId - ID of the technology
10289
+ * @returns Firestore collection reference
10290
+ */
10291
+ getProductsRef(technologyId) {
10257
10292
  return (0, import_firestore38.collection)(
10258
10293
  this.db,
10259
- CATEGORIES_COLLECTION,
10260
- categoryId,
10261
- SUBCATEGORIES_COLLECTION,
10262
- subcategoryId,
10263
10294
  TECHNOLOGIES_COLLECTION,
10264
10295
  technologyId,
10265
10296
  PRODUCTS_COLLECTION
10266
10297
  );
10267
10298
  }
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) {
10299
+ /**
10300
+ * Creates a new product under technology
10301
+ */
10302
+ async create(technologyId, brandId, product) {
10272
10303
  const now = /* @__PURE__ */ new Date();
10273
10304
  const newProduct = {
10274
10305
  ...product,
@@ -10278,23 +10309,18 @@ var ProductService = class extends BaseService {
10278
10309
  updatedAt: now,
10279
10310
  isActive: true
10280
10311
  };
10281
- const techProductRef = await (0, import_firestore38.addDoc)(
10282
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10312
+ const productRef = await (0, import_firestore38.addDoc)(
10313
+ this.getProductsRef(technologyId),
10283
10314
  newProduct
10284
10315
  );
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 };
10316
+ return { id: productRef.id, ...newProduct };
10294
10317
  }
10295
- async getAllByTechnology(categoryId, subcategoryId, technologyId) {
10318
+ /**
10319
+ * Gets all products for a technology
10320
+ */
10321
+ async getAllByTechnology(technologyId) {
10296
10322
  const q = (0, import_firestore38.query)(
10297
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10323
+ this.getProductsRef(technologyId),
10298
10324
  (0, import_firestore38.where)("isActive", "==", true)
10299
10325
  );
10300
10326
  const snapshot = await (0, import_firestore38.getDocs)(q);
@@ -10305,49 +10331,56 @@ var ProductService = class extends BaseService {
10305
10331
  })
10306
10332
  );
10307
10333
  }
10334
+ /**
10335
+ * Gets all products for a brand by filtering through all technologies
10336
+ */
10308
10337
  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
- );
10338
+ const allTechnologiesRef = (0, import_firestore38.collection)(this.db, TECHNOLOGIES_COLLECTION);
10339
+ const technologiesSnapshot = await (0, import_firestore38.getDocs)(allTechnologiesRef);
10340
+ const products = [];
10341
+ for (const techDoc of technologiesSnapshot.docs) {
10342
+ const q = (0, import_firestore38.query)(
10343
+ this.getProductsRef(techDoc.id),
10344
+ (0, import_firestore38.where)("brandId", "==", brandId),
10345
+ (0, import_firestore38.where)("isActive", "==", true)
10346
+ );
10347
+ const snapshot = await (0, import_firestore38.getDocs)(q);
10348
+ products.push(
10349
+ ...snapshot.docs.map(
10350
+ (doc26) => ({
10351
+ id: doc26.id,
10352
+ ...doc26.data()
10353
+ })
10354
+ )
10355
+ );
10356
+ }
10357
+ return products;
10320
10358
  }
10321
- async update(categoryId, subcategoryId, technologyId, productId, product) {
10359
+ /**
10360
+ * Updates a product
10361
+ */
10362
+ async update(technologyId, productId, product) {
10322
10363
  const updateData = {
10323
10364
  ...product,
10324
10365
  updatedAt: /* @__PURE__ */ new Date()
10325
10366
  };
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);
10367
+ const docRef = (0, import_firestore38.doc)(this.getProductsRef(technologyId), productId);
10368
+ await (0, import_firestore38.updateDoc)(docRef, updateData);
10369
+ return this.getById(technologyId, productId);
10340
10370
  }
10341
- async delete(categoryId, subcategoryId, technologyId, productId) {
10342
- await this.update(categoryId, subcategoryId, technologyId, productId, {
10371
+ /**
10372
+ * Soft deletes a product
10373
+ */
10374
+ async delete(technologyId, productId) {
10375
+ await this.update(technologyId, productId, {
10343
10376
  isActive: false
10344
10377
  });
10345
10378
  }
10346
- async getById(categoryId, subcategoryId, technologyId, productId) {
10347
- const docRef = (0, import_firestore38.doc)(
10348
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10349
- productId
10350
- );
10379
+ /**
10380
+ * Gets a product by ID
10381
+ */
10382
+ async getById(technologyId, productId) {
10383
+ const docRef = (0, import_firestore38.doc)(this.getProductsRef(technologyId), productId);
10351
10384
  const docSnap = await (0, import_firestore38.getDoc)(docRef);
10352
10385
  if (!docSnap.exists()) return null;
10353
10386
  return {
package/dist/index.mjs CHANGED
@@ -3522,7 +3522,7 @@ var PractitionerService = class extends BaseService {
3522
3522
  return querySnapshot.docs[0].data();
3523
3523
  }
3524
3524
  /**
3525
- * Dohvata sve zdravstvene radnike za određenu kliniku
3525
+ * Dohvata sve zdravstvene radnike za određenu kliniku sa statusom ACTIVE
3526
3526
  */
3527
3527
  async getPractitionersByClinic(clinicId) {
3528
3528
  const q = query3(
@@ -3535,7 +3535,19 @@ var PractitionerService = class extends BaseService {
3535
3535
  return querySnapshot.docs.map((doc26) => doc26.data());
3536
3536
  }
3537
3537
  /**
3538
- * Dohvata sve draft zdravstvene radnike za određenu kliniku
3538
+ * Dohvata sve zdravstvene radnike za određenu kliniku
3539
+ */
3540
+ async getAllPractitionersByClinic(clinicId) {
3541
+ const q = query3(
3542
+ collection3(this.db, PRACTITIONERS_COLLECTION),
3543
+ where3("clinics", "array-contains", clinicId),
3544
+ where3("isActive", "==", true)
3545
+ );
3546
+ const querySnapshot = await getDocs3(q);
3547
+ return querySnapshot.docs.map((doc26) => doc26.data());
3548
+ }
3549
+ /**
3550
+ * Dohvata sve draft zdravstvene radnike za određenu kliniku sa statusom DRAFT
3539
3551
  */
3540
3552
  async getDraftPractitionersByClinic(clinicId) {
3541
3553
  const q = query3(
@@ -6421,8 +6433,6 @@ var ProcedureService = class extends BaseService {
6421
6433
  ),
6422
6434
  this.technologyService.getById(validatedData.technologyId),
6423
6435
  this.productService.getById(
6424
- validatedData.categoryId,
6425
- validatedData.subcategoryId,
6426
6436
  validatedData.technologyId,
6427
6437
  validatedData.productId
6428
6438
  )
@@ -9629,9 +9639,15 @@ var BRANDS_COLLECTION = "brands";
9629
9639
 
9630
9640
  // src/backoffice/services/brand.service.ts
9631
9641
  var BrandService = class extends BaseService {
9632
- get brandsRef() {
9642
+ /**
9643
+ * Gets reference to brands collection
9644
+ */
9645
+ getBrandsRef() {
9633
9646
  return collection19(this.db, BRANDS_COLLECTION);
9634
9647
  }
9648
+ /**
9649
+ * Creates a new brand
9650
+ */
9635
9651
  async create(brand) {
9636
9652
  const now = /* @__PURE__ */ new Date();
9637
9653
  const newBrand = {
@@ -9640,11 +9656,14 @@ var BrandService = class extends BaseService {
9640
9656
  updatedAt: now,
9641
9657
  isActive: true
9642
9658
  };
9643
- const docRef = await addDoc4(this.brandsRef, newBrand);
9659
+ const docRef = await addDoc4(this.getBrandsRef(), newBrand);
9644
9660
  return { id: docRef.id, ...newBrand };
9645
9661
  }
9662
+ /**
9663
+ * Gets all active brands
9664
+ */
9646
9665
  async getAll() {
9647
- const q = query18(this.brandsRef, where18("isActive", "==", true));
9666
+ const q = query18(this.getBrandsRef(), where18("isActive", "==", true));
9648
9667
  const snapshot = await getDocs18(q);
9649
9668
  return snapshot.docs.map(
9650
9669
  (doc26) => ({
@@ -9653,20 +9672,31 @@ var BrandService = class extends BaseService {
9653
9672
  })
9654
9673
  );
9655
9674
  }
9656
- async update(id, brand) {
9675
+ /**
9676
+ * Updates a brand
9677
+ */
9678
+ async update(brandId, brand) {
9657
9679
  const updateData = {
9658
9680
  ...brand,
9659
9681
  updatedAt: /* @__PURE__ */ new Date()
9660
9682
  };
9661
- const docRef = doc21(this.brandsRef, id);
9683
+ const docRef = doc21(this.getBrandsRef(), brandId);
9662
9684
  await updateDoc22(docRef, updateData);
9663
- return this.getById(id);
9685
+ return this.getById(brandId);
9664
9686
  }
9665
- async delete(id) {
9666
- await this.update(id, { isActive: false });
9687
+ /**
9688
+ * Soft deletes a brand
9689
+ */
9690
+ async delete(brandId) {
9691
+ await this.update(brandId, {
9692
+ isActive: false
9693
+ });
9667
9694
  }
9668
- async getById(id) {
9669
- const docRef = doc21(this.brandsRef, id);
9695
+ /**
9696
+ * Gets a brand by ID
9697
+ */
9698
+ async getById(brandId) {
9699
+ const docRef = doc21(this.getBrandsRef(), brandId);
9670
9700
  const docSnap = await getDoc24(docRef);
9671
9701
  if (!docSnap.exists()) return null;
9672
9702
  return {
@@ -10334,7 +10364,6 @@ var TechnologyService = class extends BaseService {
10334
10364
  import {
10335
10365
  addDoc as addDoc8,
10336
10366
  collection as collection23,
10337
- collectionGroup,
10338
10367
  doc as doc25,
10339
10368
  getDoc as getDoc28,
10340
10369
  getDocs as getDocs22,
@@ -10348,22 +10377,23 @@ var PRODUCTS_COLLECTION = "products";
10348
10377
 
10349
10378
  // src/backoffice/services/product.service.ts
10350
10379
  var ProductService = class extends BaseService {
10351
- getProductsRefByTechnology(categoryId, subcategoryId, technologyId) {
10380
+ /**
10381
+ * Gets reference to products collection under a technology
10382
+ * @param technologyId - ID of the technology
10383
+ * @returns Firestore collection reference
10384
+ */
10385
+ getProductsRef(technologyId) {
10352
10386
  return collection23(
10353
10387
  this.db,
10354
- CATEGORIES_COLLECTION,
10355
- categoryId,
10356
- SUBCATEGORIES_COLLECTION,
10357
- subcategoryId,
10358
10388
  TECHNOLOGIES_COLLECTION,
10359
10389
  technologyId,
10360
10390
  PRODUCTS_COLLECTION
10361
10391
  );
10362
10392
  }
10363
- getProductsRefByBrand(brandId) {
10364
- return collection23(this.db, BRANDS_COLLECTION, brandId, PRODUCTS_COLLECTION);
10365
- }
10366
- async create(categoryId, subcategoryId, technologyId, brandId, product) {
10393
+ /**
10394
+ * Creates a new product under technology
10395
+ */
10396
+ async create(technologyId, brandId, product) {
10367
10397
  const now = /* @__PURE__ */ new Date();
10368
10398
  const newProduct = {
10369
10399
  ...product,
@@ -10373,23 +10403,18 @@ var ProductService = class extends BaseService {
10373
10403
  updatedAt: now,
10374
10404
  isActive: true
10375
10405
  };
10376
- const techProductRef = await addDoc8(
10377
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10406
+ const productRef = await addDoc8(
10407
+ this.getProductsRef(technologyId),
10378
10408
  newProduct
10379
10409
  );
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 };
10410
+ return { id: productRef.id, ...newProduct };
10389
10411
  }
10390
- async getAllByTechnology(categoryId, subcategoryId, technologyId) {
10412
+ /**
10413
+ * Gets all products for a technology
10414
+ */
10415
+ async getAllByTechnology(technologyId) {
10391
10416
  const q = query22(
10392
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10417
+ this.getProductsRef(technologyId),
10393
10418
  where22("isActive", "==", true)
10394
10419
  );
10395
10420
  const snapshot = await getDocs22(q);
@@ -10400,49 +10425,56 @@ var ProductService = class extends BaseService {
10400
10425
  })
10401
10426
  );
10402
10427
  }
10428
+ /**
10429
+ * Gets all products for a brand by filtering through all technologies
10430
+ */
10403
10431
  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
- );
10432
+ const allTechnologiesRef = collection23(this.db, TECHNOLOGIES_COLLECTION);
10433
+ const technologiesSnapshot = await getDocs22(allTechnologiesRef);
10434
+ const products = [];
10435
+ for (const techDoc of technologiesSnapshot.docs) {
10436
+ const q = query22(
10437
+ this.getProductsRef(techDoc.id),
10438
+ where22("brandId", "==", brandId),
10439
+ where22("isActive", "==", true)
10440
+ );
10441
+ const snapshot = await getDocs22(q);
10442
+ products.push(
10443
+ ...snapshot.docs.map(
10444
+ (doc26) => ({
10445
+ id: doc26.id,
10446
+ ...doc26.data()
10447
+ })
10448
+ )
10449
+ );
10450
+ }
10451
+ return products;
10415
10452
  }
10416
- async update(categoryId, subcategoryId, technologyId, productId, product) {
10453
+ /**
10454
+ * Updates a product
10455
+ */
10456
+ async update(technologyId, productId, product) {
10417
10457
  const updateData = {
10418
10458
  ...product,
10419
10459
  updatedAt: /* @__PURE__ */ new Date()
10420
10460
  };
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);
10461
+ const docRef = doc25(this.getProductsRef(technologyId), productId);
10462
+ await updateDoc26(docRef, updateData);
10463
+ return this.getById(technologyId, productId);
10435
10464
  }
10436
- async delete(categoryId, subcategoryId, technologyId, productId) {
10437
- await this.update(categoryId, subcategoryId, technologyId, productId, {
10465
+ /**
10466
+ * Soft deletes a product
10467
+ */
10468
+ async delete(technologyId, productId) {
10469
+ await this.update(technologyId, productId, {
10438
10470
  isActive: false
10439
10471
  });
10440
10472
  }
10441
- async getById(categoryId, subcategoryId, technologyId, productId) {
10442
- const docRef = doc25(
10443
- this.getProductsRefByTechnology(categoryId, subcategoryId, technologyId),
10444
- productId
10445
- );
10473
+ /**
10474
+ * Gets a product by ID
10475
+ */
10476
+ async getById(technologyId, productId) {
10477
+ const docRef = doc25(this.getProductsRef(technologyId), productId);
10446
10478
  const docSnap = await getDoc28(docRef);
10447
10479
  if (!docSnap.exists()) return null;
10448
10480
  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.12",
4
+ "version": "1.5.14",
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 {