@blackcode_sa/metaestetics-api 1.11.3 → 1.12.0

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.
Files changed (48) hide show
  1. package/dist/admin/index.d.mts +329 -318
  2. package/dist/admin/index.d.ts +329 -318
  3. package/dist/backoffice/index.d.mts +1166 -430
  4. package/dist/backoffice/index.d.ts +1166 -430
  5. package/dist/backoffice/index.js +1128 -245
  6. package/dist/backoffice/index.mjs +1119 -209
  7. package/dist/index.d.mts +4428 -4035
  8. package/dist/index.d.ts +4428 -4035
  9. package/dist/index.js +1642 -665
  10. package/dist/index.mjs +1406 -401
  11. package/package.json +1 -1
  12. package/src/backoffice/expo-safe/index.ts +3 -0
  13. package/src/backoffice/services/README.md +40 -0
  14. package/src/backoffice/services/brand.service.ts +85 -6
  15. package/src/backoffice/services/category.service.ts +92 -10
  16. package/src/backoffice/services/constants.service.ts +308 -0
  17. package/src/backoffice/services/documentation-template.service.ts +56 -2
  18. package/src/backoffice/services/index.ts +1 -0
  19. package/src/backoffice/services/product.service.ts +126 -5
  20. package/src/backoffice/services/requirement.service.ts +13 -0
  21. package/src/backoffice/services/subcategory.service.ts +184 -13
  22. package/src/backoffice/services/technology.service.ts +344 -129
  23. package/src/backoffice/types/admin-constants.types.ts +69 -0
  24. package/src/backoffice/types/brand.types.ts +1 -0
  25. package/src/backoffice/types/index.ts +1 -0
  26. package/src/backoffice/types/product.types.ts +31 -4
  27. package/src/backoffice/types/static/contraindication.types.ts +1 -0
  28. package/src/backoffice/types/static/treatment-benefit.types.ts +1 -0
  29. package/src/backoffice/types/technology.types.ts +113 -4
  30. package/src/backoffice/validations/schemas.ts +35 -9
  31. package/src/services/appointment/appointment.service.ts +0 -5
  32. package/src/services/appointment/utils/appointment.utils.ts +124 -113
  33. package/src/services/base.service.ts +10 -3
  34. package/src/services/documentation-templates/documentation-template.service.ts +116 -0
  35. package/src/services/media/media.service.ts +2 -2
  36. package/src/services/procedure/procedure.service.ts +436 -234
  37. package/src/types/appointment/index.ts +2 -3
  38. package/src/types/clinic/index.ts +1 -6
  39. package/src/types/patient/medical-info.types.ts +3 -3
  40. package/src/types/procedure/index.ts +20 -17
  41. package/src/validations/clinic.schema.ts +1 -6
  42. package/src/validations/patient/medical-info.schema.ts +7 -2
  43. package/src/backoffice/services/__tests__/brand.service.test.ts +0 -196
  44. package/src/backoffice/services/__tests__/category.service.test.ts +0 -201
  45. package/src/backoffice/services/__tests__/product.service.test.ts +0 -358
  46. package/src/backoffice/services/__tests__/requirement.service.test.ts +0 -226
  47. package/src/backoffice/services/__tests__/subcategory.service.test.ts +0 -181
  48. package/src/backoffice/services/__tests__/technology.service.test.ts +0 -1097
@@ -1,358 +0,0 @@
1
- import { ProductService } from "../product.service";
2
- import { Product } from "../../types/product.types";
3
- import {
4
- collection,
5
- doc,
6
- getDoc,
7
- getDocs,
8
- addDoc,
9
- updateDoc,
10
- query,
11
- where,
12
- collectionGroup,
13
- } from "firebase/firestore";
14
-
15
- jest.mock("firebase/firestore");
16
- jest.mock("../../../config/firebase", () => ({
17
- getFirebaseInstance: jest.fn().mockResolvedValue({
18
- db: {},
19
- auth: {},
20
- }),
21
- }));
22
-
23
- // Konstante za kolekcije
24
- const CATEGORIES_COLLECTION = "backoffice_categories";
25
- const SUBCATEGORIES_COLLECTION = "subcategories";
26
- const TECHNOLOGIES_COLLECTION = "technologies";
27
- const PRODUCTS_COLLECTION = "products";
28
- const BRANDS_COLLECTION = "backoffice_brands";
29
-
30
- // Mock baze podataka
31
- const mockDb = {} as any;
32
-
33
- describe("ProductService", () => {
34
- let service: ProductService;
35
- const CATEGORY_ID = "test-category-id";
36
- const SUBCATEGORY_ID = "test-subcategory-id";
37
- const TECHNOLOGY_ID = "test-technology-id";
38
- const BRAND_ID = "test-brand-id";
39
-
40
- const mockProduct: Omit<Product, "id" | "createdAt" | "updatedAt"> = {
41
- name: "Test Product",
42
- description: "Test Description",
43
- brandId: BRAND_ID,
44
- technologyId: TECHNOLOGY_ID,
45
- isActive: true,
46
- };
47
-
48
- beforeEach(() => {
49
- jest.clearAllMocks();
50
- service = new ProductService();
51
- });
52
-
53
- describe("create", () => {
54
- it("treba da kreira novi proizvod u obe kolekcije", async () => {
55
- const mockDocRef = { id: "test-id" };
56
- (collection as jest.Mock).mockReturnValue("collection-ref");
57
- (addDoc as jest.Mock).mockResolvedValue(mockDocRef);
58
-
59
- const result = await service.create(
60
- CATEGORY_ID,
61
- SUBCATEGORY_ID,
62
- TECHNOLOGY_ID,
63
- BRAND_ID,
64
- mockProduct
65
- );
66
-
67
- expect(collection).toHaveBeenCalledWith(
68
- mockDb,
69
- CATEGORIES_COLLECTION,
70
- CATEGORY_ID,
71
- SUBCATEGORIES_COLLECTION,
72
- SUBCATEGORY_ID,
73
- TECHNOLOGIES_COLLECTION,
74
- TECHNOLOGY_ID,
75
- PRODUCTS_COLLECTION
76
- );
77
-
78
- expect(collection).toHaveBeenCalledWith(
79
- mockDb,
80
- BRANDS_COLLECTION,
81
- BRAND_ID,
82
- PRODUCTS_COLLECTION
83
- );
84
-
85
- expect(addDoc).toHaveBeenCalledTimes(2);
86
- expect(result).toEqual(
87
- expect.objectContaining({
88
- id: mockDocRef.id,
89
- ...mockProduct,
90
- createdAt: expect.any(Date),
91
- updatedAt: expect.any(Date),
92
- })
93
- );
94
- });
95
- });
96
-
97
- describe("update", () => {
98
- it("treba da ažurira proizvod u obe kolekcije", async () => {
99
- const PRODUCT_ID = "test-product-id";
100
- const updateData = { name: "Updated Product" };
101
-
102
- // Mock za technology kolekciju
103
- (collection as jest.Mock).mockReturnValue("collection-ref");
104
- (doc as jest.Mock).mockReturnValue("doc-ref");
105
- (updateDoc as jest.Mock).mockResolvedValue(undefined);
106
-
107
- // Mock za brand kolekciju (collectionGroup query)
108
- (collectionGroup as jest.Mock).mockReturnValue("collection-group-ref");
109
- (query as jest.Mock).mockReturnValue("filtered-query");
110
- (where as jest.Mock).mockReturnValue("where-clause");
111
- (getDocs as jest.Mock).mockResolvedValue({
112
- docs: [
113
- {
114
- ref: "brand-doc-ref",
115
- id: PRODUCT_ID,
116
- data: () => ({
117
- ...mockProduct,
118
- ...updateData,
119
- createdAt: new Date(),
120
- updatedAt: new Date(),
121
- }),
122
- },
123
- ],
124
- });
125
-
126
- // Mock za getById
127
- (getDoc as jest.Mock).mockResolvedValue({
128
- exists: () => true,
129
- id: PRODUCT_ID,
130
- data: () => ({
131
- ...mockProduct,
132
- ...updateData,
133
- createdAt: new Date(),
134
- updatedAt: new Date(),
135
- }),
136
- });
137
-
138
- const result = await service.update(
139
- CATEGORY_ID,
140
- SUBCATEGORY_ID,
141
- TECHNOLOGY_ID,
142
- PRODUCT_ID,
143
- updateData
144
- );
145
-
146
- // Provera poziva za technology kolekciju
147
- expect(collection).toHaveBeenCalledWith(
148
- mockDb,
149
- CATEGORIES_COLLECTION,
150
- CATEGORY_ID,
151
- SUBCATEGORIES_COLLECTION,
152
- SUBCATEGORY_ID,
153
- TECHNOLOGIES_COLLECTION,
154
- TECHNOLOGY_ID,
155
- PRODUCTS_COLLECTION
156
- );
157
-
158
- // Provera poziva za brand kolekciju
159
- expect(collectionGroup).toHaveBeenCalledWith(mockDb, PRODUCTS_COLLECTION);
160
- expect(query).toHaveBeenCalledWith(
161
- "collection-group-ref",
162
- "where-clause"
163
- );
164
- expect(where).toHaveBeenCalledWith("id", "==", PRODUCT_ID);
165
-
166
- expect(updateDoc).toHaveBeenCalledTimes(2);
167
- expect(result).toEqual(
168
- expect.objectContaining({
169
- id: PRODUCT_ID,
170
- ...mockProduct,
171
- ...updateData,
172
- updatedAt: expect.any(Date),
173
- })
174
- );
175
- });
176
- });
177
-
178
- describe("delete", () => {
179
- it("treba da izvrši soft delete proizvoda u obe kolekcije", async () => {
180
- const PRODUCT_ID = "test-product-id";
181
-
182
- // Mock za technology kolekciju
183
- (collection as jest.Mock).mockReturnValue("collection-ref");
184
- (doc as jest.Mock).mockReturnValue("doc-ref");
185
- (updateDoc as jest.Mock).mockResolvedValue(undefined);
186
-
187
- // Mock za brand kolekciju (collectionGroup query)
188
- (collectionGroup as jest.Mock).mockReturnValue("collection-group-ref");
189
- (query as jest.Mock).mockReturnValue("filtered-query");
190
- (where as jest.Mock).mockReturnValue("where-clause");
191
- (getDocs as jest.Mock).mockResolvedValue({
192
- docs: [
193
- {
194
- ref: "brand-doc-ref",
195
- id: PRODUCT_ID,
196
- data: () => ({
197
- ...mockProduct,
198
- isActive: false,
199
- createdAt: new Date(),
200
- updatedAt: new Date(),
201
- }),
202
- },
203
- ],
204
- });
205
-
206
- // Mock za getById
207
- (getDoc as jest.Mock).mockResolvedValue({
208
- exists: () => true,
209
- id: PRODUCT_ID,
210
- data: () => ({
211
- ...mockProduct,
212
- isActive: false,
213
- createdAt: new Date(),
214
- updatedAt: new Date(),
215
- }),
216
- });
217
-
218
- await service.delete(
219
- CATEGORY_ID,
220
- SUBCATEGORY_ID,
221
- TECHNOLOGY_ID,
222
- PRODUCT_ID
223
- );
224
-
225
- // Provera poziva za technology kolekciju
226
- expect(collection).toHaveBeenCalledWith(
227
- mockDb,
228
- CATEGORIES_COLLECTION,
229
- CATEGORY_ID,
230
- SUBCATEGORIES_COLLECTION,
231
- SUBCATEGORY_ID,
232
- TECHNOLOGIES_COLLECTION,
233
- TECHNOLOGY_ID,
234
- PRODUCTS_COLLECTION
235
- );
236
-
237
- // Provera poziva za brand kolekciju
238
- expect(collectionGroup).toHaveBeenCalledWith(mockDb, PRODUCTS_COLLECTION);
239
- expect(query).toHaveBeenCalledWith(
240
- "collection-group-ref",
241
- "where-clause"
242
- );
243
- expect(where).toHaveBeenCalledWith("id", "==", PRODUCT_ID);
244
-
245
- expect(updateDoc).toHaveBeenCalledTimes(2);
246
- expect(updateDoc).toHaveBeenCalledWith(
247
- "doc-ref",
248
- expect.objectContaining({
249
- isActive: false,
250
- updatedAt: expect.any(Date),
251
- })
252
- );
253
- });
254
- });
255
-
256
- describe("getById", () => {
257
- it("treba da vrati proizvod po ID-u", async () => {
258
- const PRODUCT_ID = "test-product-id";
259
-
260
- (collection as jest.Mock).mockReturnValue("collection-ref");
261
- (doc as jest.Mock).mockReturnValue("doc-ref");
262
- (getDoc as jest.Mock).mockResolvedValue({
263
- exists: () => true,
264
- id: PRODUCT_ID,
265
- data: () => ({
266
- ...mockProduct,
267
- createdAt: new Date(),
268
- updatedAt: new Date(),
269
- }),
270
- });
271
-
272
- const result = await service.getById(
273
- CATEGORY_ID,
274
- SUBCATEGORY_ID,
275
- TECHNOLOGY_ID,
276
- PRODUCT_ID
277
- );
278
-
279
- expect(result).toBeDefined();
280
- expect(result?.id).toBe(PRODUCT_ID);
281
- });
282
-
283
- it("treba da vrati null ako proizvod ne postoji", async () => {
284
- const PRODUCT_ID = "non-existent-id";
285
-
286
- (collection as jest.Mock).mockReturnValue("collection-ref");
287
- (doc as jest.Mock).mockReturnValue("doc-ref");
288
- (getDoc as jest.Mock).mockResolvedValue({
289
- exists: () => false,
290
- });
291
-
292
- const result = await service.getById(
293
- CATEGORY_ID,
294
- SUBCATEGORY_ID,
295
- TECHNOLOGY_ID,
296
- PRODUCT_ID
297
- );
298
-
299
- expect(result).toBeNull();
300
- });
301
- });
302
-
303
- describe("getAllByTechnology", () => {
304
- it("treba da vrati sve aktivne proizvode za tehnologiju", async () => {
305
- const mockDocs = [
306
- {
307
- id: "prod-1",
308
- data: () => ({
309
- ...mockProduct,
310
- createdAt: new Date(),
311
- updatedAt: new Date(),
312
- }),
313
- },
314
- ];
315
-
316
- (collection as jest.Mock).mockReturnValue("collection-ref");
317
- (query as jest.Mock).mockReturnValue("filtered-query");
318
- (where as jest.Mock).mockReturnValue("where-clause");
319
- (getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
320
-
321
- const results = await service.getAllByTechnology(
322
- CATEGORY_ID,
323
- SUBCATEGORY_ID,
324
- TECHNOLOGY_ID
325
- );
326
-
327
- expect(query).toHaveBeenCalledWith("collection-ref", "where-clause");
328
- expect(where).toHaveBeenCalledWith("isActive", "==", true);
329
- expect(results).toHaveLength(1);
330
- });
331
- });
332
-
333
- describe("getAllByBrand", () => {
334
- it("treba da vrati sve aktivne proizvode za brend", async () => {
335
- const mockDocs = [
336
- {
337
- id: "prod-1",
338
- data: () => ({
339
- ...mockProduct,
340
- createdAt: new Date(),
341
- updatedAt: new Date(),
342
- }),
343
- },
344
- ];
345
-
346
- (collection as jest.Mock).mockReturnValue("collection-ref");
347
- (query as jest.Mock).mockReturnValue("filtered-query");
348
- (where as jest.Mock).mockReturnValue("where-clause");
349
- (getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
350
-
351
- const results = await service.getAllByBrand(BRAND_ID);
352
-
353
- expect(query).toHaveBeenCalledWith("collection-ref", "where-clause");
354
- expect(where).toHaveBeenCalledWith("isActive", "==", true);
355
- expect(results).toHaveLength(1);
356
- });
357
- });
358
- });
@@ -1,226 +0,0 @@
1
- import { RequirementService } from "../requirement.service";
2
- import {
3
- Requirement,
4
- RequirementType,
5
- TimeUnit,
6
- } from "../../types/requirement.types";
7
- import {
8
- collection,
9
- doc,
10
- getDoc,
11
- getDocs,
12
- addDoc,
13
- updateDoc,
14
- query,
15
- where,
16
- } from "firebase/firestore";
17
-
18
- // Mock Firebase Firestore
19
- jest.mock("firebase/firestore");
20
-
21
- // Dodati na vrh fajla
22
- jest.mock("../../../config/firebase", () => ({
23
- getFirebaseInstance: jest.fn().mockResolvedValue({
24
- db: {},
25
- auth: {},
26
- }),
27
- }));
28
-
29
- const COLLECTION = "backoffice_requirements";
30
-
31
- describe("RequirementService", () => {
32
- let service: RequirementService;
33
- const mockDb = {} as any;
34
-
35
- // Test data
36
- const mockRequirement: Omit<Requirement, "id" | "createdAt" | "updatedAt"> = {
37
- name: "Test Requirement",
38
- description: "Test Description",
39
- type: RequirementType.PRE,
40
- timeframe: {
41
- duration: 2,
42
- unit: TimeUnit.HOURS,
43
- notifyAt: [1, 2],
44
- },
45
- importance: "high",
46
- isActive: true,
47
- };
48
-
49
- beforeEach(() => {
50
- jest.clearAllMocks();
51
- service = new RequirementService();
52
- });
53
-
54
- describe("create", () => {
55
- it("treba da kreira novi zahtev", async () => {
56
- const mockDocRef = { id: "test-id" };
57
- (collection as jest.Mock).mockReturnValue("requirements-collection");
58
- (addDoc as jest.Mock).mockResolvedValue(mockDocRef);
59
-
60
- const result = await service.create(mockRequirement);
61
-
62
- expect(collection).toHaveBeenCalledWith(mockDb, COLLECTION);
63
- expect(addDoc).toHaveBeenCalledWith(
64
- "requirements-collection",
65
- expect.objectContaining({
66
- ...mockRequirement,
67
- createdAt: expect.any(Date),
68
- updatedAt: expect.any(Date),
69
- })
70
- );
71
- expect(result).toEqual({
72
- id: "test-id",
73
- ...mockRequirement,
74
- createdAt: expect.any(Date),
75
- updatedAt: expect.any(Date),
76
- });
77
- });
78
-
79
- it("treba da baci grešku ako kreiranje ne uspe", async () => {
80
- (collection as jest.Mock).mockReturnValue("requirements-collection");
81
- (addDoc as jest.Mock).mockRejectedValue(new Error("Firebase Error"));
82
-
83
- await expect(service.create(mockRequirement)).rejects.toThrow(
84
- "Firebase Error"
85
- );
86
- });
87
- });
88
-
89
- describe("getAll", () => {
90
- it("treba da vrati sve aktivne zahteve", async () => {
91
- const mockDocs = [
92
- {
93
- id: "req-1",
94
- data: () => ({ ...mockRequirement }),
95
- },
96
- {
97
- id: "req-2",
98
- data: () => ({ ...mockRequirement }),
99
- },
100
- ];
101
-
102
- (collection as jest.Mock).mockReturnValue("requirements-collection");
103
- (query as jest.Mock).mockReturnValue("filtered-query");
104
- (where as jest.Mock).mockReturnValue("where-clause");
105
- (getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
106
-
107
- const results = await service.getAll();
108
-
109
- expect(collection).toHaveBeenCalledWith(mockDb, COLLECTION);
110
- expect(query).toHaveBeenCalledWith(
111
- "requirements-collection",
112
- "where-clause"
113
- );
114
- expect(where).toHaveBeenCalledWith("isActive", "==", true);
115
- expect(results).toHaveLength(2);
116
- expect(results[0]).toEqual({
117
- id: "req-1",
118
- ...mockRequirement,
119
- });
120
- });
121
- });
122
-
123
- describe("getById", () => {
124
- it("treba da vrati zahtev po ID-u", async () => {
125
- const mockDoc = {
126
- exists: () => true,
127
- data: () => ({ ...mockRequirement }),
128
- id: "test-id",
129
- };
130
-
131
- (collection as jest.Mock).mockReturnValue("requirements-collection");
132
- (doc as jest.Mock).mockReturnValue("doc-ref");
133
- (getDoc as jest.Mock).mockResolvedValue(mockDoc);
134
-
135
- const result = await service.getById("test-id");
136
-
137
- expect(collection).toHaveBeenCalledWith(mockDb, COLLECTION);
138
- expect(doc).toHaveBeenCalledWith("requirements-collection", "test-id");
139
- expect(result).toEqual({
140
- id: "test-id",
141
- ...mockRequirement,
142
- });
143
- });
144
-
145
- it("treba da vrati null ako zahtev ne postoji", async () => {
146
- const mockDoc = {
147
- exists: () => false,
148
- };
149
-
150
- (collection as jest.Mock).mockReturnValue("requirements-collection");
151
- (doc as jest.Mock).mockReturnValue("doc-ref");
152
- (getDoc as jest.Mock).mockResolvedValue(mockDoc);
153
-
154
- const result = await service.getById("non-existent-id");
155
-
156
- expect(result).toBeNull();
157
- });
158
- });
159
-
160
- describe("update", () => {
161
- it("treba da ažurira postojeći zahtev", async () => {
162
- const updateData = {
163
- name: "Updated Name",
164
- description: "Updated Description",
165
- };
166
-
167
- (collection as jest.Mock).mockReturnValue("requirements-collection");
168
- (doc as jest.Mock).mockReturnValue("doc-ref");
169
- (updateDoc as jest.Mock).mockResolvedValue(undefined);
170
-
171
- await service.update("test-id", updateData);
172
-
173
- expect(collection).toHaveBeenCalledWith(mockDb, COLLECTION);
174
- expect(doc).toHaveBeenCalledWith("requirements-collection", "test-id");
175
- expect(updateDoc).toHaveBeenCalledWith(
176
- "doc-ref",
177
- expect.objectContaining({
178
- ...updateData,
179
- updatedAt: expect.any(Date),
180
- })
181
- );
182
- });
183
-
184
- it("treba da baci grešku ako ažuriranje ne uspe", async () => {
185
- (collection as jest.Mock).mockReturnValue("requirements-collection");
186
- (doc as jest.Mock).mockReturnValue("doc-ref");
187
- (updateDoc as jest.Mock).mockRejectedValue(new Error("Update Failed"));
188
-
189
- await expect(
190
- service.update("test-id", { name: "New Name" })
191
- ).rejects.toThrow("Update Failed");
192
- });
193
- });
194
-
195
- describe("getAllByType", () => {
196
- it("treba da vrati sve zahteve određenog tipa", async () => {
197
- const mockDocs = [
198
- {
199
- id: "req-1",
200
- data: () => ({ ...mockRequirement, type: RequirementType.PRE }),
201
- },
202
- {
203
- id: "req-2",
204
- data: () => ({ ...mockRequirement, type: RequirementType.PRE }),
205
- },
206
- ];
207
-
208
- (collection as jest.Mock).mockReturnValue("requirements-collection");
209
- (query as jest.Mock).mockReturnValue("filtered-query");
210
- (where as jest.Mock).mockReturnValue("where-clause");
211
- (getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
212
-
213
- const results = await service.getAllByType(RequirementType.PRE);
214
-
215
- expect(query).toHaveBeenCalledWith(
216
- "requirements-collection",
217
- "where-clause",
218
- "where-clause"
219
- );
220
- expect(where).toHaveBeenCalledWith("type", "==", RequirementType.PRE);
221
- expect(where).toHaveBeenCalledWith("isActive", "==", true);
222
- expect(results).toHaveLength(2);
223
- expect(results[0].type).toBe(RequirementType.PRE);
224
- });
225
- });
226
- });