@blackcode_sa/metaestetics-api 1.11.1 → 1.11.2

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 (36) hide show
  1. package/dist/admin/index.d.mts +324 -330
  2. package/dist/admin/index.d.ts +324 -330
  3. package/dist/backoffice/index.d.mts +67 -283
  4. package/dist/backoffice/index.d.ts +67 -283
  5. package/dist/backoffice/index.js +6 -114
  6. package/dist/backoffice/index.mjs +6 -112
  7. package/dist/index.d.mts +3037 -3100
  8. package/dist/index.d.ts +3037 -3100
  9. package/dist/index.js +129 -379
  10. package/dist/index.mjs +130 -379
  11. package/package.json +1 -1
  12. package/src/backoffice/expo-safe/index.ts +0 -2
  13. package/src/backoffice/services/__tests__/brand.service.test.ts +196 -0
  14. package/src/backoffice/services/__tests__/category.service.test.ts +201 -0
  15. package/src/backoffice/services/__tests__/product.service.test.ts +358 -0
  16. package/src/backoffice/services/__tests__/requirement.service.test.ts +226 -0
  17. package/src/backoffice/services/__tests__/subcategory.service.test.ts +181 -0
  18. package/src/backoffice/services/__tests__/technology.service.test.ts +1097 -0
  19. package/src/backoffice/services/technology.service.ts +10 -122
  20. package/src/backoffice/types/index.ts +0 -1
  21. package/src/backoffice/types/product.types.ts +1 -3
  22. package/src/backoffice/types/technology.types.ts +4 -4
  23. package/src/backoffice/validations/schemas.ts +9 -35
  24. package/src/services/appointment/appointment.service.ts +5 -0
  25. package/src/services/appointment/utils/appointment.utils.ts +113 -124
  26. package/src/services/procedure/procedure.service.ts +234 -434
  27. package/src/types/appointment/index.ts +37 -43
  28. package/src/types/clinic/index.ts +6 -1
  29. package/src/types/patient/medical-info.types.ts +3 -3
  30. package/src/types/procedure/index.ts +17 -20
  31. package/src/validations/appointment.schema.ts +118 -170
  32. package/src/validations/clinic.schema.ts +6 -1
  33. package/src/validations/patient/medical-info.schema.ts +2 -7
  34. package/src/backoffice/services/README.md +0 -40
  35. package/src/backoffice/services/constants.service.ts +0 -268
  36. package/src/backoffice/types/admin-constants.types.ts +0 -69
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.11.1",
4
+ "version": "1.11.2",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -34,6 +34,4 @@ export {
34
34
  export { Contraindication } from "../types/static/contraindication.types";
35
35
  export { ProcedureFamily } from "../types/static/procedure-family.types";
36
36
  export { TreatmentBenefit } from "../types/static/treatment-benefit.types";
37
- export { TreatmentBenefitDynamic } from "../types/";
38
- export { ContraindicationDynamic } from "../types/";
39
37
  export { RequirementType, TimeUnit } from "../types/requirement.types";
@@ -0,0 +1,196 @@
1
+ import { BrandService } from "../brand.service";
2
+ import { Brand } from "../../types/brand.types";
3
+ import {
4
+ collection,
5
+ doc,
6
+ getDoc,
7
+ getDocs,
8
+ addDoc,
9
+ updateDoc,
10
+ query,
11
+ where,
12
+ } from "firebase/firestore";
13
+
14
+ // Mock Firebase
15
+ jest.mock("firebase/firestore");
16
+ jest.mock("../../../config/firebase", () => ({
17
+ getFirebaseInstance: jest.fn().mockResolvedValue({
18
+ db: {},
19
+ auth: {},
20
+ }),
21
+ }));
22
+
23
+ const COLLECTION = "backoffice_brands";
24
+
25
+ describe("BrandService", () => {
26
+ let service: BrandService;
27
+
28
+ const mockBrand: Omit<Brand, "id" | "createdAt" | "updatedAt"> = {
29
+ name: "Test Brand",
30
+ manufacturer: "Test Manufacturer",
31
+ website: "https://test.com",
32
+ description: "Test Description",
33
+ isActive: true,
34
+ };
35
+
36
+ beforeEach(() => {
37
+ jest.clearAllMocks();
38
+ service = new BrandService();
39
+ });
40
+
41
+ describe("create", () => {
42
+ it("treba da kreira novi brend sa ispravnim podacima", async () => {
43
+ const mockDocRef = { id: "test-id" };
44
+ (collection as jest.Mock).mockReturnValue("brands-collection");
45
+ (addDoc as jest.Mock).mockResolvedValue(mockDocRef);
46
+
47
+ const result = await service.create(mockBrand);
48
+
49
+ expect(collection).toHaveBeenCalledWith({}, COLLECTION);
50
+ expect(addDoc).toHaveBeenCalledWith(
51
+ "brands-collection",
52
+ expect.objectContaining({
53
+ ...mockBrand,
54
+ createdAt: expect.any(Date),
55
+ updatedAt: expect.any(Date),
56
+ })
57
+ );
58
+ expect(result).toEqual({
59
+ id: "test-id",
60
+ ...mockBrand,
61
+ createdAt: expect.any(Date),
62
+ updatedAt: expect.any(Date),
63
+ });
64
+ });
65
+ });
66
+
67
+ describe("getAll", () => {
68
+ it("treba da vrati sve aktivne brendove", async () => {
69
+ const mockDocs = [
70
+ {
71
+ id: "test-id-1",
72
+ data: () => ({
73
+ ...mockBrand,
74
+ createdAt: new Date(),
75
+ updatedAt: new Date(),
76
+ }),
77
+ },
78
+ {
79
+ id: "test-id-2",
80
+ data: () => ({
81
+ ...mockBrand,
82
+ name: "Test Brand 2",
83
+ createdAt: new Date(),
84
+ updatedAt: new Date(),
85
+ }),
86
+ },
87
+ ];
88
+
89
+ (collection as jest.Mock).mockReturnValue("brands-collection");
90
+ (query as jest.Mock).mockReturnValue("filtered-query");
91
+ (where as jest.Mock).mockReturnValue("where-clause");
92
+ (getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
93
+
94
+ const result = await service.getAll();
95
+
96
+ expect(collection).toHaveBeenCalledWith({}, COLLECTION);
97
+ expect(query).toHaveBeenCalledWith("brands-collection", "where-clause");
98
+ expect(where).toHaveBeenCalledWith("isActive", "==", true);
99
+ expect(result).toHaveLength(2);
100
+ expect(result[0]).toEqual({
101
+ id: "test-id-1",
102
+ ...mockBrand,
103
+ createdAt: expect.any(Date),
104
+ updatedAt: expect.any(Date),
105
+ });
106
+ });
107
+ });
108
+
109
+ describe("update", () => {
110
+ it("treba da ažurira postojeći brend", async () => {
111
+ const updateData = { name: "Updated Brand" };
112
+
113
+ (collection as jest.Mock).mockReturnValue("brands-collection");
114
+ (doc as jest.Mock).mockReturnValue("doc-ref");
115
+ (getDoc as jest.Mock).mockResolvedValue({
116
+ exists: () => true,
117
+ id: "test-id",
118
+ data: () => ({
119
+ ...mockBrand,
120
+ ...updateData,
121
+ createdAt: new Date(),
122
+ updatedAt: new Date(),
123
+ }),
124
+ });
125
+ (updateDoc as jest.Mock).mockResolvedValue(undefined);
126
+
127
+ const result = await service.update("test-id", updateData);
128
+
129
+ expect(collection).toHaveBeenCalledWith({}, COLLECTION);
130
+ expect(doc).toHaveBeenCalledWith("brands-collection", "test-id");
131
+ expect(updateDoc).toHaveBeenCalledWith(
132
+ "doc-ref",
133
+ expect.objectContaining({
134
+ ...updateData,
135
+ updatedAt: expect.any(Date),
136
+ })
137
+ );
138
+ });
139
+ });
140
+
141
+ describe("delete", () => {
142
+ it("treba da izvrši soft delete brenda", async () => {
143
+ (collection as jest.Mock).mockReturnValue("brands-collection");
144
+ (doc as jest.Mock).mockReturnValue("doc-ref");
145
+ (updateDoc as jest.Mock).mockResolvedValue(undefined);
146
+
147
+ await service.delete("test-id");
148
+
149
+ expect(collection).toHaveBeenCalledWith({}, COLLECTION);
150
+ expect(doc).toHaveBeenCalledWith("brands-collection", "test-id");
151
+ expect(updateDoc).toHaveBeenCalledWith("doc-ref", {
152
+ isActive: false,
153
+ updatedAt: expect.any(Date),
154
+ });
155
+ });
156
+ });
157
+
158
+ describe("getById", () => {
159
+ it("treba da vrati brend po ID-u", async () => {
160
+ (collection as jest.Mock).mockReturnValue("brands-collection");
161
+ (doc as jest.Mock).mockReturnValue("doc-ref");
162
+ (getDoc as jest.Mock).mockResolvedValue({
163
+ exists: () => true,
164
+ id: "test-id",
165
+ data: () => ({
166
+ ...mockBrand,
167
+ createdAt: new Date(),
168
+ updatedAt: new Date(),
169
+ }),
170
+ });
171
+
172
+ const result = await service.getById("test-id");
173
+
174
+ expect(collection).toHaveBeenCalledWith({}, COLLECTION);
175
+ expect(doc).toHaveBeenCalledWith("brands-collection", "test-id");
176
+ expect(result).toEqual({
177
+ id: "test-id",
178
+ ...mockBrand,
179
+ createdAt: expect.any(Date),
180
+ updatedAt: expect.any(Date),
181
+ });
182
+ });
183
+
184
+ it("treba da vrati null ako brend ne postoji", async () => {
185
+ (collection as jest.Mock).mockReturnValue("brands-collection");
186
+ (doc as jest.Mock).mockReturnValue("doc-ref");
187
+ (getDoc as jest.Mock).mockResolvedValue({
188
+ exists: () => false,
189
+ });
190
+
191
+ const result = await service.getById("non-existent-id");
192
+
193
+ expect(result).toBeNull();
194
+ });
195
+ });
196
+ });
@@ -0,0 +1,201 @@
1
+ import { CategoryService } from "../category.service";
2
+ import { Category } from "../../types/category.types";
3
+ import { ProcedureFamily } from "../../types/static/procedure-family.types";
4
+ import {
5
+ collection,
6
+ doc,
7
+ getDoc,
8
+ getDocs,
9
+ addDoc,
10
+ updateDoc,
11
+ query,
12
+ where,
13
+ } from "firebase/firestore";
14
+
15
+ // Mock Firebase
16
+ jest.mock("firebase/firestore");
17
+ jest.mock("../../../config/firebase", () => ({
18
+ getFirebaseInstance: jest.fn().mockResolvedValue({
19
+ db: {},
20
+ auth: {},
21
+ }),
22
+ }));
23
+
24
+ const COLLECTION = "backoffice_categories";
25
+
26
+ describe("CategoryService", () => {
27
+ let service: CategoryService;
28
+
29
+ const mockCategory: Omit<Category, "id" | "createdAt" | "updatedAt"> = {
30
+ name: "Test Category",
31
+ description: "Test Description",
32
+ family: ProcedureFamily.AESTHETICS,
33
+ isActive: true,
34
+ };
35
+
36
+ beforeEach(() => {
37
+ jest.clearAllMocks();
38
+ service = new CategoryService();
39
+ });
40
+
41
+ describe("create", () => {
42
+ it("treba da kreira novu kategoriju", async () => {
43
+ const mockDocRef = { id: "test-id" };
44
+ (collection as jest.Mock).mockReturnValue("categories-collection");
45
+ (addDoc as jest.Mock).mockResolvedValue(mockDocRef);
46
+
47
+ const result = await service.create(mockCategory);
48
+
49
+ expect(collection).toHaveBeenCalledWith({}, COLLECTION);
50
+ expect(addDoc).toHaveBeenCalledWith(
51
+ "categories-collection",
52
+ expect.objectContaining({
53
+ ...mockCategory,
54
+ createdAt: expect.any(Date),
55
+ updatedAt: expect.any(Date),
56
+ })
57
+ );
58
+ expect(result).toEqual({
59
+ id: "test-id",
60
+ ...mockCategory,
61
+ createdAt: expect.any(Date),
62
+ updatedAt: expect.any(Date),
63
+ });
64
+ });
65
+ });
66
+
67
+ describe("getAll", () => {
68
+ it("treba da vrati sve aktivne kategorije", async () => {
69
+ const mockDocs = [
70
+ {
71
+ id: "cat-1",
72
+ data: () => ({
73
+ ...mockCategory,
74
+ createdAt: new Date(),
75
+ updatedAt: new Date(),
76
+ }),
77
+ },
78
+ {
79
+ id: "cat-2",
80
+ data: () => ({
81
+ ...mockCategory,
82
+ name: "Test Category 2",
83
+ createdAt: new Date(),
84
+ updatedAt: new Date(),
85
+ }),
86
+ },
87
+ ];
88
+
89
+ (collection as jest.Mock).mockReturnValue("categories-collection");
90
+ (query as jest.Mock).mockReturnValue("filtered-query");
91
+ (where as jest.Mock).mockReturnValue("where-clause");
92
+ (getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
93
+
94
+ const results = await service.getAll();
95
+
96
+ expect(collection).toHaveBeenCalledWith({}, COLLECTION);
97
+ expect(query).toHaveBeenCalledWith(
98
+ "categories-collection",
99
+ "where-clause"
100
+ );
101
+ expect(where).toHaveBeenCalledWith("isActive", "==", true);
102
+ expect(results).toHaveLength(2);
103
+ expect(results[0]).toEqual({
104
+ id: "cat-1",
105
+ ...mockCategory,
106
+ createdAt: expect.any(Date),
107
+ updatedAt: expect.any(Date),
108
+ });
109
+ });
110
+ });
111
+
112
+ describe("getAllByFamily", () => {
113
+ it("treba da vrati sve kategorije za određenu familiju", async () => {
114
+ const mockDocs = [
115
+ {
116
+ id: "cat-1",
117
+ data: () => ({
118
+ ...mockCategory,
119
+ family: ProcedureFamily.AESTHETICS,
120
+ createdAt: new Date(),
121
+ updatedAt: new Date(),
122
+ }),
123
+ },
124
+ ];
125
+
126
+ (collection as jest.Mock).mockReturnValue("categories-collection");
127
+ (query as jest.Mock).mockReturnValue("filtered-query");
128
+ (where as jest.Mock).mockReturnValue("where-clause");
129
+ (getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
130
+
131
+ const results = await service.getAllByFamily(ProcedureFamily.AESTHETICS);
132
+
133
+ expect(query).toHaveBeenCalledWith(
134
+ "categories-collection",
135
+ "where-clause",
136
+ "where-clause"
137
+ );
138
+ expect(where).toHaveBeenCalledWith(
139
+ "family",
140
+ "==",
141
+ ProcedureFamily.AESTHETICS
142
+ );
143
+ expect(where).toHaveBeenCalledWith("isActive", "==", true);
144
+ expect(results).toHaveLength(1);
145
+ expect(results[0].family).toBe(ProcedureFamily.AESTHETICS);
146
+ });
147
+ });
148
+
149
+ describe("update", () => {
150
+ it("treba da ažurira postojeću kategoriju", async () => {
151
+ const updateData = { name: "Updated Category" };
152
+
153
+ (collection as jest.Mock).mockReturnValue("categories-collection");
154
+ (doc as jest.Mock).mockReturnValue("doc-ref");
155
+ (updateDoc as jest.Mock).mockResolvedValue(undefined);
156
+ (getDoc as jest.Mock).mockResolvedValue({
157
+ exists: () => true,
158
+ id: "test-id",
159
+ data: () => ({
160
+ ...mockCategory,
161
+ ...updateData,
162
+ createdAt: new Date(),
163
+ updatedAt: new Date(),
164
+ }),
165
+ });
166
+
167
+ const result = await service.update("test-id", updateData);
168
+
169
+ expect(collection).toHaveBeenCalledWith({}, COLLECTION);
170
+ expect(doc).toHaveBeenCalledWith("categories-collection", "test-id");
171
+ expect(updateDoc).toHaveBeenCalledWith("doc-ref", {
172
+ ...updateData,
173
+ updatedAt: expect.any(Date),
174
+ });
175
+ expect(result).toEqual({
176
+ id: "test-id",
177
+ ...mockCategory,
178
+ ...updateData,
179
+ createdAt: expect.any(Date),
180
+ updatedAt: expect.any(Date),
181
+ });
182
+ });
183
+ });
184
+
185
+ describe("delete", () => {
186
+ it("treba da izvrši soft delete kategorije", async () => {
187
+ (collection as jest.Mock).mockReturnValue("categories-collection");
188
+ (doc as jest.Mock).mockReturnValue("doc-ref");
189
+ (updateDoc as jest.Mock).mockResolvedValue(undefined);
190
+
191
+ await service.delete("test-id");
192
+
193
+ expect(collection).toHaveBeenCalledWith({}, COLLECTION);
194
+ expect(doc).toHaveBeenCalledWith("categories-collection", "test-id");
195
+ expect(updateDoc).toHaveBeenCalledWith("doc-ref", {
196
+ isActive: false,
197
+ updatedAt: expect.any(Date),
198
+ });
199
+ });
200
+ });
201
+ });