@blackcode_sa/metaestetics-api 1.12.2 → 1.12.3
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/backoffice/index.d.mts +64 -14
- package/dist/backoffice/index.d.ts +64 -14
- package/dist/backoffice/index.js +72 -53
- package/dist/backoffice/index.mjs +72 -53
- package/dist/index.d.mts +129 -17
- package/dist/index.d.ts +129 -17
- package/dist/index.js +72 -53
- package/dist/index.mjs +72 -53
- package/package.json +1 -1
- package/src/backoffice/services/FIXES_README.md +102 -0
- package/src/backoffice/services/category.service.ts +46 -27
- package/src/backoffice/services/product.service.ts +52 -74
- package/src/backoffice/services/technology.service.ts +99 -116
- package/src/backoffice/types/category.types.ts +28 -2
- package/src/backoffice/types/product.types.ts +10 -9
- package/src/backoffice/types/technology.types.ts +31 -59
|
@@ -13,14 +13,10 @@ import {
|
|
|
13
13
|
startAfter,
|
|
14
14
|
getCountFromServer,
|
|
15
15
|
QueryConstraint,
|
|
16
|
-
} from
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
IProductService,
|
|
21
|
-
} from "../types/product.types";
|
|
22
|
-
import { BaseService } from "../../services/base.service";
|
|
23
|
-
import { TECHNOLOGIES_COLLECTION } from "../types/technology.types";
|
|
16
|
+
} from 'firebase/firestore';
|
|
17
|
+
import { Product, PRODUCTS_COLLECTION, IProductService } from '../types/product.types';
|
|
18
|
+
import { BaseService } from '../../services/base.service';
|
|
19
|
+
import { TECHNOLOGIES_COLLECTION } from '../types/technology.types';
|
|
24
20
|
|
|
25
21
|
export class ProductService extends BaseService implements IProductService {
|
|
26
22
|
/**
|
|
@@ -29,12 +25,7 @@ export class ProductService extends BaseService implements IProductService {
|
|
|
29
25
|
* @returns Firestore collection reference
|
|
30
26
|
*/
|
|
31
27
|
private getProductsRef(technologyId: string) {
|
|
32
|
-
return collection(
|
|
33
|
-
this.db,
|
|
34
|
-
TECHNOLOGIES_COLLECTION,
|
|
35
|
-
technologyId,
|
|
36
|
-
PRODUCTS_COLLECTION
|
|
37
|
-
);
|
|
28
|
+
return collection(this.db, TECHNOLOGIES_COLLECTION, technologyId, PRODUCTS_COLLECTION);
|
|
38
29
|
}
|
|
39
30
|
|
|
40
31
|
/**
|
|
@@ -43,14 +34,11 @@ export class ProductService extends BaseService implements IProductService {
|
|
|
43
34
|
async create(
|
|
44
35
|
technologyId: string,
|
|
45
36
|
brandId: string,
|
|
46
|
-
product: Omit<
|
|
47
|
-
Product,
|
|
48
|
-
"id" | "createdAt" | "updatedAt" | "brandId" | "technologyId"
|
|
49
|
-
>
|
|
37
|
+
product: Omit<Product, 'id' | 'createdAt' | 'updatedAt' | 'brandId' | 'technologyId'>,
|
|
50
38
|
): Promise<Product> {
|
|
51
39
|
const now = new Date();
|
|
52
40
|
// categoryId and subcategoryId are now expected to be part of the product object
|
|
53
|
-
const newProduct: Omit<Product,
|
|
41
|
+
const newProduct: Omit<Product, 'id'> = {
|
|
54
42
|
...product,
|
|
55
43
|
brandId,
|
|
56
44
|
technologyId,
|
|
@@ -59,10 +47,7 @@ export class ProductService extends BaseService implements IProductService {
|
|
|
59
47
|
isActive: true,
|
|
60
48
|
};
|
|
61
49
|
|
|
62
|
-
const productRef = await addDoc(
|
|
63
|
-
this.getProductsRef(technologyId),
|
|
64
|
-
newProduct
|
|
65
|
-
);
|
|
50
|
+
const productRef = await addDoc(this.getProductsRef(technologyId), newProduct);
|
|
66
51
|
|
|
67
52
|
return { id: productRef.id, ...newProduct };
|
|
68
53
|
}
|
|
@@ -78,27 +63,18 @@ export class ProductService extends BaseService implements IProductService {
|
|
|
78
63
|
subcategoryId?: string;
|
|
79
64
|
technologyId?: string;
|
|
80
65
|
}): Promise<{ products: Product[]; lastVisible: any }> {
|
|
81
|
-
const {
|
|
82
|
-
rowsPerPage,
|
|
83
|
-
lastVisible,
|
|
84
|
-
categoryId,
|
|
85
|
-
subcategoryId,
|
|
86
|
-
technologyId,
|
|
87
|
-
} = options;
|
|
66
|
+
const { rowsPerPage, lastVisible, categoryId, subcategoryId, technologyId } = options;
|
|
88
67
|
|
|
89
|
-
const constraints: QueryConstraint[] = [
|
|
90
|
-
where("isActive", "==", true),
|
|
91
|
-
orderBy("name"),
|
|
92
|
-
];
|
|
68
|
+
const constraints: QueryConstraint[] = [where('isActive', '==', true), orderBy('name')];
|
|
93
69
|
|
|
94
70
|
if (categoryId) {
|
|
95
|
-
constraints.push(where(
|
|
71
|
+
constraints.push(where('categoryId', '==', categoryId));
|
|
96
72
|
}
|
|
97
73
|
if (subcategoryId) {
|
|
98
|
-
constraints.push(where(
|
|
74
|
+
constraints.push(where('subcategoryId', '==', subcategoryId));
|
|
99
75
|
}
|
|
100
76
|
if (technologyId) {
|
|
101
|
-
constraints.push(where(
|
|
77
|
+
constraints.push(where('technologyId', '==', technologyId));
|
|
102
78
|
}
|
|
103
79
|
|
|
104
80
|
if (lastVisible) {
|
|
@@ -106,18 +82,15 @@ export class ProductService extends BaseService implements IProductService {
|
|
|
106
82
|
}
|
|
107
83
|
constraints.push(limit(rowsPerPage));
|
|
108
84
|
|
|
109
|
-
const q = query(
|
|
110
|
-
collectionGroup(this.db, PRODUCTS_COLLECTION),
|
|
111
|
-
...constraints
|
|
112
|
-
);
|
|
85
|
+
const q = query(collectionGroup(this.db, PRODUCTS_COLLECTION), ...constraints);
|
|
113
86
|
const snapshot = await getDocs(q);
|
|
114
87
|
|
|
115
88
|
const products = snapshot.docs.map(
|
|
116
|
-
|
|
89
|
+
doc =>
|
|
117
90
|
({
|
|
118
91
|
id: doc.id,
|
|
119
92
|
...doc.data(),
|
|
120
|
-
} as Product)
|
|
93
|
+
} as Product),
|
|
121
94
|
);
|
|
122
95
|
const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
|
|
123
96
|
|
|
@@ -133,22 +106,19 @@ export class ProductService extends BaseService implements IProductService {
|
|
|
133
106
|
technologyId?: string;
|
|
134
107
|
}): Promise<number> {
|
|
135
108
|
const { categoryId, subcategoryId, technologyId } = options;
|
|
136
|
-
const constraints: QueryConstraint[] = [where(
|
|
109
|
+
const constraints: QueryConstraint[] = [where('isActive', '==', true)];
|
|
137
110
|
|
|
138
111
|
if (categoryId) {
|
|
139
|
-
constraints.push(where(
|
|
112
|
+
constraints.push(where('categoryId', '==', categoryId));
|
|
140
113
|
}
|
|
141
114
|
if (subcategoryId) {
|
|
142
|
-
constraints.push(where(
|
|
115
|
+
constraints.push(where('subcategoryId', '==', subcategoryId));
|
|
143
116
|
}
|
|
144
117
|
if (technologyId) {
|
|
145
|
-
constraints.push(where(
|
|
118
|
+
constraints.push(where('technologyId', '==', technologyId));
|
|
146
119
|
}
|
|
147
120
|
|
|
148
|
-
const q = query(
|
|
149
|
-
collectionGroup(this.db, PRODUCTS_COLLECTION),
|
|
150
|
-
...constraints
|
|
151
|
-
);
|
|
121
|
+
const q = query(collectionGroup(this.db, PRODUCTS_COLLECTION), ...constraints);
|
|
152
122
|
const snapshot = await getCountFromServer(q);
|
|
153
123
|
return snapshot.data().count;
|
|
154
124
|
}
|
|
@@ -162,10 +132,7 @@ export class ProductService extends BaseService implements IProductService {
|
|
|
162
132
|
bySubcategory: Record<string, number>;
|
|
163
133
|
byTechnology: Record<string, number>;
|
|
164
134
|
}> {
|
|
165
|
-
const q = query(
|
|
166
|
-
collectionGroup(this.db, PRODUCTS_COLLECTION),
|
|
167
|
-
where("isActive", "==", true)
|
|
168
|
-
);
|
|
135
|
+
const q = query(collectionGroup(this.db, PRODUCTS_COLLECTION), where('isActive', '==', true));
|
|
169
136
|
const snapshot = await getDocs(q);
|
|
170
137
|
|
|
171
138
|
const counts = {
|
|
@@ -178,27 +145,43 @@ export class ProductService extends BaseService implements IProductService {
|
|
|
178
145
|
return counts;
|
|
179
146
|
}
|
|
180
147
|
|
|
181
|
-
snapshot.docs.forEach(
|
|
148
|
+
snapshot.docs.forEach(doc => {
|
|
182
149
|
const product = doc.data() as Product;
|
|
183
150
|
const { categoryId, subcategoryId, technologyId } = product;
|
|
184
151
|
|
|
185
152
|
if (categoryId) {
|
|
186
|
-
counts.byCategory[categoryId] =
|
|
187
|
-
(counts.byCategory[categoryId] || 0) + 1;
|
|
153
|
+
counts.byCategory[categoryId] = (counts.byCategory[categoryId] || 0) + 1;
|
|
188
154
|
}
|
|
189
155
|
if (subcategoryId) {
|
|
190
|
-
counts.bySubcategory[subcategoryId] =
|
|
191
|
-
(counts.bySubcategory[subcategoryId] || 0) + 1;
|
|
156
|
+
counts.bySubcategory[subcategoryId] = (counts.bySubcategory[subcategoryId] || 0) + 1;
|
|
192
157
|
}
|
|
193
158
|
if (technologyId) {
|
|
194
|
-
counts.byTechnology[technologyId] =
|
|
195
|
-
(counts.byTechnology[technologyId] || 0) + 1;
|
|
159
|
+
counts.byTechnology[technologyId] = (counts.byTechnology[technologyId] || 0) + 1;
|
|
196
160
|
}
|
|
197
161
|
});
|
|
198
162
|
|
|
199
163
|
return counts;
|
|
200
164
|
}
|
|
201
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Gets all products for a specific technology (non-paginated, for filters/dropdowns)
|
|
168
|
+
*/
|
|
169
|
+
async getAllByTechnology(technologyId: string): Promise<Product[]> {
|
|
170
|
+
const q = query(
|
|
171
|
+
this.getProductsRef(technologyId),
|
|
172
|
+
where('isActive', '==', true),
|
|
173
|
+
orderBy('name'),
|
|
174
|
+
);
|
|
175
|
+
const snapshot = await getDocs(q);
|
|
176
|
+
return snapshot.docs.map(
|
|
177
|
+
doc =>
|
|
178
|
+
({
|
|
179
|
+
id: doc.id,
|
|
180
|
+
...doc.data(),
|
|
181
|
+
} as Product),
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
202
185
|
/**
|
|
203
186
|
* Gets all products for a brand by filtering through all technologies
|
|
204
187
|
*/
|
|
@@ -211,18 +194,18 @@ export class ProductService extends BaseService implements IProductService {
|
|
|
211
194
|
for (const techDoc of technologiesSnapshot.docs) {
|
|
212
195
|
const q = query(
|
|
213
196
|
this.getProductsRef(techDoc.id),
|
|
214
|
-
where(
|
|
215
|
-
where(
|
|
197
|
+
where('brandId', '==', brandId),
|
|
198
|
+
where('isActive', '==', true),
|
|
216
199
|
);
|
|
217
200
|
const snapshot = await getDocs(q);
|
|
218
201
|
products.push(
|
|
219
202
|
...snapshot.docs.map(
|
|
220
|
-
|
|
203
|
+
doc =>
|
|
221
204
|
({
|
|
222
205
|
id: doc.id,
|
|
223
206
|
...doc.data(),
|
|
224
|
-
} as Product)
|
|
225
|
-
)
|
|
207
|
+
} as Product),
|
|
208
|
+
),
|
|
226
209
|
);
|
|
227
210
|
}
|
|
228
211
|
|
|
@@ -235,9 +218,7 @@ export class ProductService extends BaseService implements IProductService {
|
|
|
235
218
|
async update(
|
|
236
219
|
technologyId: string,
|
|
237
220
|
productId: string,
|
|
238
|
-
product: Partial<
|
|
239
|
-
Omit<Product, "id" | "createdAt" | "brandId" | "technologyId">
|
|
240
|
-
>
|
|
221
|
+
product: Partial<Omit<Product, 'id' | 'createdAt' | 'brandId' | 'technologyId'>>,
|
|
241
222
|
): Promise<Product | null> {
|
|
242
223
|
const updateData = {
|
|
243
224
|
...product,
|
|
@@ -262,10 +243,7 @@ export class ProductService extends BaseService implements IProductService {
|
|
|
262
243
|
/**
|
|
263
244
|
* Gets a product by ID
|
|
264
245
|
*/
|
|
265
|
-
async getById(
|
|
266
|
-
technologyId: string,
|
|
267
|
-
productId: string
|
|
268
|
-
): Promise<Product | null> {
|
|
246
|
+
async getById(technologyId: string, productId: string): Promise<Product | null> {
|
|
269
247
|
const docRef = doc(this.getProductsRef(technologyId), productId);
|
|
270
248
|
const docSnap = await getDoc(docRef);
|
|
271
249
|
if (!docSnap.exists()) return null;
|