@blackcode_sa/metaestetics-api 1.6.13 → 1.6.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/admin/index.js +4615 -37524
- package/dist/admin/index.mjs +4584 -37515
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/admin/booking/booking.admin.ts +5 -11
- package/src/admin/notifications/notifications.admin.ts +19 -24
- package/src/admin/requirements/patient-requirements.admin.service.ts +25 -32
- package/src/types/clinic/index.ts +19 -27
- package/src/types/patient/index.ts +20 -22
- package/src/utils/TIMESTAMPS.md +176 -0
- package/src/utils/TimestampUtils.ts +136 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import * as admin from "firebase-admin";
|
|
2
|
+
import { Timestamp as ClientTimestamp } from "firebase/firestore";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Utilities for managing timestamps across client and server-side Firebase code.
|
|
6
|
+
* This module provides conversion functions to ensure timestamp compatibility
|
|
7
|
+
* between admin and client Firebase SDKs.
|
|
8
|
+
*/
|
|
9
|
+
export class TimestampUtils {
|
|
10
|
+
/**
|
|
11
|
+
* Converts an admin Firestore Timestamp to a client Firestore Timestamp
|
|
12
|
+
* @param adminTimestamp - Admin SDK Timestamp (from firebase-admin)
|
|
13
|
+
* @returns A client SDK Timestamp (from firebase/firestore) with same seconds/nanoseconds or null if input is null
|
|
14
|
+
*/
|
|
15
|
+
static adminToClient(
|
|
16
|
+
adminTimestamp: admin.firestore.Timestamp | null
|
|
17
|
+
): ClientTimestamp | null {
|
|
18
|
+
if (!adminTimestamp) return null;
|
|
19
|
+
|
|
20
|
+
return new ClientTimestamp(
|
|
21
|
+
adminTimestamp.seconds,
|
|
22
|
+
adminTimestamp.nanoseconds
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Converts a client Firestore Timestamp to an admin Firestore Timestamp
|
|
28
|
+
* @param clientTimestamp - Client SDK Timestamp (from firebase/firestore)
|
|
29
|
+
* @returns An admin SDK Timestamp (from firebase-admin) with same seconds/nanoseconds or null if input is null
|
|
30
|
+
*/
|
|
31
|
+
static clientToAdmin(
|
|
32
|
+
clientTimestamp: ClientTimestamp | null
|
|
33
|
+
): admin.firestore.Timestamp | null {
|
|
34
|
+
if (!clientTimestamp) return null;
|
|
35
|
+
|
|
36
|
+
return new admin.firestore.Timestamp(
|
|
37
|
+
clientTimestamp.seconds,
|
|
38
|
+
clientTimestamp.nanoseconds
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Creates a client-compatible timestamp for the current time
|
|
44
|
+
* @returns A client SDK Timestamp (from firebase/firestore) for the current time
|
|
45
|
+
*/
|
|
46
|
+
static nowAsClient(): ClientTimestamp {
|
|
47
|
+
const now = admin.firestore.Timestamp.now();
|
|
48
|
+
return this.adminToClient(now) as ClientTimestamp;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Converts a Date object to a client Firestore Timestamp
|
|
53
|
+
* @param date - JavaScript Date object
|
|
54
|
+
* @returns A client SDK Timestamp (from firebase/firestore) or null if input is null
|
|
55
|
+
*/
|
|
56
|
+
static dateToClientTimestamp(date: Date | null): ClientTimestamp | null {
|
|
57
|
+
if (!date) return null;
|
|
58
|
+
|
|
59
|
+
return ClientTimestamp.fromDate(date);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Converts a Date object to an admin Firestore Timestamp
|
|
64
|
+
* @param date - JavaScript Date object
|
|
65
|
+
* @returns An admin SDK Timestamp (from firebase-admin) or null if input is null
|
|
66
|
+
*/
|
|
67
|
+
static dateToAdminTimestamp(
|
|
68
|
+
date: Date | null
|
|
69
|
+
): admin.firestore.Timestamp | null {
|
|
70
|
+
if (!date) return null;
|
|
71
|
+
|
|
72
|
+
return admin.firestore.Timestamp.fromDate(date);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Deeply converts all admin Firestore Timestamps in an object to client Firestore Timestamps
|
|
77
|
+
* @param obj - Object that may contain admin Firestore Timestamps
|
|
78
|
+
* @returns The same object with all admin Timestamps converted to client Timestamps
|
|
79
|
+
*/
|
|
80
|
+
static convertObjectTimestampsAdminToClient<T>(obj: T): T {
|
|
81
|
+
if (!obj || typeof obj !== "object") {
|
|
82
|
+
return obj;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (obj instanceof admin.firestore.Timestamp) {
|
|
86
|
+
return this.adminToClient(obj) as unknown as T;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (Array.isArray(obj)) {
|
|
90
|
+
return obj.map((item) =>
|
|
91
|
+
this.convertObjectTimestampsAdminToClient(item)
|
|
92
|
+
) as unknown as T;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const result = { ...obj } as any;
|
|
96
|
+
|
|
97
|
+
for (const key in result) {
|
|
98
|
+
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
|
99
|
+
result[key] = this.convertObjectTimestampsAdminToClient(result[key]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return result as T;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Deeply converts all client Firestore Timestamps in an object to admin Firestore Timestamps
|
|
108
|
+
* @param obj - Object that may contain client Firestore Timestamps
|
|
109
|
+
* @returns The same object with all client Timestamps converted to admin Timestamps
|
|
110
|
+
*/
|
|
111
|
+
static convertObjectTimestampsClientToAdmin<T>(obj: T): T {
|
|
112
|
+
if (!obj || typeof obj !== "object") {
|
|
113
|
+
return obj;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (obj instanceof ClientTimestamp) {
|
|
117
|
+
return this.clientToAdmin(obj) as unknown as T;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (Array.isArray(obj)) {
|
|
121
|
+
return obj.map((item) =>
|
|
122
|
+
this.convertObjectTimestampsClientToAdmin(item)
|
|
123
|
+
) as unknown as T;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const result = { ...obj } as any;
|
|
127
|
+
|
|
128
|
+
for (const key in result) {
|
|
129
|
+
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
|
130
|
+
result[key] = this.convertObjectTimestampsClientToAdmin(result[key]);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return result as T;
|
|
135
|
+
}
|
|
136
|
+
}
|