Skip to content

Commit 5f3264d

Browse files
committed
Fix 500 error when there is no pairs left
1 parent 71b53b2 commit 5f3264d

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/flow/flow.service.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export class FlowService {
5252
}
5353
};
5454

55+
getOveralRanking = async (cid = null) => {
56+
console.log(cid);
57+
};
58+
5559
voteForCollections = async (
5660
userId: number,
5761
collection1Id: number,
@@ -226,6 +230,18 @@ export class FlowService {
226230

227231
const combinations = getPairwiseCombinations(allIds);
228232

233+
if (allVotes.length === combinations.length)
234+
return {
235+
pairs: [],
236+
totalPairs: combinations.length,
237+
votedPairs: allVotes.length,
238+
type: 'collection' as const,
239+
threshold: this.calculateThreshold(
240+
allIds.length,
241+
parentCollection ? false : true,
242+
),
243+
};
244+
229245
const sortedCombinations = sortCombinations(combinations, idRanking);
230246

231247
const result = [];
@@ -276,7 +292,7 @@ export class FlowService {
276292

277293
return {
278294
pairs,
279-
totalPairs: combinations.flat(0).length,
295+
totalPairs: combinations.length,
280296
votedPairs: allVotes.length,
281297
type: 'collection' as const,
282298
threshold: this.calculateThreshold(
@@ -322,10 +338,20 @@ export class FlowService {
322338

323339
const combinations = getPairwiseCombinations(allIds);
324340

341+
if (allVotes.length === combinations.length)
342+
return {
343+
pairs: [],
344+
totalPairs: combinations.length,
345+
votedPairs: allVotes.length,
346+
type: 'project' as const,
347+
threshold: this.calculateThreshold(allIds.length),
348+
};
349+
325350
const sortedCombinations = sortCombinations(combinations, idRanking);
326351

327352
const result = [];
328353
let i = 0;
354+
329355
while (result.length < count) {
330356
const combination = sortedCombinations[i];
331357
const px = combination[0];
@@ -360,7 +386,7 @@ export class FlowService {
360386

361387
return {
362388
pairs,
363-
totalPairs: combinations.flat(0).length,
389+
totalPairs: combinations.length,
364390
votedPairs: allVotes.length,
365391
type: 'project' as const,
366392
threshold: this.calculateThreshold(allIds.length),

0 commit comments

Comments
 (0)