@@ -179,6 +179,43 @@ async function queryOneIssue(model, repositoryId, number, provider) {
179
179
} ) ;
180
180
}
181
181
182
+ /**
183
+ * Get Issue's id and challengeUUID by repoUrl
184
+ * @param {String } repoUrl The repo url
185
+ * @returns {Promise<Object> }
186
+ */
187
+ async function queryIssueIdChallengeUUIDByRepoUrl ( repoUrl ) {
188
+ return await new Promise ( ( resolve , reject ) => {
189
+ models . Issue . scan ( 'repoUrl' ) . eq ( repoUrl )
190
+ . attributes ( [ 'id' , 'challengeUUID' ] )
191
+ . exec ( ( err , result ) => {
192
+ if ( err ) {
193
+ return reject ( err ) ;
194
+ }
195
+ return resolve ( result ) ;
196
+ } ) ;
197
+ } ) ;
198
+ }
199
+
200
+
201
+ /**
202
+ * Get CopilotPayment's id by challengeUUID
203
+ * @param {String } challengeUUID The challengeUUID
204
+ * @returns {Promise<String> }
205
+ */
206
+ async function queryPaymentIdByChallengeUUID ( challengeUUID ) {
207
+ return await new Promise ( ( resolve , reject ) => {
208
+ models . CopilotPayment . scan ( 'challengeUUID' ) . eq ( challengeUUID )
209
+ . attributes ( [ 'id' ] )
210
+ . exec ( ( err , result ) => {
211
+ if ( err ) {
212
+ return reject ( err ) ;
213
+ }
214
+ return resolve ( result . id ) ;
215
+ } ) ;
216
+ } ) ;
217
+ }
218
+
182
219
/**
183
220
* Get single data by query parameters
184
221
* @param {Object } model The dynamoose model to query
@@ -248,6 +285,27 @@ async function queryOneUserMappingByTCUsername(model, tcusername) {
248
285
} ) ;
249
286
}
250
287
288
+ /**
289
+ * Get single data by query parameters
290
+ * @param {Object } model The dynamoose model to query
291
+ * @param {String } provider The git provider
292
+ * @param {String } gitUsername The git username
293
+ * @returns {Promise<void> }
294
+ */
295
+ async function queryTCUsernameByGitUsername ( model , provider , gitUsername ) {
296
+ return await new Promise ( ( resolve , reject ) => {
297
+ model . queryOne ( `${ provider } Username` ) . eq ( gitUsername )
298
+ . all ( )
299
+ . exec ( ( err , result ) => {
300
+ if ( err ) {
301
+ logger . debug ( `queryTCUsernameByGitUsername. Error. ${ err } ` ) ;
302
+ return reject ( err ) ;
303
+ }
304
+ return resolve ( result . topcoderUsername ) ;
305
+ } ) ;
306
+ } ) ;
307
+ }
308
+
251
309
/**
252
310
* Get single data by query parameters
253
311
* @param {Object } model The dynamoose model to query
@@ -257,7 +315,7 @@ async function queryOneUserMappingByTCUsername(model, tcusername) {
257
315
async function queryOneActiveProject ( model , repoUrl ) {
258
316
return await new Promise ( ( resolve , reject ) => {
259
317
queryOneActiveRepository ( models . Repository , repoUrl ) . then ( ( repo ) => {
260
- if ( ! repo ) resolve ( null ) ;
318
+ if ( ! repo || repo . length === 0 ) resolve ( null ) ;
261
319
else model . queryOne ( 'id' ) . eq ( repo . projectId ) . consistent ( )
262
320
. exec ( ( err , result ) => {
263
321
if ( err ) {
@@ -470,6 +528,35 @@ async function queryOneOrganisation(model, organisation) {
470
528
} ) ;
471
529
}
472
530
531
+ /**
532
+ * Query one active repository
533
+ * @param {String } url the repository url
534
+ * @returns {Promise<Object> }
535
+ */
536
+ async function queryOneRepository ( url ) {
537
+ return await new Promise ( ( resolve , reject ) => {
538
+ models . Repository . query ( {
539
+ url,
540
+ } )
541
+ . all ( )
542
+ . exec ( ( err , repos ) => {
543
+ if ( err ) {
544
+ return reject ( err ) ;
545
+ }
546
+ if ( ! repos || repos . length === 0 ) resolve ( null ) ;
547
+ if ( repos . length > 1 ) {
548
+ let error = `Repository's url is unique in this version.
549
+ This Error must be caused by old data in the Repository table.
550
+ The old version can only guarrentee that the active Repository's url is unique.
551
+ Please migrate the old Repository table.` ;
552
+ logger . debug ( `queryOneRepository. Error. ${ error } ` ) ;
553
+ reject ( error ) ;
554
+ }
555
+ return resolve ( repos [ 0 ] ) ;
556
+ } ) ;
557
+ } ) ;
558
+ }
559
+
473
560
/**
474
561
* Query one active repository
475
562
* @param {Object } model the dynamoose model
@@ -480,8 +567,8 @@ async function queryOneActiveRepository(model, url) {
480
567
return await new Promise ( ( resolve , reject ) => {
481
568
model . queryOne ( {
482
569
url,
483
- archived : 'false'
484
570
} )
571
+ . filter ( 'archived' ) . eq ( 'false' )
485
572
. all ( )
486
573
. exec ( ( err , result ) => {
487
574
if ( err ) {
@@ -502,8 +589,8 @@ async function queryActiveRepositoriesExcludeByProjectId(url, projectId) {
502
589
return await new Promise ( ( resolve , reject ) => {
503
590
models . Repository . query ( {
504
591
url,
505
- archived : 'false'
506
592
} )
593
+ . filter ( 'archived' ) . eq ( 'false' )
507
594
. filter ( 'projectId' )
508
595
. not ( ) . eq ( projectId )
509
596
. all ( )
@@ -580,6 +667,8 @@ async function populateRepoUrls(projectId) {
580
667
}
581
668
582
669
module . exports = {
670
+ queryIssueIdChallengeUUIDByRepoUrl,
671
+ queryPaymentIdByChallengeUUID,
583
672
getById,
584
673
getByKey,
585
674
scan,
@@ -597,13 +686,15 @@ module.exports = {
597
686
queryOneActiveProject,
598
687
queryOneActiveProjectWithFilter,
599
688
queryOneActiveRepository,
689
+ queryOneRepository,
600
690
queryOneOrganisation,
601
691
queryOneIssue,
602
692
queryOneUserByType,
603
693
queryOneUserByTypeAndRole,
604
694
queryOneUserGroupMapping,
605
695
queryOneUserTeamMapping,
606
696
queryOneUserMappingByTCUsername,
697
+ queryTCUsernameByGitUsername,
607
698
queryRepositoriesByProjectId,
608
699
queryRepositoryByProjectIdFilterUrl
609
700
} ;
0 commit comments