@dev-crew-berlin/enter-js-utils 0.20.0 → 0.22.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.
@@ -8,7 +8,7 @@ export declare type AttendeeJSON = {
8
8
  userdata: Record<string, FieldValue>;
9
9
  tags: string[] | null;
10
10
  language: string | null;
11
- time: Date;
11
+ time: string;
12
12
  rsvp: Record<string, number | null>;
13
13
  checkin: Record<string, CheckinsJSON>;
14
14
  companions: {
@@ -48,6 +48,8 @@ export declare class Attendee {
48
48
  } | null;
49
49
  deleted: boolean;
50
50
  constructor(rawAttendee: RawAttendee);
51
+ static fromJSON(json: AttendeeJSON): Attendee;
52
+ toJSON(): AttendeeJSON;
51
53
  getRsvpCountForTag(checkinTag: string): number;
52
54
  getResponseForTag(checkinTag: string): 'no-response' | 'negative-repsone' | 'positive-response';
53
55
  getCheckinsForTag(checkinTag: string): Checkins;
@@ -18,6 +18,32 @@ export class Attendee {
18
18
  this.deleted = rawAttendee.deleted;
19
19
  }
20
20
 
21
+ static fromJSON(json) {
22
+ const checkin = Object.entries(json.checkin).reduce((obj, [tag, checkins]) => {
23
+ obj[tag] = Checkins.fromJSON(checkins);
24
+ return obj;
25
+ }, {});
26
+ return new Attendee({ ...json,
27
+ time: new Date(json.time),
28
+ checkin
29
+ });
30
+ }
31
+
32
+ toJSON() {
33
+ // this is exactly what js also provides out of the box
34
+ // but then typescript complains that there is no toJSON function
35
+ // so we implement it here again by hand
36
+ // convert each checkin to its json representation
37
+ const checkin = Object.entries(this.checkin).reduce((obj, [tag, checkins]) => {
38
+ obj[tag] = checkins.toJSON();
39
+ return obj;
40
+ }, {});
41
+ return { ...this,
42
+ time: this.time.toISOString(),
43
+ checkin
44
+ };
45
+ }
46
+
21
47
  getRsvpCountForTag(checkinTag) {
22
48
  const rsvp = this.rsvp[checkinTag];
23
49
  if (!rsvp) return 0;
@@ -16,6 +16,7 @@ export declare class Checkins {
16
16
  checkins: Checkin[];
17
17
  deleted: string[];
18
18
  constructor(rawCheckins: RawCheckins);
19
+ static fromJSON(json: CheckinsJSON): Checkins;
19
20
  toJSON(): CheckinsJSON;
20
21
  getAllCheckins(): Checkin[];
21
22
  getOtherCheckins(): Checkin[];
@@ -6,6 +6,15 @@ export class Checkins {
6
6
  this.deleted = rawCheckins.deleted;
7
7
  }
8
8
 
9
+ static fromJSON(json) {
10
+ return new Checkins({
11
+ checkins: json.checkins.map(checkin => ({ ...checkin,
12
+ time: new Date(checkin.time)
13
+ })),
14
+ deleted: json.deleted
15
+ });
16
+ }
17
+
9
18
  toJSON() {
10
19
  return {
11
20
  checkins: this.checkins.map(checkin => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-crew-berlin/enter-js-utils",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "utils such as vaildation and other helpers to work with data from the enter app",
5
5
  "files": [
6
6
  "dist",