Skip to content

Commit fc0c02e

Browse files
fix(model): add parent role and remove handle prop
1 parent 30a58f6 commit fc0c02e

File tree

7 files changed

+33
-31
lines changed

7 files changed

+33
-31
lines changed

lib/model/analytics.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ export type TagTotals<Tag extends string> = { total: number } & {
3636
* is updated until 24 hours have passed (and a new analytics doc is created).
3737
*/
3838
export interface AnalyticsInterface extends ResourceInterface {
39-
mentor: TagTotals<Exclude<UserTag, Role>>;
40-
mentee: TagTotals<Exclude<UserTag, Role>>;
4139
tutor: TagTotals<Exclude<UserTag, Role>>;
4240
tutee: TagTotals<Exclude<UserTag, Role>>;
41+
mentor: TagTotals<Exclude<UserTag, Role>>;
42+
mentee: TagTotals<Exclude<UserTag, Role>>;
43+
parent: TagTotals<Exclude<UserTag, Role>>;
4344
match: TagTotals<MatchTag>;
4445
meeting: TagTotals<MeetingTag>;
4546
ref?: DocumentReference;
@@ -59,28 +60,35 @@ export type AnalyticsFirestore = Omit<
5960
ResourceFirestore & { date: Timestamp };
6061

6162
export class Analytics extends Resource implements AnalyticsInterface {
62-
public mentor: TagTotals<Exclude<UserTag, Role>> = {
63+
public tutor: TagTotals<Exclude<UserTag, Role>> = {
6364
total: 0,
6465
vetted: 0,
6566
matched: 0,
6667
meeting: 0,
6768
};
6869

69-
public mentee: TagTotals<Exclude<UserTag, Role>> = {
70+
public tutee: TagTotals<Exclude<UserTag, Role>> = {
7071
total: 0,
7172
vetted: 0,
7273
matched: 0,
7374
meeting: 0,
7475
};
7576

76-
public tutor: TagTotals<Exclude<UserTag, Role>> = {
77+
public mentor: TagTotals<Exclude<UserTag, Role>> = {
7778
total: 0,
7879
vetted: 0,
7980
matched: 0,
8081
meeting: 0,
8182
};
8283

83-
public tutee: TagTotals<Exclude<UserTag, Role>> = {
84+
public mentee: TagTotals<Exclude<UserTag, Role>> = {
85+
total: 0,
86+
vetted: 0,
87+
matched: 0,
88+
meeting: 0,
89+
};
90+
91+
public parent: TagTotals<Exclude<UserTag, Role>> = {
8492
total: 0,
8593
vetted: 0,
8694
matched: 0,

lib/model/match.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as admin from 'firebase-admin';
22
import { ObjectWithObjectID } from '@algolia/client-search';
3-
import { v4 as uuid } from 'uuid';
43

54
import { Person, isPerson } from 'lib/model/person';
65
import {
@@ -90,7 +89,6 @@ export class Match extends Resource implements MatchInterface {
9089
id: '',
9190
name: '',
9291
photo: '',
93-
handle: uuid(),
9492
roles: [],
9593
};
9694

lib/model/meeting.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as admin from 'firebase-admin';
22
import { ObjectWithObjectID } from '@algolia/client-search';
3-
import { v4 as uuid } from 'uuid';
43

54
import {
65
Match,
@@ -155,7 +154,6 @@ export class Meeting extends Resource implements MeetingInterface {
155154
id: '',
156155
name: '',
157156
photo: '',
158-
handle: uuid(),
159157
roles: [],
160158
};
161159

lib/model/person.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
import { isArray, isJSON } from 'lib/model/json';
22

3-
export type Role = 'tutor' | 'tutee' | 'mentor' | 'mentee';
3+
export type Role = 'tutor' | 'tutee' | 'mentor' | 'mentee' | 'parent';
44

55
export function isRole(role: unknown): role is Role {
66
if (typeof role !== 'string') return false;
7-
return ['tutor', 'tutee', 'mentor', 'mentee'].includes(role);
7+
return ['tutor', 'tutee', 'mentor', 'mentee', 'parent'].includes(role);
88
}
99

1010
/**
1111
* Represents a person that is involved in a request or match. Here, roles are
1212
* explicitly listed (unlike the `User` object where roles are implied by
1313
* role-specific properties).
14-
* @property id - The user's unique Firebase-assigned user ID (note that this
15-
* contains both lowercase and capital letters which is why it can't be used as
16-
* a unique anonymous email address handle).
14+
* @property id - The user's unique Firebase-assigned user ID.
1715
* @property [name] - The user's name (so we don't have to query an API just to
1816
* show an intelligible representation of this person).
1917
* @property [photo] - The user's photo URL (if any). This is included for the
2018
* same reason as above; speed on the front-end rendering. If not added by the
2119
* front-end, this is always updated by our back-end GCP function (triggered
2220
* when user documents are updated so as to keep profile info in sync).
23-
* @property handle - The user's all-lowercase anonymous email handle.
2421
* @property roles - The user's roles in this request or match (e.g. `tutor`).
2522
*/
2623
export interface Person {
2724
id: string;
2825
name?: string;
2926
photo?: string;
30-
handle: string;
3127
roles: Role[];
3228
}
3329

@@ -36,7 +32,6 @@ export function isPerson(json: unknown): json is Person {
3632
if (typeof json.id !== 'string') return false;
3733
if (json.name && typeof json.name !== 'string') return false;
3834
if (json.photo && typeof json.photo !== 'string') return false;
39-
if (typeof json.handle !== 'string') return false;
4035
if (!isArray(json.roles, isRole)) return false;
4136
return true;
4237
}

lib/model/user.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as admin from 'firebase-admin';
2-
import { v4 as uuid } from 'uuid';
32

43
import {
54
Account,
@@ -54,19 +53,21 @@ export type UserTag =
5453

5554
export type UserHitTag =
5655
| UserTag
57-
| 'not-mentor'
58-
| 'not-mentee'
5956
| 'not-tutor'
6057
| 'not-tutee'
58+
| 'not-mentor'
59+
| 'not-mentee'
60+
| 'not-parent'
6161
| 'not-vetted'
6262
| 'not-matched'
6363
| 'not-meeting';
6464

6565
export const USER_TAGS: UserTag[] = [
66-
'mentor',
67-
'mentee',
6866
'tutor',
6967
'tutee',
68+
'mentor',
69+
'mentee',
70+
'parent',
7071
'vetted',
7172
'matched',
7273
'meeting',
@@ -98,6 +99,7 @@ export function isSubjects(json: unknown): json is Subjects {
9899
* A user object (that is stored in their Firestore profile document by uID).
99100
* @typedef {Object} UserInterface
100101
* @extends AccountInterface
102+
* @property [age] - The user's age (mostly used for students).
101103
* @property orgs - An array of the IDs of the orgs this user belongs to.
102104
* @property zooms - An array of Zoom user accounts. These are used when
103105
* creating Zoom meetings for a match. Each TB user can have multiple Zoom user
@@ -122,6 +124,7 @@ export function isSubjects(json: unknown): json is Subjects {
122124
* meetings).
123125
*/
124126
export interface UserInterface extends AccountInterface {
127+
age?: number;
125128
orgs: string[];
126129
zooms: ZoomUser[];
127130
availability: Availability;
@@ -174,6 +177,7 @@ export type UserSearchHit = Omit<
174177
export function isUserJSON(json: unknown): json is UserJSON {
175178
if (!isAccountJSON(json)) return false;
176179
if (!isJSON(json)) return false;
180+
if (json.age && typeof json.age !== 'number') return false;
177181
if (!isStringArray(json.orgs)) return false;
178182
if (!isArray(json.zooms, isZoomUserJSON)) return false;
179183
if (!isAvailabilityJSON(json.availability)) return false;
@@ -198,6 +202,8 @@ export function isUserJSON(json: unknown): json is UserJSON {
198202
* @see {@link https://stackoverflow.com/a/54857125/10023158}
199203
*/
200204
export class User extends Account implements UserInterface {
205+
public age?: number;
206+
201207
public orgs: string[] = [];
202208

203209
public zooms: ZoomUser[] = [];
@@ -259,13 +265,17 @@ export class User extends Account implements UserInterface {
259265
return parts[parts.length - 1];
260266
}
261267

268+
public get subjects(): string[] {
269+
const subjects = this.tutoring.subjects.concat(this.mentoring.subjects);
270+
return [...new Set<string>(subjects)];
271+
}
272+
262273
public toPerson(): Person {
263274
return {
264275
id: this.id,
265276
name: this.name,
266277
photo: this.photo,
267278
roles: this.roles,
268-
handle: uuid(),
269279
};
270280
}
271281

scripts/firebase/picktime.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const prompt = require('prompt-sync')();
99
const algoliasearch = require('algoliasearch');
1010
const parseSync = require('csv-parse/lib/sync');
1111
const { default: to } = require('await-to-js');
12-
const { v4: uuid } = require('uuid');
1312
const { nanoid } = require('nanoid');
1413

1514
const logger = winston.createLogger({
@@ -295,22 +294,19 @@ async function convertPicktimeRow(row, headers) {
295294
id: student.id || '',
296295
name: student.name || '',
297296
photo: student.photo || '',
298-
handle: uuid(),
299297
roles: ['mentee'],
300298
},
301299
{
302300
id: mentor.id || '',
303301
name: mentor.name || '',
304302
photo: mentor.photo || '',
305-
handle: uuid(),
306303
roles: ['mentor'],
307304
},
308305
],
309306
creator: {
310307
id: student.id || '',
311308
name: student.name || '',
312309
photo: student.photo || '',
313-
handle: uuid(),
314310
roles: ['mentee'],
315311
},
316312
message: generateMatchMessage(row),
@@ -354,7 +350,6 @@ async function convertPicktimeRow(row, headers) {
354350
id: student.id || '',
355351
name: student.name || '',
356352
photo: student.photo || '',
357-
handle: uuid(),
358353
roles: ['mentee'],
359354
},
360355
venue: {

scripts/firebase/utils.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ console.log(
2323
)
2424
);
2525

26-
const { v4: uuid } = require('uuid');
2726
const { nanoid } = require('nanoid');
2827
const axios = require('axios');
2928
const updateSubjects = require('./update-subjects');
@@ -562,7 +561,6 @@ const changeDateJSONToDates = async () => {
562561
id: '',
563562
name: '',
564563
photo: '',
565-
handle: uuid(),
566564
roles: [],
567565
},
568566
message: '',

0 commit comments

Comments
 (0)