-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponses.ts
More file actions
62 lines (47 loc) · 1.12 KB
/
responses.ts
File metadata and controls
62 lines (47 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {Date_t_F, firebaseDate} from './firebaseTypes';
export interface Response_t
{
id ?: string;
createdAt : Date;
userId : string;
questionId : string;
contents : string;
upVotes : number;
views : number;
userPhotoUrl ?: string;
userDisplayName : string;
}
export interface Response_t_F
{
createdAt : Date_t_F | Date;
contents : string;
upVotes : number;
views : number;
questionId : string;
userPhotoUrl ?: string;
userId : string;
userDisplayName : string;
}
export type Response_t_A = Response_t_F &
{
objectID : string;
}
export class Response
{
constructor(
opts : Response_t
){
return Object.assign(this, opts)
}
static fromFirebase = (doc : Response_t_F, id ?: string) =>
{
const obj = {...doc, createdAt : firebaseDate(doc.createdAt as Date_t_F), id};
return new Response(obj)
}
static toFirebase(doc : Response) : Response_t_F
{
const {id, ...firebaseDoc} = {...doc}
return firebaseDoc
}
}
export interface Response extends Response_t {}