1 | var NoteComment = require('./NoteComment');
|
2 |
|
3 | var Note = function(data, comments) {
|
4 | this.id = data.note_id;
|
5 | this.createdAt = data.created_at;
|
6 | this.closedAt = data.closed_at || null;
|
7 | this.note = data.note;
|
8 | this.userName = data.user_name || null;
|
9 | this.lastCommentComment = data.last_comment_comment || null;
|
10 | this.lastCommentTimestamp = data.last_comment_timestamp || null;
|
11 | this.lastCommentUserName = data.last_comment_user_name || null;
|
12 | this.lastCommentUserID = data.last_comment_user_id || null;
|
13 | this.lastCommentAction = data.last_comment_action || null;
|
14 | this.commentCount = data.comment_count;
|
15 |
|
16 | this.point = JSON.parse(data.point);
|
17 | if (comments) {
|
18 | this.comments = comments.map(function(comment) {
|
19 | return new NoteComment(comment);
|
20 | });
|
21 | } else {
|
22 | this.comments = null;
|
23 | }
|
24 | return this;
|
25 | };
|
26 |
|
27 | Note.prototype.getGeoJSON = function() {
|
28 | return {
|
29 | 'type': 'Feature',
|
30 | 'geometry': this.point,
|
31 | 'properties': this.getProperties()
|
32 | };
|
33 | };
|
34 |
|
35 | Note.prototype.getProperties = function() {
|
36 | var props = {
|
37 | 'id': this.id,
|
38 | 'createdAt': this.createdAt,
|
39 | 'closedAt': this.closedAt,
|
40 | 'note': this.note,
|
41 | 'userName': this.userName,
|
42 | 'lastCommentComment': this.lastCommentComment,
|
43 | 'lastCommentTimestamp': this.lastCommentTimestamp,
|
44 | 'lastCommentUserName': this.lastCommentUserName,
|
45 | 'lastCommentUserID': this.lastCommentUserID,
|
46 | 'lastCommentAction': this.lastCommentAction,
|
47 | 'commentCount': this.commentCount
|
48 | };
|
49 | if (this.comments) {
|
50 | props.comments = this.comments.map(function(noteComment) {
|
51 | return noteComment.getJSON();
|
52 | });
|
53 | }
|
54 | return props;
|
55 | };
|
56 |
|
57 | module.exports = Note;
|