Commit bded2cd7 authored by soheib's avatar soheib
Browse files

fix lottrey result bug when start from first

parent 027de527
......@@ -53,10 +53,12 @@ export class LotteryService {
foundUser_idsList.push(user_id)
}
})
let user_index = 0
for await (const user_id of foundUser_idsList) {
let userScore = await this.scoreService.calculateUserScore(user_id, profileUsername, postArray)
for (let u = 0; u < userScore; u++) {
console.log();
let foundIndex = await this.lotteryResultModel.findOne({
$and: [
{
......@@ -68,14 +70,15 @@ export class LotteryService {
if (!foundIndex) {
await this.lotteryResultModel.create({
_id: new Types.ObjectId(),
index: `${user_index}`,
index: `${u}`,
user_id: user_id,
status: 'valid',
chance: await this.codeGenerator()
})
}
}
user_index++
}
return 'successfull'
}
......@@ -83,9 +86,13 @@ export class LotteryService {
let lastIndex = await this.lotteryResultModel.find().sort({ createdAt: -1 })
if (lastIndex[0]) {
let temp = lastIndex[0].chance
let code =Number(temp.split('LT_')[1])
return `LT_${code++}`
let lastChanceIndex = lastIndex[0].chance
console.log('last chance',lastChanceIndex);
let code =lastChanceIndex.split('LT_')[1]
console.log('code',code);
let res = `LT_${(Number(code)+1)}`
console.log('res',res);
return res
}
else {
return `LT_${1000}`
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment