@glissandoo/lib 1.31.0 → 1.32.1

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.
@@ -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: (string: string, values: MetaNotificationData, lang: LanguagesTypes) => string;
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 = (string, values, lang) => {
24
+ const replaceKeysNotification = (text, values, lang) => {
25
25
  const dateLang = (0, lang_1.getDateLang)(lang);
26
- const matches = string.match(/(\{).+?(\})/g);
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 = string;
33
- if (matches && matches.length > 0) {
34
- matches.forEach((match) => {
35
- const value = match.slice(1, -1);
36
- const typeKeyMatch = value.split(':');
37
- const type = typeKeyMatch[0];
38
- const key = typeKeyMatch[1];
39
- switch (type) {
40
- case 'instrument': {
41
- const instrumentId = (0, get_1.default)(newValues, key.split('.'));
42
- const instrument = new Instrument_1.default(instrumentId, lang);
43
- if (instrument) {
44
- replaceString = replaceString.replace(match, instrument.name.toLowerCase());
45
- }
46
- break;
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
- case 'string': {
64
- replaceString = replaceString.replace(match, (0, get_1.default)(newValues, key.split('.')));
65
- break;
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
- default: {
68
- break;
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
  };
@@ -18,4 +18,5 @@ export default class EventoBasic<D> extends ModelWithLang<EventBasicData & D> {
18
18
  get duration(): number;
19
19
  get isOutDate(): boolean;
20
20
  get isHappening(): boolean;
21
+ get timezone(): string;
21
22
  }
@@ -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;
@@ -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;
@@ -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
  }
@@ -11,4 +11,5 @@ export default class EventoTiny {
11
11
  get isPractice(): boolean;
12
12
  get isPerformance(): boolean;
13
13
  get datetime(): FirebaseFirestore.Timestamp;
14
+ get timezone(): string;
14
15
  }
@@ -29,5 +29,8 @@ class EventoTiny {
29
29
  get datetime() {
30
30
  return this.data.datetime;
31
31
  }
32
+ get timezone() {
33
+ return this.data.timezone || 'Europe/Madrid';
34
+ }
32
35
  }
33
36
  exports.default = EventoTiny;
@@ -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;
@@ -1,4 +1,4 @@
1
- import { DocumentReference, DocumentSnapshot } from '@google-cloud/firestore';
1
+ import { DocumentReference, DocumentSnapshot, Timestamp } from '@google-cloud/firestore';
2
2
  import { PlansGroup } from '../../helpers/plans';
3
3
  import { LanguagesTypes } from '../../lang';
4
4
  import GroupBasic from './basic';
@@ -17,8 +17,8 @@ export default class Group extends GroupBasic<GroupData> {
17
17
  get invitationEmails(): string[];
18
18
  get shortDynamicLink(): string;
19
19
  get admins(): string[];
20
- get createdAt(): FirebaseFirestore.Timestamp;
21
- get deletedAt(): FirebaseFirestore.Timestamp | null;
20
+ get createdAt(): Timestamp;
21
+ get deletedAt(): Timestamp | null;
22
22
  get repertoryCount(): number;
23
23
  get eventCount(): Record<import("../Evento/types").EventType, number>;
24
24
  get performanceCount(): number;
@@ -60,10 +60,11 @@ export default class Group extends GroupBasic<GroupData> {
60
60
  get stageTemplatesList(): (import("../../helpers/types").StageTemplate & {
61
61
  id: string;
62
62
  })[];
63
- get firstAnswerAt(): FirebaseFirestore.Timestamp | null;
63
+ get firstAnswerAt(): Timestamp | null;
64
64
  get repertoireTags(): Record<string, import("./types").GroupRepertoireTag>;
65
65
  get repertoireTagsList(): (import("./types").GroupRepertoireTag & {
66
66
  id: string;
67
67
  })[];
68
68
  getRepertoireTagName(id: string): string | null;
69
+ get trialEndAt(): Timestamp;
69
70
  }
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const firestore_1 = require("@google-cloud/firestore");
6
7
  const date_fns_1 = require("date-fns");
7
8
  const lodash_1 = require("lodash");
8
9
  const orders_1 = require("../../helpers/musicStyles/orders");
@@ -148,7 +149,7 @@ class Group extends basic_1.default {
148
149
  return this.data.metadata || {};
149
150
  }
150
151
  get isExpiredTrial() {
151
- const isOutDateTrial = (0, date_fns_1.isBefore)(this.createdAt.toDate(), (0, date_fns_1.subMonths)(new Date(), 1));
152
+ const isOutDateTrial = (0, date_fns_1.isPast)(this.trialEndAt.toDate());
152
153
  const members = this.activePlayers.length;
153
154
  const isAboveMembersLimitPlanFree = members > plans_1.membersPerPlan[plans_1.PlansGroup.Piano];
154
155
  return this.status !== types_1.GroupStatus.Premium && isOutDateTrial && isAboveMembersLimitPlanFree;
@@ -174,5 +175,8 @@ class Group extends basic_1.default {
174
175
  const tag = this.repertoireTags[id];
175
176
  return tag.default ? (0, lang_1.getTranslation)(tag.title, this.lang) : tag.title;
176
177
  }
178
+ get trialEndAt() {
179
+ return this.data.trialEndAt || firestore_1.Timestamp.fromDate((0, date_fns_1.addMonths)(this.createdAt.toDate(), 1));
180
+ }
177
181
  }
178
182
  exports.default = Group;
@@ -110,6 +110,7 @@ export interface GroupData extends GroupBasicData {
110
110
  metadata: Record<string, string>;
111
111
  firstAnswerAt: Timestamp | null;
112
112
  repertoireTags: Record<string, GroupRepertoireTag>;
113
+ trialEndAt: Timestamp | null;
113
114
  readonly owner: DocumentReference;
114
115
  readonly createdAt: Timestamp;
115
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glissandoo/lib",
3
- "version": "1.31.0",
3
+ "version": "1.32.1",
4
4
  "description": "Glissandoo library js",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",