/
Reflection.js
67 lines (66 loc) · 1.56 KB
/
Reflection.js
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
import moment from 'moment';
import uuid from 'uuid';
class Reflection {
/**
* class constructor
* @param {object} data
*/
constructor() {
this.reflections = [];
}
/**
*
* @returns {object} reflection object
*/
create(data) {
const newReflection = {
id: uuid.v4(),
success: data.success || '',
lowPoint: data.lowPoint || '',
takeAway: data.takeAway || '',
createdDate: moment.now(),
modifiedDate: moment.now()
};
this.reflections.push(newReflection);
return newReflection
}
/**
*
* @param {uuid} id
* @returns {object} reflection object
*/
findOne(id) {
return this.reflections.find(reflect => reflect.id === id);
}
/**
* @returns {object} returns all reflections
*/
findAll() {
return this.reflections;
}
/**
*
* @param {uuid} id
* @param {object} data
*/
update(id, data) {
const reflection = this.findOne(id);
const index = this.reflections.indexOf(reflection);
this.reflections[index].success = data['success'] || reflection.success;
this.reflections[index].lowPoint = data['lowPoint'] || reflection.lowPoint;
this.reflections[index].takeAway = data['takeAway'] || reflection.takeAway;
this.reflections[index].modifiedDate = moment.now()
return this.reflections[index];
}
/**
*
* @param {uuid} id
*/
delete(id) {
const reflection = this.findOne(id);
const index = this.reflections.indexOf(reflection);
this.reflections.splice(index, 1);
return {};
}
}
export default new Reflection();