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
3b77a902
Commit
3b77a902
authored
Aug 07, 2021
by
soheib
Browse files
add weakly lottory code
parent
c017535c
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/add-to-story-data.ts
0 → 100644
View file @
3b77a902
export
default
{
addToStoryData
:
[
{
username
:
"
soma.ye2103
"
,
count
:
5
},
{
username
:
"
zahra_51512
"
,
count
:
1
},
{
username
:
"
nafas3633m
"
,
count
:
1
},
{
username
:
"
jafar.amr
"
,
count
:
1
},
{
username
:
"
sougool5382
"
,
count
:
1
},
{
username
:
"
maryam.maryammy
"
,
count
:
1
},
{
username
:
"
toktam.yobi80
"
,
count
:
1
},
{
username
:
"
roghayeh_b8082
"
,
count
:
1
},
{
username
:
"
turky.yyy
"
,
count
:
1
},
{
username
:
"
liligoli
"
,
count
:
1
},
{
username
:
"
soh.ila50
"
,
count
:
1
},
{
username
:
"
_mrs_kz_z
"
,
count
:
1
},
]
}
\ No newline at end of file
src/app.controller.ts
View file @
3b77a902
...
@@ -8,7 +8,12 @@ export class AppController {
...
@@ -8,7 +8,12 @@ export class AppController {
@
Post
(
'
get-score
'
)
@
Post
(
'
get-score
'
)
async
getUserResults
(@
Body
(
'
username
'
)
username
:
string
)
{
async
getUserResults
(@
Body
(
'
username
'
)
username
:
string
)
{
return
await
this
.
appService
.
getUserLikes
(
username
);
return
await
this
.
appService
.
getUserScore
(
username
);
}
@
Get
(
'
calculate-score
'
)
async
getFollowers
()
{
return
await
this
.
appService
.
addResultsToDB
();
}
}
}
}
...
...
src/app.module.ts
View file @
3b77a902
...
@@ -5,11 +5,12 @@ import { AppController } from './app.controller';
...
@@ -5,11 +5,12 @@ import { AppController } from './app.controller';
import
{
AppService
}
from
'
./app.service
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
LikeSchema
}
from
'
./models/like.schema
'
;
import
{
LikeSchema
}
from
'
./models/like.schema
'
;
import
{
CommentSchema
}
from
'
./models/comment.schema
'
;
import
{
CommentSchema
}
from
'
./models/comment.schema
'
;
import
{
LottoryResultSchema
}
from
'
./models/LottoryResult.schema
'
;
@
Module
({
@
Module
({
imports
:
[
imports
:
[
MongooseModule
.
forRoot
(
MongooseModule
.
forRoot
(
'
mongodb://
azadi:azadi
%4040
10
@185.231.180.248:27017/?serverSelectionTimeoutMS=5000&connectTimeoutMS=10000&authSource=admin
&authMechanism=SCRAM-SHA-256
'
,
'
mongodb://
netware:Netware
%4040
8009
@185.231.180.248:27017/
instagram-lottry
?serverSelectionTimeoutMS=5000&connectTimeoutMS=10000&authSource=admin
'
,
),
),
MongooseModule
.
forFeature
([
MongooseModule
.
forFeature
([
{
name
:
'
Follower
'
,
schema
:
FollowerSchema
},
{
name
:
'
Follower
'
,
schema
:
FollowerSchema
},
...
@@ -20,6 +21,9 @@ import { CommentSchema } from './models/comment.schema';
...
@@ -20,6 +21,9 @@ import { CommentSchema } from './models/comment.schema';
MongooseModule
.
forFeature
([
MongooseModule
.
forFeature
([
{
name
:
'
Comment
'
,
schema
:
CommentSchema
},
{
name
:
'
Comment
'
,
schema
:
CommentSchema
},
]),
]),
MongooseModule
.
forFeature
([
{
name
:
'
LottryResult
'
,
schema
:
LottoryResultSchema
},
]),
],
],
controllers
:
[
AppController
],
controllers
:
[
AppController
],
providers
:
[
AppService
],
providers
:
[
AppService
],
...
...
src/app.service.ts
View file @
3b77a902
...
@@ -18,8 +18,10 @@ import FollowerPrivateData from './followers_data';
...
@@ -18,8 +18,10 @@ import FollowerPrivateData from './followers_data';
import
{
CleanedComments
,
MentionDocument
}
from
'
./interface/IcleandComment
'
;
import
{
CleanedComments
,
MentionDocument
}
from
'
./interface/IcleandComment
'
;
import
{
CommentStatus
,
UserAllMention
}
from
'
./interface/UserAllMentions
'
;
import
{
CommentStatus
,
UserAllMention
}
from
'
./interface/UserAllMentions
'
;
import
{
ResultDocument
}
from
'
./result.schema
'
;
import
{
ResultDocument
}
from
'
./result.schema
'
;
import
{
LottoryResultDocument
}
from
'
./LottoryResult.schema
'
;
import
{
LottoryResultDocument
}
from
'
./
models/
LottoryResult.schema
'
;
import
{
FollowerDocument
}
from
'
./models/follower.schema
'
;
import
{
FollowerDocument
}
from
'
./models/follower.schema
'
;
import
{
LikeDocument
}
from
'
./models/like.schema
'
;
import
addToStoryData
from
'
./add-to-story-data
'
@
Injectable
()
@
Injectable
()
export
class
AppService
implements
OnApplicationBootstrap
{
export
class
AppService
implements
OnApplicationBootstrap
{
...
@@ -29,27 +31,128 @@ export class AppService implements OnApplicationBootstrap {
...
@@ -29,27 +31,128 @@ export class AppService implements OnApplicationBootstrap {
@
InjectModel
(
'
Follower
'
)
@
InjectModel
(
'
Follower
'
)
private
followerModel
:
Model
<
FollowerDocument
>
,
private
followerModel
:
Model
<
FollowerDocument
>
,
@
InjectModel
(
'
Like
'
)
@
InjectModel
(
'
Like
'
)
private
likeModel
:
Model
<
Follower
Document
>
,
private
likeModel
:
Model
<
Like
Document
>
,
@
InjectModel
(
'
Comment
'
)
@
InjectModel
(
'
Comment
'
)
private
commentModel
:
Model
<
FollowerDocument
>
,
private
commentModel
:
Model
<
CommentDocument
>
,
@
InjectModel
(
'
LottryResult
'
)
private
lottryResultModel
:
Model
<
LottoryResultDocument
>
,
)
{}
)
{
}
async
onApplicationBootstrap
()
{
async
onApplicationBootstrap
()
{
// this.client = await this.login('shahriarvelayat', 'shve8864@@');
// this.client = await this.login('shahriarvelayat', 'shve8864@@');
this
.
client
=
null
;
this
.
client
=
null
;
}
}
async
getUserLikes
(
username
:
string
){
async
getUserLikesScore
(
username
:
string
)
{
let
foundLikes
=
await
this
.
likeModel
.
find
({
username
})
// let foundFollower = await this.followerModel.findOne({ username })
console
.
log
(
foundLikes
);
// if (foundFollower) {
let
foundLikes
=
await
this
.
likeModel
.
find
({
username
})
return
foundLikes
.
length
return
foundLikes
.
length
// }
// else {
// throw new HttpException(`you are not a follower of this page`, 404)
// }
}
async
getUserCommentsScore
(
username
:
string
)
{
let
foundUserPosts
=
await
this
.
commentModel
.
distinct
(
'
post_short_code
'
)
let
userCommentScore
=
new
Array
<
{
post
:
string
,
post_score
:
number
}
>
()
foundUserPosts
.
forEach
((
post
)
=>
{
userCommentScore
.
push
({
post
,
post_score
:
0
})
})
let
foundUserComments
=
await
this
.
commentModel
.
find
({
owner_username
:
username
})
for
await
(
const
comment
of
foundUserComments
)
{
userCommentScore
.
forEach
(
element
=>
{
if
(
comment
.
post_short_code
===
element
.
post
&&
element
.
post_score
<
3
)
{
element
.
post_score
++
}
})
}
let
score
=
0
userCommentScore
.
forEach
(
element
=>
{
score
+=
element
.
post_score
})
return
score
}
async
getTagsScore
(
username
:
string
)
{
let
addToStoryScore
=
0
let
foundUser
=
addToStoryData
.
addToStoryData
.
find
((
user
)
=>
{
return
user
.
username
===
username
})
if
(
foundUser
)
{
addToStoryScore
=
foundUser
.
count
}
return
addToStoryScore
}
async
calculateUserScore
(
username
:
string
)
{
let
likesScore
=
await
this
.
getUserLikesScore
(
username
)
let
commentScore
=
await
this
.
getUserCommentsScore
(
username
)
let
addToStoryScore
=
await
this
.
getTagsScore
(
username
)
return
likesScore
+
commentScore
+
addToStoryScore
}
async
getUserScore
(
username
:
string
)
{
let
likesScore
=
await
this
.
getUserLikesScore
(
username
)
let
commentScore
=
await
this
.
getUserCommentsScore
(
username
)
let
addToStoryScore
=
await
this
.
getTagsScore
(
username
)
return
{
likesScore
,
commentScore
,
addToStoryScore
,
totalScore
:
likesScore
+
commentScore
+
addToStoryScore
}
}
}
async
getUserComments
(
username
:
string
){
async
addResultsToDB
()
{
let
foundComments
=
await
this
.
commentModel
.
find
({
username
})
await
this
.
lottryResultModel
.
deleteMany
({})
console
.
log
(
foundComments
);
let
foundUsernameInComment
=
await
this
.
commentModel
.
distinct
(
'
owner_username
'
)
return
foundComments
.
length
let
foundUsernameInLike
=
await
this
.
likeModel
.
distinct
(
'
username
'
)
let
foundUsernames
=
new
Array
<
string
>
()
foundUsernameInComment
.
forEach
((
username
)
=>
{
if
(
!
foundUsernames
.
includes
(
username
))
{
foundUsernames
.
push
(
username
)
}
})
foundUsernameInLike
.
forEach
((
username
)
=>
{
if
(
!
foundUsernames
.
includes
(
username
))
{
foundUsernames
.
push
(
username
)
}
})
console
.
log
(
foundUsernames
);
const
comptitionArray
=
new
Array
<
any
>
();
let
index
=
1000
;
let
totalItems
=
foundUsernames
.
length
let
count
=
0
for
await
(
const
username
of
foundUsernames
)
{
let
userScore
=
await
this
.
calculateUserScore
(
username
)
for
(
let
u
=
0
;
u
<
userScore
;
u
++
)
{
comptitionArray
.
push
({
index
,
username
:
username
,
})
index
++
;
console
.
log
(
`username:
${
username
}
, index:
${
index
}
, score:
${
userScore
}
`
);
}
console
.
log
(
`user index:
${
count
}
, total items:
${
totalItems
}
`
);
count
++
}
await
this
.
lottryResultModel
.
insertMany
(
comptitionArray
);
return
'
successfull
'
;
}
}
}
}
...
...
src/LottoryResult.schema.ts
→
src/
models/
LottoryResult.schema.ts
View file @
3b77a902
...
@@ -9,8 +9,8 @@ export class LottoryResult {
...
@@ -9,8 +9,8 @@ export class LottoryResult {
index
:
number
;
index
:
number
;
@
Prop
()
@
Prop
()
username
:
string
;
username
:
string
;
@
Prop
()
//
@Prop()
tagged_user
:
string
;
//
tagged_user: string;
@
Prop
()
@
Prop
()
status
:
string
;
status
:
string
;
}
}
...
...
src/models/comment.schema.ts
View file @
3b77a902
...
@@ -23,6 +23,9 @@ export class Comment {
...
@@ -23,6 +23,9 @@ export class Comment {
@
Prop
()
@
Prop
()
date
:
number
;
date
:
number
;
@
Prop
()
post_short_code
:
string
;
@
Prop
({
type
:
Object
})
@
Prop
({
type
:
Object
})
comment_object
:
Object
;
comment_object
:
Object
;
}
}
...
...
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