Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
Ygopro Arena Revive
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Ygopro Arena Revive
Commits
abe143da
Commit
abe143da
authored
Feb 21, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
/history
parent
092fadcd
Pipeline
#2467
passed with stages
in 37 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
12 deletions
+77
-12
src/app.controller.ts
src/app.controller.ts
+4
-0
src/app.service.ts
src/app.service.ts
+73
-12
No files found.
src/app.controller.ts
View file @
abe143da
...
...
@@ -221,4 +221,8 @@ export class AppController {
const
code
=
await
this
.
appService
.
submitDeckInfo
(
body
);
res
.
status
(
code
).
json
({
code
});
}
@
Get
(
'
history
'
)
async
getBattleHistory
(@
Query
()
query
:
any
)
{
return
await
this
.
appService
.
getBattleHistory
(
query
);
}
}
src/app.service.ts
View file @
abe143da
import
{
Injectable
}
from
'
@nestjs/common
'
;
import
{
InjectConnection
,
InjectEntityManager
}
from
'
@nestjs/typeorm
'
;
import
{
Brackets
,
Connection
,
EntityManager
,
LessThan
,
LessThanOrEqual
,
Like
,
MoreThanOrEqual
,
SelectQueryBuilder
,
}
from
'
typeorm
'
;
import
{
UserInfo
}
from
'
./entities/mycard/UserInfo
'
;
import
Filter
from
'
bad-words-chinese
'
;
...
...
@@ -622,7 +624,6 @@ export class AppService {
if
(
!
tryFirstWin
)
{
firstWin
=
true
;
}
console
.
log
(
tryFirstWin
);
}
const
ptResult
=
EloUtility
.
getEloScore
(
userA
.
pt
,
userB
.
pt
,
sa
,
sb
);
...
...
@@ -1050,6 +1051,20 @@ export class AppService {
voteCountMap
[
voteId
]
=
voteCountResult
.
voteCount
;
}
private
async
queryPageAndTotal
<
T
>
(
page_no
:
number
,
page_num
:
number
,
queryFunction
:
()
=>
SelectQueryBuilder
<
T
>
,
)
{
// page_no 当前页数 page_num 每页展示数
// offset = (page_no - 1) * page_num
// select * from battle_history limit 5 offset 15;
const
offset
=
(
page_no
-
1
)
*
page_num
;
const
total
=
await
queryFunction
().
getCount
();
const
data
=
await
queryFunction
().
limit
(
page_num
).
offset
(
offset
).
getMany
();
return
{
total
,
data
};
}
async
getVotes
(
query
:
any
)
{
const
username
=
query
.
username
;
const
type
=
query
.
type
;
...
...
@@ -1064,21 +1079,22 @@ export class AppService {
const
from_date
=
query
.
from_date
;
const
to_date
=
query
.
to_date
;
// page_no 当前页数 page_num 每页展示数
// offset = (page_no - 1) * page_num
// select * from battle_history limit 5 offset 15;
const
page_no
:
number
=
query
.
page
||
1
;
const
page_num
:
number
=
query
.
page_num
||
15
;
const
offset
=
(
page_no
-
1
)
*
page_num
;
const
repo
=
this
.
mcdb
.
getRepository
(
Votes
);
const
{
total
,
data
:
votes
}
=
await
this
.
queryPageAndTotal
(
page_no
,
page_num
,
()
=>
{
const
voteQuery
=
repo
.
createQueryBuilder
();
if
(
status
!==
undefined
)
{
voteQuery
.
where
(
'
status = :status
'
,
{
status
});
}
const
total
=
await
voteQuery
.
getCount
();
voteQuery
.
orderBy
(
'
create_time
'
,
'
DESC
'
);
voteQuery
.
limit
(
page_num
).
offset
(
offset
);
const
votes
=
await
voteQuery
.
getMany
();
return
voteQuery
;
},
);
const
optionCountMap
:
any
=
{};
const
voteCountMap
:
any
=
{};
await
Promise
.
all
(
...
...
@@ -1373,4 +1389,49 @@ export class AppService {
});
return
code
;
}
async
getBattleHistory
(
query
:
any
)
{
const
username
:
string
=
query
.
username
;
const
type
=
query
.
type
;
let
arena
:
string
=
null
;
//1 athletic 2 entertain
if
(
type
===
'
1
'
)
{
arena
=
'
athletic
'
;
}
if
(
type
===
'
2
'
)
{
arena
=
'
entertain
'
;
}
const
from_date
=
query
.
from_date
;
const
to_date
=
query
.
to_date
;
// page_no 当前页数 page_num 每页展示数
// offset = (page_no - 1) * page_num
// select * from battle_history limit 5 offset 15;
const
page_no
:
number
=
query
.
page
||
1
;
const
page_num
:
number
=
query
.
page_num
||
15
;
const
ret
=
await
this
.
queryPageAndTotal
(
page_no
,
page_num
,
()
=>
{
const
query
=
this
.
mcdb
.
getRepository
(
BattleHistory
)
.
createQueryBuilder
()
.
where
(
'
1 = 1
'
);
if
(
username
)
{
query
.
andWhere
(
new
Brackets
((
qb
)
=>
{
qb
.
where
(
'
usernamea = :usernamea
'
,
{
usernamea
:
username
,
}).
orWhere
(
'
usernameb = :usernameb
'
,
{
usernameb
:
username
,
});
}),
);
}
if
(
arena
)
{
query
.
andWhere
(
'
type = :arena
'
,
{
arena
});
}
query
.
orderBy
(
'
start_time
'
,
'
DESC
'
);
return
query
;
});
return
ret
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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