1- import mongoose from " mongoose" ;
2- import showdown from " showdown" ;
1+ import mongoose from ' mongoose' ;
2+ import showdown from ' showdown' ;
33
4- import Note from " ./note.model" ;
4+ import Note from ' ./note.model' ;
55
6- import {
7- getRepoOwnerType ,
8- checkUserIsACollaborator
9- } from "../../../../utils/githubapi" ;
6+ import { getRepoOwnerType , checkUserIsACollaborator } from '../../../../utils/githubapi' ;
107
118const converter = new showdown . Converter ( ) ;
129
@@ -18,7 +15,7 @@ async function createNote(user, noteDetails) {
1815 projectName,
1916 repoOwner,
2017 noteVisibility,
21- nearestCommentId
18+ nearestCommentId,
2219 } = noteDetails ;
2320
2421 let userHasAccessToRepo = false ;
@@ -30,12 +27,12 @@ async function createNote(user, noteDetails) {
3027 repoOwner,
3128 projectName,
3229 userName,
33- accessToken
30+ accessToken,
3431 } ) ;
3532 if ( ! userHasAccessToRepo ) {
3633 return {
3734 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' ,
3936 } ;
4037 }
4138
@@ -51,25 +48,25 @@ async function createNote(user, noteDetails) {
5148 repoOwner,
5249 noteVisibility,
5350 userId,
54- userDetails
51+ userDetails,
5552 } ) ;
5653
5754 if ( ! userId ) {
5855 return {
5956 status : 400 ,
60- message : " User id is required"
57+ message : ' User id is required' ,
6158 } ;
6259 }
6360 if ( ! issueId ) {
6461 return {
6562 status : 400 ,
66- message : " Issue id or Pull id is required"
63+ message : ' Issue id or Pull id is required' ,
6764 } ;
6865 }
6966 if ( ! projectName ) {
7067 return {
7168 status : 400 ,
72- message : " Project name is required"
69+ message : ' Project name is required' ,
7370 } ;
7471 }
7572
@@ -84,19 +81,19 @@ async function createNote(user, noteDetails) {
8481 updatedAt : result . updatedAt ,
8582 nearestCommentId : result . nearestCommentId ,
8683 noteVisibility : result . noteVisibility ,
87- userDetails
84+ userDetails,
8885 } ;
8986
9087 return {
9188 status : 200 ,
9289 data : newlyCreatedNote ,
93- message : " Note created successfully"
90+ message : ' Note created successfully' ,
9491 } ;
9592 } catch ( err ) {
9693 return {
9794 status : 401 ,
9895 data : { error : err } ,
99- message : " Note not created"
96+ message : ' Note not created' ,
10097 } ;
10198 }
10299}
@@ -112,7 +109,7 @@ async function getNotes(user, noteDetails) {
112109 repoOwner,
113110 projectName,
114111 userName,
115- accessToken
112+ accessToken,
116113 } ) ;
117114
118115 if ( userHasAccessToRepo ) {
@@ -121,35 +118,33 @@ async function getNotes(user, noteDetails) {
121118 { issueId } ,
122119 { projectName } ,
123120 { 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' ) ;
127124 const userDetails = { userName, avatarUrl, githubId } ;
128125
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+ } ) ) ;
141136 }
142137
143138 return {
144139 status : 200 ,
145- message : " Fetched notes" ,
146- data : notes
140+ message : ' Fetched notes' ,
141+ data : notes ,
147142 } ;
148143 } catch ( err ) {
149144 return {
150145 status : 200 ,
151- message : " Failed to fetch notes" ,
152- data : { error : err }
146+ message : ' Failed to fetch notes' ,
147+ data : { error : err } ,
153148 } ;
154149 }
155150}
@@ -159,7 +154,7 @@ async function deleteNote(userId, noteDetails) {
159154 if ( ! noteId ) {
160155 return {
161156 status : 400 ,
162- message : " Note id is required"
157+ message : ' Note id is required' ,
163158 } ;
164159 }
165160
@@ -170,20 +165,20 @@ async function deleteNote(userId, noteDetails) {
170165 { userId } ,
171166 { issueId } ,
172167 { projectName } ,
173- { noteType }
174- ]
175- } ) . populate ( " userId" , " userName avatarUrl githubId" ) ;
168+ { noteType } ,
169+ ] ,
170+ } ) . populate ( ' userId' , ' userName avatarUrl githubId' ) ;
176171 if ( note ) note . remove ( ) ;
177172 return {
178173 status : 200 ,
179174 data : note ,
180- message : " Note removed successfully"
175+ message : ' Note removed successfully' ,
181176 } ;
182177 } catch ( err ) {
183178 return {
184179 status : 401 ,
185180 data : { error : err } ,
186- message : " Invalid note id"
181+ message : ' Invalid note id' ,
187182 } ;
188183 }
189184}
@@ -193,31 +188,28 @@ async function editNote(userId, noteDetails) {
193188 if ( ! noteId ) {
194189 return {
195190 status : 400 ,
196- message : " Note id is required"
191+ message : ' Note id is required' ,
197192 } ;
198193 }
199194
200195 try {
201- await Note . findOneAndUpdate (
202- { _id : mongoose . Types . ObjectId ( noteId ) } ,
203- { noteVisibility }
204- ) ;
196+ await Note . findOneAndUpdate ( { _id : mongoose . Types . ObjectId ( noteId ) } , { noteVisibility } ) ;
205197
206198 return {
207199 status : 200 ,
208- message : " Note updated successfully"
200+ message : ' Note updated successfully' ,
209201 } ;
210202 } catch ( err ) {
211203 return {
212204 status : 401 ,
213205 data : { error : err } ,
214- message : " Invalid note id"
206+ message : ' Invalid note id' ,
215207 } ;
216208 }
217209}
218210export default {
219211 createNote,
220212 getNotes,
221213 deleteNote,
222- editNote
214+ editNote,
223215} ;
0 commit comments