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
251575ce
Commit
251575ce
authored
Jul 31, 2021
by
velayat
Browse files
change lottry result api
parent
476384c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/LottoryResult.schema.ts
View file @
251575ce
...
...
@@ -5,10 +5,14 @@ export type LottoryResultDocument = LottoryResult & Document;
@
Schema
({
timestamps
:
true
})
export
class
LottoryResult
{
@
Prop
()
index
:
number
;
@
Prop
()
username
:
string
;
@
Prop
()
index
:
number
;
tagged_user
:
string
;
@
Prop
()
status
:
string
;
}
export
const
LottoryResultSchema
=
SchemaFactory
.
createForClass
(
LottoryResult
);
src/app.service.ts
View file @
251575ce
...
...
@@ -505,7 +505,7 @@ export class AppService implements OnApplicationBootstrap {
(
response
.
followed_before_mentions
=
userRes
.
followed_before
),
(
response
.
pending_mentions
=
userRes
.
pending_mentions
),
(
response
.
last_update
=
userRes
[
'
updatedAt
'
]),
(
response
.
score
=
userRes
.
score
);
(
response
.
score
=
userRes
.
score
);
userIndexs
.
forEach
((
index
)
=>
{
response
.
lottory_chances_codes
.
push
(
index
.
index
.
toString
());
});
...
...
@@ -552,16 +552,43 @@ export class AppService implements OnApplicationBootstrap {
}
async
addResultsToDB
()
{
await
this
.
lotoryResultModel
.
deleteMany
();
//
await this.lotoryResultModel.deleteMany();
const
comptitionArray
=
new
Array
<
any
>
();
const
foundUsernames
=
await
this
.
resultModel
.
find
().
sort
({
score
:
-
1
});
console
.
log
(
foundUsernames
);
const
foundUsernames
=
await
this
.
resultModel
.
find
({})
.
sort
({
score
:
-
1
});
let
index
=
1
;
for
await
(
const
user
of
foundUsernames
)
{
for
(
let
u
=
0
;
u
<
user
.
score
;
u
++
)
{
comptitionArray
.
push
({
username
:
user
.
username
,
index
});
for
(
let
u
=
0
;
u
<
user
.
valid_users
.
length
;
u
++
)
{
const
isChanceExist
=
await
this
.
lotoryResultModel
.
findOne
({
username
:
user
.
username
,
tagged_user
:
user
.
valid_users
[
u
],
})
.
exec
();
if
(
!
isChanceExist
)
comptitionArray
.
push
({
index
,
username
:
user
.
username
,
tagged_user
:
user
.
valid_users
[
u
],
status
:
"
valid
"
});
index
++
;
}
const
isUserChanceExist
=
await
this
.
lotoryResultModel
.
findOne
({
username
:
user
.
username
,
tagged_user
:
user
.
username
,
});
if
(
!
isUserChanceExist
)
comptitionArray
.
push
({
index
,
username
:
user
.
username
,
tagged_user
:
user
.
username
,
status
:
"
valid
"
});
index
++
;
}
await
this
.
lotoryResultModel
.
insertMany
(
comptitionArray
);
return
'
successfull
'
;
...
...
@@ -570,7 +597,7 @@ export class AppService implements OnApplicationBootstrap {
async
getResultDb
()
{
return
await
this
.
lotoryResultModel
.
find
()
.
select
({
username
:
1
,
index
:
1
});
.
select
({
username
:
1
,
tagged_user
:
1
,
index
:
1
,
status
:
1
});
}
}
...
...
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