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 { ...@@ -53,10 +53,12 @@ export class LotteryService {
foundUser_idsList.push(user_id) foundUser_idsList.push(user_id)
} }
}) })
let user_index = 0
for await (const user_id of foundUser_idsList) { for await (const user_id of foundUser_idsList) {
let userScore = await this.scoreService.calculateUserScore(user_id, profileUsername, postArray) let userScore = await this.scoreService.calculateUserScore(user_id, profileUsername, postArray)
for (let u = 0; u < userScore; u++) { for (let u = 0; u < userScore; u++) {
console.log();
let foundIndex = await this.lotteryResultModel.findOne({ let foundIndex = await this.lotteryResultModel.findOne({
$and: [ $and: [
{ {
...@@ -68,14 +70,15 @@ export class LotteryService { ...@@ -68,14 +70,15 @@ export class LotteryService {
if (!foundIndex) { if (!foundIndex) {
await this.lotteryResultModel.create({ await this.lotteryResultModel.create({
_id: new Types.ObjectId(), _id: new Types.ObjectId(),
index: `${user_index}`, index: `${u}`,
user_id: user_id, user_id: user_id,
status: 'valid', status: 'valid',
chance: await this.codeGenerator() chance: await this.codeGenerator()
}) })
} }
} }
user_index++
} }
return 'successfull' return 'successfull'
} }
...@@ -83,9 +86,13 @@ export class LotteryService { ...@@ -83,9 +86,13 @@ export class LotteryService {
let lastIndex = await this.lotteryResultModel.find().sort({ createdAt: -1 }) let lastIndex = await this.lotteryResultModel.find().sort({ createdAt: -1 })
if (lastIndex[0]) { if (lastIndex[0]) {
let temp = lastIndex[0].chance let lastChanceIndex = lastIndex[0].chance
let code =Number(temp.split('LT_')[1]) console.log('last chance',lastChanceIndex);
return `LT_${code++}` let code =lastChanceIndex.split('LT_')[1]
console.log('code',code);
let res = `LT_${(Number(code)+1)}`
console.log('res',res);
return res
} }
else { else {
return `LT_${1000}` 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