@glissandoo/lib 1.31.0 → 1.32.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.
- package/helpers/utils.d.ts +1 -1
- package/helpers/utils.js +43 -38
- package/models/Evento/basic.d.ts +1 -0
- package/models/Evento/basic.js +5 -0
- package/models/Evento/index.d.ts +0 -11
- package/models/Evento/index.js +0 -21
- package/models/Evento/tiny.d.ts +1 -0
- package/models/Evento/tiny.js +3 -0
- package/models/Evento/types.d.ts +1 -1
- package/package.json +1 -1
package/helpers/utils.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { LanguagesTypes } from '../lang';
|
|
|
2
2
|
import { MetaNotificationData } from '../models/User/Notification/types';
|
|
3
3
|
import { Descendant } from './slate';
|
|
4
4
|
export declare const replaceVarsBrackets: (string: string, values: MetaNotificationData) => string;
|
|
5
|
-
export declare const replaceKeysNotification: (
|
|
5
|
+
export declare const replaceKeysNotification: (text: string, values: MetaNotificationData, lang: LanguagesTypes) => string;
|
|
6
6
|
export declare const serializeSlateBlock: (nodes: Descendant[]) => string;
|
|
7
7
|
export declare const orderByMatch: <T>(list: T[], field: keyof T, order: string[]) => T[];
|
package/helpers/utils.js
CHANGED
|
@@ -21,54 +21,59 @@ const replaceVarsBrackets = (string, values) => {
|
|
|
21
21
|
return replaceString;
|
|
22
22
|
};
|
|
23
23
|
exports.replaceVarsBrackets = replaceVarsBrackets;
|
|
24
|
-
const replaceKeysNotification = (
|
|
24
|
+
const replaceKeysNotification = (text, values, lang) => {
|
|
25
25
|
const dateLang = (0, lang_1.getDateLang)(lang);
|
|
26
|
-
const matches =
|
|
26
|
+
const matches = text.match(/(\{).+?(\})/g);
|
|
27
27
|
const { extra, ...other } = values;
|
|
28
28
|
const newValues = { extra };
|
|
29
29
|
Object.keys(other || {}).forEach((key) => Object.assign(newValues, {
|
|
30
30
|
[key]: Object.values((0, get_1.default)(other, key)),
|
|
31
31
|
}));
|
|
32
|
-
let replaceString =
|
|
33
|
-
if (matches
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
case 'date': {
|
|
49
|
-
const timestamp = (0, get_1.default)(newValues, key.split('.'));
|
|
50
|
-
if (!timestamp) {
|
|
51
|
-
replaceString = replaceString.replace(match, '');
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
const dateUTC = (0, date_fns_tz_1.utcToZonedTime)(timestamp.toDate(), 'Europe/Madrid');
|
|
55
|
-
const formatValue = typeKeyMatch[2] || 'shortDate';
|
|
56
|
-
const dateFormat = (0, date_fns_1.format)(dateUTC, (0, get_1.default)(dateLang.format, formatValue), {
|
|
57
|
-
locale: dateLang.locale,
|
|
58
|
-
});
|
|
59
|
-
replaceString = replaceString.replace(match, dateFormat);
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
32
|
+
let replaceString = text;
|
|
33
|
+
if (!matches || matches.length === 0) {
|
|
34
|
+
return replaceString;
|
|
35
|
+
}
|
|
36
|
+
for (const match of matches) {
|
|
37
|
+
const value = match.slice(1, -1);
|
|
38
|
+
const typeKeyMatch = value.split(':');
|
|
39
|
+
const type = typeKeyMatch[0];
|
|
40
|
+
const key = typeKeyMatch[1];
|
|
41
|
+
const path = key.split('.');
|
|
42
|
+
switch (type) {
|
|
43
|
+
case 'instrument': {
|
|
44
|
+
const instrumentId = (0, get_1.default)(newValues, path);
|
|
45
|
+
const instrument = new Instrument_1.default(instrumentId, lang);
|
|
46
|
+
if (instrument) {
|
|
47
|
+
replaceString = replaceString.replace(match, instrument.name.toLowerCase());
|
|
62
48
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case 'date': {
|
|
52
|
+
const timestamp = (0, get_1.default)(newValues, path);
|
|
53
|
+
if (!timestamp) {
|
|
54
|
+
replaceString = replaceString.replace(match, '');
|
|
66
55
|
}
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
else {
|
|
57
|
+
const timezonePath = path;
|
|
58
|
+
timezonePath[path.length - 1] = 'timezone';
|
|
59
|
+
const timezone = (0, get_1.default)(newValues, timezonePath) || 'Europe/Madrid';
|
|
60
|
+
const dateUTC = (0, date_fns_tz_1.utcToZonedTime)(timestamp.toDate(), timezone);
|
|
61
|
+
const formatValue = typeKeyMatch[2] || 'shortDate';
|
|
62
|
+
const dateFormat = (0, date_fns_1.format)(dateUTC, (0, get_1.default)(dateLang.format, formatValue), {
|
|
63
|
+
locale: dateLang.locale,
|
|
64
|
+
});
|
|
65
|
+
replaceString = replaceString.replace(match, dateFormat);
|
|
69
66
|
}
|
|
67
|
+
break;
|
|
70
68
|
}
|
|
71
|
-
|
|
69
|
+
case 'string': {
|
|
70
|
+
replaceString = replaceString.replace(match, (0, get_1.default)(newValues, path));
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
default: {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
72
77
|
}
|
|
73
78
|
return replaceString;
|
|
74
79
|
};
|
package/models/Evento/basic.d.ts
CHANGED
package/models/Evento/basic.js
CHANGED
|
@@ -16,6 +16,7 @@ class EventoBasic extends lang_2.default {
|
|
|
16
16
|
displayName: this.displayName,
|
|
17
17
|
datetime: this.datetime,
|
|
18
18
|
type: this.type,
|
|
19
|
+
timezone: this.data.timezone,
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
22
|
get basicInfo() {
|
|
@@ -26,6 +27,7 @@ class EventoBasic extends lang_2.default {
|
|
|
26
27
|
datetime: this.datetime,
|
|
27
28
|
datetimeEnd: this.datetimeEnd,
|
|
28
29
|
type: this.type,
|
|
30
|
+
timezone: this.data.timezone,
|
|
29
31
|
};
|
|
30
32
|
}
|
|
31
33
|
get displayName() {
|
|
@@ -67,5 +69,8 @@ class EventoBasic extends lang_2.default {
|
|
|
67
69
|
get isHappening() {
|
|
68
70
|
return (0, date_fns_1.isPast)(this.datetime.toDate()) && (0, date_fns_1.isFuture)(this.datetimeEnd.toDate());
|
|
69
71
|
}
|
|
72
|
+
get timezone() {
|
|
73
|
+
return this.data.timezone || 'Europe/Madrid';
|
|
74
|
+
}
|
|
70
75
|
}
|
|
71
76
|
exports.default = EventoBasic;
|
package/models/Evento/index.d.ts
CHANGED
|
@@ -53,19 +53,8 @@ export default class Evento extends EventoPromoter<EventData> {
|
|
|
53
53
|
get declinedRollCallPlayers(): string[];
|
|
54
54
|
get isRollCalled(): boolean;
|
|
55
55
|
get isActiveRollCall(): boolean;
|
|
56
|
-
/** @deprecated */
|
|
57
|
-
get viewers(): Record<string, import("./types").EventViewer>;
|
|
58
|
-
/** @deprecated */
|
|
59
|
-
get listViewers(): (import("./types").EventViewer & {
|
|
60
|
-
id: string;
|
|
61
|
-
})[];
|
|
62
|
-
/** @deprecated */
|
|
63
|
-
get totalViews(): number;
|
|
64
56
|
get templateId(): string | null;
|
|
65
57
|
get repeat(): import("./types").EventRepeatType | null;
|
|
66
|
-
get timezone(): string;
|
|
67
|
-
/** @deprecated */
|
|
68
|
-
getViewer(userId: string): import("./types").EventViewer | null;
|
|
69
58
|
isPlayer: (userId: string) => boolean;
|
|
70
59
|
getPlayer: (userId: string) => EventPlayerBasicData | null;
|
|
71
60
|
isPlayerConfirmed(player: EventPlayerBasicData): boolean;
|
package/models/Evento/index.js
CHANGED
|
@@ -152,33 +152,12 @@ class Evento extends promoter_1.default {
|
|
|
152
152
|
get isActiveRollCall() {
|
|
153
153
|
return (0, date_fns_1.isPast)((0, date_fns_1.addHours)(this.datetime.toDate(), -1));
|
|
154
154
|
}
|
|
155
|
-
/** @deprecated */
|
|
156
|
-
get viewers() {
|
|
157
|
-
return this.data.viewers || {};
|
|
158
|
-
}
|
|
159
|
-
/** @deprecated */
|
|
160
|
-
get listViewers() {
|
|
161
|
-
return Object.keys(this.viewers).map((userId) => Object.assign(this.viewers[userId], { id: userId }));
|
|
162
|
-
}
|
|
163
|
-
/** @deprecated */
|
|
164
|
-
get totalViews() {
|
|
165
|
-
return this.listViewers
|
|
166
|
-
.map((viewer) => viewer.count || 0)
|
|
167
|
-
.reduce((acc, current) => acc + current);
|
|
168
|
-
}
|
|
169
155
|
get templateId() {
|
|
170
156
|
return this.data.templateId || null;
|
|
171
157
|
}
|
|
172
158
|
get repeat() {
|
|
173
159
|
return this.data.repeat || null;
|
|
174
160
|
}
|
|
175
|
-
get timezone() {
|
|
176
|
-
return this.data.timezone || 'Europe/Madrid';
|
|
177
|
-
}
|
|
178
|
-
/** @deprecated */
|
|
179
|
-
getViewer(userId) {
|
|
180
|
-
return userId in this.viewers ? this.viewers[userId] : null;
|
|
181
|
-
}
|
|
182
161
|
isPlayerConfirmed(player) {
|
|
183
162
|
return player.status === types_1.EventPlayerStatus.Confirmed;
|
|
184
163
|
}
|
package/models/Evento/tiny.d.ts
CHANGED
package/models/Evento/tiny.js
CHANGED
package/models/Evento/types.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export interface EventTinyData {
|
|
|
59
59
|
displayName: string | null;
|
|
60
60
|
datetime: Timestamp;
|
|
61
61
|
type: EventType;
|
|
62
|
+
timezone: string;
|
|
62
63
|
}
|
|
63
64
|
export interface EventBasicData extends EventTinyData {
|
|
64
65
|
locality: string | null;
|
|
@@ -94,7 +95,6 @@ export interface EventData extends EventPromoterData {
|
|
|
94
95
|
repeat: EventRepeatType | null;
|
|
95
96
|
stage: EventStage | null;
|
|
96
97
|
stageTemplateId: string | null;
|
|
97
|
-
timezone: string;
|
|
98
98
|
readonly owner: DocumentReference;
|
|
99
99
|
readonly createdAt: Timestamp;
|
|
100
100
|
readonly createdOn: EventCreatedOn;
|