-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathorganization.model.ts
115 lines (89 loc) · 2.05 KB
/
organization.model.ts
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import {
CollectionProperty,
DateProperty,
Model,
PartitionKey,
Property,
SortKey,
Transient,
} from '../../src/dynamo-easy'
import { Employee } from './employee.model'
// tslint:disable:max-classes-per-file
@Model()
export class Gift {
description: string
}
@Model()
export class Birthday {
@DateProperty()
date: Date
@CollectionProperty({ itemType: Gift })
presents: Gift[]
constructor(date: Date, ...gifts: string[]) {
this.date = date
const giftArr: Gift[] = []
gifts.forEach((giftDescription) => giftArr.push({ description: giftDescription }))
this.presents = giftArr
}
}
@Model()
export class OrganizationEvent {
name: string
@Property({ name: 'participantCount' })
participants: number
constructor(name: string, participants: number) {
this.name = name
this.participants = participants
}
}
@Model({ tableName: 'Organization' })
export class Organization {
// String
@PartitionKey()
id: string
name: string
@SortKey()
@DateProperty()
createdAtDate: Date
@DateProperty()
lastUpdated: Date
// Boolean
active: boolean
// Number
count = 52
@Transient()
// transient: Transient<any>
transient: any
/*
* collections
*/
/*
* ARRAY
*/
// simple type -> L(ist) (no metadata required)
domains: string[]
// simple type, mixed (no metadata required)
randomDetails: any[]
// complex type (requires metadata)
@CollectionProperty({ itemType: Employee })
employees: Employee[]
/*
* SET
*/
// set with simple type -> SS
// @TypedSet()
cities: Set<string>
// set with complex type -> L(ist)
@CollectionProperty({ itemType: Birthday })
birthdays: Set<Birthday>
// set with simple type but sorted -> L(ist)
@CollectionProperty({ sorted: true })
awards: Set<string>
// set with complex type + sorted -> L(ist)
@CollectionProperty({ sorted: true, itemType: OrganizationEvent })
events: Set<OrganizationEvent>
@CollectionProperty()
emptySet: Set<string> = new Set()
// tslint:disable-next-line:no-empty
constructor() {}
}