Skip to content

Commit 440ae3b

Browse files
committed
lesson2
0 parents  commit 440ae3b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

lesson2.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Permissions implementation does not matter
2+
import { Permissions } from '@/lib/permissions'
3+
4+
// Check what should be tested
5+
class User {
6+
7+
// NO
8+
constructor(details, traits = {}) {
9+
const { firstname, lastname } = details
10+
this.firstname = firstname
11+
this.lastname = lastname
12+
this.traits = traits
13+
14+
this.sessionStartedAt = Date.now()
15+
}
16+
17+
// YES
18+
get name() {
19+
return `${this.firstname} ${this.lastname}`
20+
}
21+
22+
// YES
23+
get isAdmin() {
24+
return Permissions.granted(this, 'admin')
25+
}
26+
27+
// YES in combination
28+
get currentSessionIsValid() {
29+
const tenMinutesInMiliseconds = 600000
30+
return (this.sessionStartedAt + tenMinutesInMiliseconds) <= Date.now()
31+
}
32+
33+
extendSession() {
34+
this.sessionStartedAt = Date.now()
35+
}
36+
}

0 commit comments

Comments
 (0)