1
- import mongoose from " mongoose" ;
2
- import showdown from " showdown" ;
1
+ import mongoose from ' mongoose' ;
2
+ import showdown from ' showdown' ;
3
3
4
- import Note from " ./note.model" ;
4
+ import Note from ' ./note.model' ;
5
5
6
- import {
7
- getRepoOwnerType ,
8
- checkUserIsACollaborator
9
- } from "../../../../utils/githubapi" ;
6
+ import { getRepoOwnerType , checkUserIsACollaborator } from '../../../../utils/githubapi' ;
10
7
11
8
const converter = new showdown . Converter ( ) ;
12
9
@@ -18,7 +15,7 @@ async function createNote(user, noteDetails) {
18
15
projectName,
19
16
repoOwner,
20
17
noteVisibility,
21
- nearestCommentId
18
+ nearestCommentId,
22
19
} = noteDetails ;
23
20
24
21
let userHasAccessToRepo = false ;
@@ -30,12 +27,12 @@ async function createNote(user, noteDetails) {
30
27
repoOwner,
31
28
projectName,
32
29
userName,
33
- accessToken
30
+ accessToken,
34
31
} ) ;
35
32
if ( ! userHasAccessToRepo ) {
36
33
return {
37
34
status : 400 ,
38
- message : " You don't have authorization to create the private note"
35
+ message : ' You cannot add private notes to this repository since you are not a contributor' ,
39
36
} ;
40
37
}
41
38
@@ -51,25 +48,25 @@ async function createNote(user, noteDetails) {
51
48
repoOwner,
52
49
noteVisibility,
53
50
userId,
54
- userDetails
51
+ userDetails,
55
52
} ) ;
56
53
57
54
if ( ! userId ) {
58
55
return {
59
56
status : 400 ,
60
- message : " User id is required"
57
+ message : ' User id is required' ,
61
58
} ;
62
59
}
63
60
if ( ! issueId ) {
64
61
return {
65
62
status : 400 ,
66
- message : " Issue id or Pull id is required"
63
+ message : ' Issue id or Pull id is required' ,
67
64
} ;
68
65
}
69
66
if ( ! projectName ) {
70
67
return {
71
68
status : 400 ,
72
- message : " Project name is required"
69
+ message : ' Project name is required' ,
73
70
} ;
74
71
}
75
72
@@ -84,19 +81,19 @@ async function createNote(user, noteDetails) {
84
81
updatedAt : result . updatedAt ,
85
82
nearestCommentId : result . nearestCommentId ,
86
83
noteVisibility : result . noteVisibility ,
87
- userDetails
84
+ userDetails,
88
85
} ;
89
86
90
87
return {
91
88
status : 200 ,
92
89
data : newlyCreatedNote ,
93
- message : " Note created successfully"
90
+ message : ' Note created successfully' ,
94
91
} ;
95
92
} catch ( err ) {
96
93
return {
97
94
status : 401 ,
98
95
data : { error : err } ,
99
- message : " Note not created"
96
+ message : ' Note not created' ,
100
97
} ;
101
98
}
102
99
}
@@ -112,7 +109,7 @@ async function getNotes(user, noteDetails) {
112
109
repoOwner,
113
110
projectName,
114
111
userName,
115
- accessToken
112
+ accessToken,
116
113
} ) ;
117
114
118
115
if ( userHasAccessToRepo ) {
@@ -121,35 +118,33 @@ async function getNotes(user, noteDetails) {
121
118
{ issueId } ,
122
119
{ projectName } ,
123
120
{ noteType } ,
124
- { $or : [ { userId } , { noteVisibility : true } ] }
125
- ]
126
- } ) . populate ( " userId" , " userName avatarUrl githubId" ) ;
121
+ { $or : [ { userId } , { noteVisibility : true } ] } ,
122
+ ] ,
123
+ } ) . populate ( ' userId' , ' userName avatarUrl githubId' ) ;
127
124
const userDetails = { userName, avatarUrl, githubId } ;
128
125
129
- notes = notes . map ( note => {
130
- return {
131
- _id : note . _id ,
132
- noteContent : converter . makeHtml ( note . noteContent ) ,
133
- author : note . userId ,
134
- createdAt : note . createdAt ,
135
- updatedAt : note . updatedAt ,
136
- nearestCommentId : note . nearestCommentId ,
137
- noteVisibility : note . noteVisibility ,
138
- userDetails
139
- } ;
140
- } ) ;
126
+ notes = notes . map ( note => ( {
127
+ _id : note . _id ,
128
+ noteContent : converter . makeHtml ( note . noteContent ) ,
129
+ author : note . userId ,
130
+ createdAt : note . createdAt ,
131
+ updatedAt : note . updatedAt ,
132
+ nearestCommentId : note . nearestCommentId ,
133
+ noteVisibility : note . noteVisibility ,
134
+ userDetails,
135
+ } ) ) ;
141
136
}
142
137
143
138
return {
144
139
status : 200 ,
145
- message : " Fetched notes" ,
146
- data : notes
140
+ message : ' Fetched notes' ,
141
+ data : notes ,
147
142
} ;
148
143
} catch ( err ) {
149
144
return {
150
145
status : 200 ,
151
- message : " Failed to fetch notes" ,
152
- data : { error : err }
146
+ message : ' Failed to fetch notes' ,
147
+ data : { error : err } ,
153
148
} ;
154
149
}
155
150
}
@@ -159,7 +154,7 @@ async function deleteNote(userId, noteDetails) {
159
154
if ( ! noteId ) {
160
155
return {
161
156
status : 400 ,
162
- message : " Note id is required"
157
+ message : ' Note id is required' ,
163
158
} ;
164
159
}
165
160
@@ -170,20 +165,20 @@ async function deleteNote(userId, noteDetails) {
170
165
{ userId } ,
171
166
{ issueId } ,
172
167
{ projectName } ,
173
- { noteType }
174
- ]
175
- } ) . populate ( " userId" , " userName avatarUrl githubId" ) ;
168
+ { noteType } ,
169
+ ] ,
170
+ } ) . populate ( ' userId' , ' userName avatarUrl githubId' ) ;
176
171
if ( note ) note . remove ( ) ;
177
172
return {
178
173
status : 200 ,
179
174
data : note ,
180
- message : " Note removed successfully"
175
+ message : ' Note removed successfully' ,
181
176
} ;
182
177
} catch ( err ) {
183
178
return {
184
179
status : 401 ,
185
180
data : { error : err } ,
186
- message : " Invalid note id"
181
+ message : ' Invalid note id' ,
187
182
} ;
188
183
}
189
184
}
@@ -193,31 +188,28 @@ async function editNote(userId, noteDetails) {
193
188
if ( ! noteId ) {
194
189
return {
195
190
status : 400 ,
196
- message : " Note id is required"
191
+ message : ' Note id is required' ,
197
192
} ;
198
193
}
199
194
200
195
try {
201
- await Note . findOneAndUpdate (
202
- { _id : mongoose . Types . ObjectId ( noteId ) } ,
203
- { noteVisibility }
204
- ) ;
196
+ await Note . findOneAndUpdate ( { _id : mongoose . Types . ObjectId ( noteId ) } , { noteVisibility } ) ;
205
197
206
198
return {
207
199
status : 200 ,
208
- message : " Note updated successfully"
200
+ message : ' Note updated successfully' ,
209
201
} ;
210
202
} catch ( err ) {
211
203
return {
212
204
status : 401 ,
213
205
data : { error : err } ,
214
- message : " Invalid note id"
206
+ message : ' Invalid note id' ,
215
207
} ;
216
208
}
217
209
}
218
210
export default {
219
211
createNote,
220
212
getNotes,
221
213
deleteNote,
222
- editNote
214
+ editNote,
223
215
} ;
0 commit comments