Commit 11b7f235 authored by soheib's avatar soheib
Browse files

add user change status to online

parent ce49fc38
...@@ -24,6 +24,9 @@ export class User { ...@@ -24,6 +24,9 @@ export class User {
@Prop({ enum: AccountType }) @Prop({ enum: AccountType })
type: string type: string
@Prop()
mobile: string
} }
export const UserSchema = export const UserSchema =
SchemaFactory.createForClass(User) SchemaFactory.createForClass(User)
\ No newline at end of file
export class ChangeStatusDto{
mobile: string
username: string
}
\ No newline at end of file
import { Body, Query, Controller, Get, Post } from '@nestjs/common'; import { Body, Query, Controller, Get, Post } from '@nestjs/common';
import { CalculateScoreDto } from './dto/calculate-score-dto' import { CalculateScoreDto } from './dto/calculate-score-dto'
import { ChangeStatusDto } from './dto/change-status-dto'
import { WeeklySearchDto } from './dto/weekly-search-dto' import { WeeklySearchDto } from './dto/weekly-search-dto'
import { LotteryService } from './lottery.service'; import { LotteryService } from './lottery.service';
...@@ -16,7 +17,7 @@ export class LotteryController { ...@@ -16,7 +17,7 @@ export class LotteryController {
} }
@Post('weekly/calculate-score') @Post('weekly/calculate-score')
async addResultsToDb(calculateScoreDto: CalculateScoreDto) { async addResultsToDb(@Body() calculateScoreDto: CalculateScoreDto) {
return await this.lotteryService.addResultsToDB(calculateScoreDto.profile_username, return await this.lotteryService.addResultsToDB(calculateScoreDto.profile_username,
calculateScoreDto.post_array) calculateScoreDto.post_array)
} }
...@@ -25,4 +26,9 @@ export class LotteryController { ...@@ -25,4 +26,9 @@ export class LotteryController {
async getResultDb() { async getResultDb() {
return await this.lotteryService.getResultDb() return await this.lotteryService.getResultDb()
} }
@Post('weekly/change-status')
async changeStatus(@Body() changeStatusDto: ChangeStatusDto) {
return await this.lotteryService.changeStatus(changeStatusDto)
}
} }
import { HttpException, Injectable } from '@nestjs/common'; import { HttpException, Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose'; import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose'; import { Model } from 'mongoose';
import { of } from 'rxjs'
import { CommentDocument } from 'src/instagram/models/comment.schema'; import { CommentDocument } from 'src/instagram/models/comment.schema';
import { FollowerDocument } from 'src/instagram/models/follower.schema'; import { FollowerDocument } from 'src/instagram/models/follower.schema';
import { LikeDocument } from 'src/instagram/models/like.schema'; import { LikeDocument } from 'src/instagram/models/like.schema';
import { LottoryResultDocument } from 'src/instagram/models/LottoryResult.schema'
import { UserDocument } from 'src/instagram/models/user.schema'; import { UserDocument } from 'src/instagram/models/user.schema';
import addToStoryData from '../instagram/values/add-to-story-data' import addToStoryData from '../instagram/values/add-to-story-data'
import { ChangeStatusDto } from './dto/change-status-dto'
import { ScoreService } from './score.service'; import { ScoreService } from './score.service';
...@@ -22,7 +25,7 @@ export class LotteryService { ...@@ -22,7 +25,7 @@ export class LotteryService {
@InjectModel('Comment') @InjectModel('Comment')
private commentModel: Model<CommentDocument>, private commentModel: Model<CommentDocument>,
@InjectModel('LottryResult') @InjectModel('LottryResult')
private lotteryResultModel: Model<CommentDocument> private lotteryResultModel: Model<LottoryResultDocument>
) { } ) { }
async getUserScore(username: string, profileUsername: string, postArray: string[]) { async getUserScore(username: string, profileUsername: string, postArray: string[]) {
...@@ -76,7 +79,20 @@ export class LotteryService { ...@@ -76,7 +79,20 @@ export class LotteryService {
async getResultDb() { async getResultDb() {
return await this.lotteryResultModel return await this.lotteryResultModel
.find() .find()
.select({ username: 1, index: 1 }); .select({ username: 1, index: 1 , status: 1});
} }
async changeStatus(changeStatus: ChangeStatusDto){
let foundLottryResults = await this.lotteryResultModel.find({
username: changeStatus.username
})
for await (const result of foundLottryResults) {
result.status = "online"
await result.save()
}
await this.userModel.findOneAndUpdate({username: changeStatus.username},{mobile: changeStatus.mobile})
return {
message: "status changed to online successfully"
}
}
} }
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