Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
shahriar
instagram-service
Commits
7d1337da
Commit
7d1337da
authored
Aug 22, 2021
by
soheib
Browse files
add getting posts from db
parent
58873aad
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/lottery/dto/calculate-score-dto.ts
View file @
7d1337da
...
@@ -2,11 +2,5 @@ import { ApiProperty } from "@nestjs/swagger"
...
@@ -2,11 +2,5 @@ import { ApiProperty } from "@nestjs/swagger"
import
{
IsDateString
,
IsNotEmpty
}
from
"
class-validator
"
import
{
IsDateString
,
IsNotEmpty
}
from
"
class-validator
"
export
class
CalculateScoreDto
{
export
class
CalculateScoreDto
{
@
ApiProperty
({
example
:
"
azadi.gold
"
})
@
IsNotEmpty
()
profile_username
:
string
@
ApiProperty
({
example
:
[
'
GKCUev0s5dJO
'
,
'
CSCUev0swJO
'
,
'
CSCUev0swJO
'
]
})
@
IsNotEmpty
()
post_array
:
string
[]
}
}
\ No newline at end of file
src/lottery/dto/weekly-search-dto.ts
View file @
7d1337da
...
@@ -6,11 +6,5 @@ export class WeeklySearchDto {
...
@@ -6,11 +6,5 @@ export class WeeklySearchDto {
@
ApiProperty
({
example
:
"
kakasrm
"
})
@
ApiProperty
({
example
:
"
kakasrm
"
})
@
IsNotEmpty
()
@
IsNotEmpty
()
username
:
string
username
:
string
@
ApiProperty
({
example
:
"
azadi.gold
"
})
@
IsNotEmpty
()
profile_username
:
string
@
ApiProperty
({
example
:
[
'
GKCUev0s5dJO
'
,
'
CSCUev0swJO
'
,
'
CSCUev0swJO
'
]
})
@
IsNotEmpty
()
post_array
:
string
[]
}
}
\ No newline at end of file
src/lottery/lottery.controller.ts
View file @
7d1337da
import
{
Body
,
Query
,
Controller
,
Get
,
Post
}
from
'
@nestjs/common
'
;
import
{
Body
,
Controller
,
Get
,
Post
}
from
'
@nestjs/common
'
;
import
{
ApiBody
,
ApiTags
}
from
'
@nestjs/swagger
'
import
{
ApiBody
,
ApiTags
}
from
'
@nestjs/swagger
'
import
{
CalculateScoreDto
}
from
'
./dto/calculate-score-dto
'
import
{
ChangeStatusDto
}
from
'
./dto/change-status-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
'
;
...
@@ -15,16 +14,13 @@ export class LotteryController {
...
@@ -15,16 +14,13 @@ export class LotteryController {
@
ApiTags
(
'
Lottery/weekly
'
)
@
ApiTags
(
'
Lottery/weekly
'
)
@
Post
(
'
weekly/search
'
)
@
Post
(
'
weekly/search
'
)
async
getUserResults
(@
Body
()
searchDto
:
WeeklySearchDto
)
{
async
getUserResults
(@
Body
()
searchDto
:
WeeklySearchDto
)
{
return
await
this
.
lotteryService
.
getUserScore
(
searchDto
.
username
,
return
await
this
.
lotteryService
.
getUserScore
(
searchDto
.
username
)
searchDto
.
profile_username
,
searchDto
.
post_array
)
}
}
@
ApiBody
({
type
:
CalculateScoreDto
})
@
ApiTags
(
'
Lottery/weekly
'
)
@
ApiTags
(
'
Lottery/weekly
'
)
@
Post
(
'
weekly/calculate-score
'
)
@
Get
(
'
weekly/calculate-score
'
)
async
addResultsToDb
(@
Body
()
calculateScoreDto
:
CalculateScoreDto
)
{
async
addResultsToDb
()
{
return
await
this
.
lotteryService
.
addResultsToDB
(
calculateScoreDto
.
profile_username
,
return
await
this
.
lotteryService
.
addResultsToDB
()
calculateScoreDto
.
post_array
)
}
}
@
ApiTags
(
'
Lottery/weekly
'
)
@
ApiTags
(
'
Lottery/weekly
'
)
...
...
src/lottery/lottery.service.ts
View file @
7d1337da
...
@@ -2,15 +2,14 @@ import { Injectable, NotFoundException } from '@nestjs/common'
...
@@ -2,15 +2,14 @@ import { Injectable, NotFoundException } from '@nestjs/common'
import
{
InjectModel
}
from
'
@nestjs/mongoose
'
import
{
InjectModel
}
from
'
@nestjs/mongoose
'
import
{
Model
,
Types
}
from
'
mongoose
'
import
{
Model
,
Types
}
from
'
mongoose
'
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
{
LikeDocument
}
from
'
src/instagram/models/like.schema
'
import
{
LikeDocument
}
from
'
src/instagram/models/like.schema
'
import
{
LottoryResultDocument
}
from
'
src/instagram/models/LottoryResult.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
{
ChangeStatusDto
}
from
'
./dto/change-status-dto
'
import
{
ChangeStatusDto
}
from
'
./dto/change-status-dto
'
import
{
ScoreService
}
from
'
./score.service
'
import
{
ScoreService
}
from
'
./score.service
'
import
{
StoryMentionDocument
}
from
'
src/instagram/models/storyMention.schema
'
import
{
StoryMentionDocument
}
from
'
src/instagram/models/storyMention.schema
'
import
{
Cron
,
CronExpression
}
from
'
@nestjs/schedule
'
import
{
Cron
,
CronExpression
}
from
'
@nestjs/schedule
'
import
{
PostDocument
}
from
'
src/instagram/models/post.schema
'
@
Injectable
()
@
Injectable
()
export
class
LotteryService
{
export
class
LotteryService
{
...
@@ -18,8 +17,8 @@ export class LotteryService {
...
@@ -18,8 +17,8 @@ export class LotteryService {
private
scoreService
:
ScoreService
,
private
scoreService
:
ScoreService
,
@
InjectModel
(
'
User
'
)
@
InjectModel
(
'
User
'
)
private
userModel
:
Model
<
UserDocument
>
,
private
userModel
:
Model
<
UserDocument
>
,
@
InjectModel
(
'
Follower
'
)
@
InjectModel
(
'
Post
'
)
private
follower
Model
:
Model
<
Follower
Document
>
,
private
post
Model
:
Model
<
Post
Document
>
,
@
InjectModel
(
'
Like
'
)
@
InjectModel
(
'
Like
'
)
private
likeModel
:
Model
<
LikeDocument
>
,
private
likeModel
:
Model
<
LikeDocument
>
,
@
InjectModel
(
'
Comment
'
)
@
InjectModel
(
'
Comment
'
)
...
@@ -30,26 +29,23 @@ export class LotteryService {
...
@@ -30,26 +29,23 @@ export class LotteryService {
private
storyMentionModel
:
Model
<
StoryMentionDocument
>
,
private
storyMentionModel
:
Model
<
StoryMentionDocument
>
,
)
{
}
)
{
}
async
getUserScore
(
async
getUserScore
(
username
:
string
)
{
username
:
string
,
profileUsername
:
string
,
postArray
:
string
[],
)
{
const
foundUser
=
await
this
.
userModel
.
findOne
({
username
})
const
foundUser
=
await
this
.
userModel
.
findOne
({
username
})
let
postArray
=
await
this
.
getPosts
()
const
likesScore
=
await
this
.
scoreService
.
getUserLikesScore
(
const
likesScore
=
await
this
.
scoreService
.
getUserLikesScore
(
foundUser
.
_id
,
foundUser
.
_id
,
profileUsername
,
"
azadi.gold
"
,
postArray
,
postArray
,
)
)
const
commentScore
=
await
this
.
scoreService
.
getUserCommentsScore
(
const
commentScore
=
await
this
.
scoreService
.
getUserCommentsScore
(
foundUser
.
_id
,
foundUser
.
_id
,
profileUsername
,
"
azadi.gold
"
,
postArray
,
postArray
,
)
)
const
addToStoryScore
=
await
this
.
scoreService
.
getTagsScore
(
username
)
const
addToStoryScore
=
await
this
.
scoreService
.
getTagsScore
(
username
)
let
foundIndexes
=
await
this
.
lotteryResultModel
.
find
({
user_id
:
foundUser
.
_id
})
let
foundIndexes
=
await
this
.
lotteryResultModel
.
find
({
user_id
:
foundUser
.
_id
})
let
chances
=
new
Array
<
string
>
()
let
chances
=
new
Array
<
string
>
()
foundIndexes
.
forEach
(
result
=>
{
foundIndexes
.
forEach
(
result
=>
{
chances
.
push
(
result
.
index
)
chances
.
push
(
result
.
index
)
})
})
return
{
return
{
...
@@ -57,13 +53,13 @@ export class LotteryService {
...
@@ -57,13 +53,13 @@ export class LotteryService {
commentScore
,
commentScore
,
addToStoryScore
,
addToStoryScore
,
totalScore
:
likesScore
+
commentScore
+
addToStoryScore
,
totalScore
:
likesScore
+
commentScore
+
addToStoryScore
,
lottry_chances
:
chances
lottry_chances
:
chances
}
}
}
}
async
addResultsToDB
(
profileUsername
:
string
,
postArray
:
string
[]
)
{
async
addResultsToDB
(
profileUsername
=
"
azadi.gold
"
)
{
const
foundUser_idsList
=
await
this
.
getUserList
()
const
foundUser_idsList
=
await
this
.
getUserList
()
let
postArray
=
await
this
.
getPosts
()
let
index
=
0
let
index
=
0
for
await
(
const
user_id
of
foundUser_idsList
)
{
for
await
(
const
user_id
of
foundUser_idsList
)
{
const
userScore
=
await
this
.
scoreService
.
calculateUserScore
(
const
userScore
=
await
this
.
scoreService
.
calculateUserScore
(
...
@@ -71,8 +67,6 @@ export class LotteryService {
...
@@ -71,8 +67,6 @@ export class LotteryService {
profileUsername
,
profileUsername
,
postArray
,
postArray
,
)
)
console
.
log
(
'
=========
'
,
userScore
);
const
foundUserLastCount
=
await
this
.
lotteryResultModel
.
countDocuments
({
const
foundUserLastCount
=
await
this
.
lotteryResultModel
.
countDocuments
({
user_id
:
new
Types
.
ObjectId
(
user_id
),
user_id
:
new
Types
.
ObjectId
(
user_id
),
})
})
...
@@ -162,11 +156,14 @@ export class LotteryService {
...
@@ -162,11 +156,14 @@ export class LotteryService {
return
userList
return
userList
}
}
async
getPosts
()
{
return
await
this
.
postModel
.
distinct
(
'
url
'
)
as
string
[]
}
@
Cron
(
CronExpression
.
EVERY_3_HOURS
)
@
Cron
(
CronExpression
.
EVERY_3_HOURS
)
async
cronCalculateScore
()
{
async
cronCalculateScore
()
{
console
.
log
(
'
start cron ======> calculate daily score
'
);
console
.
log
(
'
start cron ======> calculate daily score
'
)
let
postArray
=
[
"
CSlqcUEAZsU
"
]
let
account
=
"
azadi.gold
"
let
account
=
"
azadi.gold
"
await
this
.
addResultsToDB
(
account
,
postArray
)
await
this
.
addResultsToDB
(
account
)
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment