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
3f851a16
Commit
3f851a16
authored
Feb 19, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get /api/votes
parent
30a316c9
Pipeline
#2453
passed with stages
in 1 minute and 6 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
3 deletions
+101
-3
src/app.controller.ts
src/app.controller.ts
+10
-2
src/app.service.ts
src/app.service.ts
+90
-0
src/entities/mycard/Votes.ts
src/entities/mycard/Votes.ts
+1
-1
No files found.
src/app.controller.ts
View file @
3f851a16
...
...
@@ -102,6 +102,12 @@ export class AppController {
res
.
status
(
code
).
json
({
code
});
}
@
Get
(
'
votes
'
)
async
getVotes
(@
Query
()
query
:
any
)
{
const
result
=
await
this
.
appService
.
getVotes
(
query
);
return
result
;
}
@
Post
(
'
upload
'
)
uploadFile
(@
Req
()
req
:
express
.
Request
,
@
Res
()
res
:
express
.
Response
)
{
const
form
=
new
IncomingForm
();
...
...
@@ -115,7 +121,9 @@ export class AppController {
return
res
.
status
(
500
).
send
(
'
upload image fail!
'
);
}
const
response
:
any
=
{};
const
response
=
{
code
:
200
,
};
if
(
err
)
{
response
.
code
=
500
;
}
else
{
...
...
@@ -125,7 +133,7 @@ export class AppController {
response
.
path
=
files
.
file
.
path
;
}
res
.
json
(
response
);
res
.
status
(
response
.
code
).
json
(
response
);
});
}
@
Get
(
'
download/:id
'
)
...
...
src/app.service.ts
View file @
3f851a16
...
...
@@ -75,6 +75,13 @@ interface PlayerDiff {
entertain_all
:
number
;
}
interface
VoteOption
{
key
:
number
;
name
:
string
;
count
:
number
;
percentage
:
number
;
}
@
Injectable
()
export
class
AppService
{
chineseDirtyFilter
:
Filter
;
...
...
@@ -924,4 +931,87 @@ export class AppService {
return
500
;
}
}
private
async
fetchVoteOptionCount
(
voteId
:
number
,
optionId
:
number
,
optionCountMap
,
)
{
const
count
=
await
this
.
mcdb
.
getRepository
(
VoteResult
).
count
({
voteId
:
voteId
.
toString
(),
optionId
:
optionId
.
toString
(),
});
optionCountMap
[
optionId
]
=
count
;
}
private
async
fetchVoteInfo
(
vote
:
Votes
,
optionCountMap
:
any
,
voteCountMap
:
any
,
)
{
const
repo
=
this
.
mcdb
.
getRepository
(
VoteResult
);
const
voteId
=
vote
.
id
;
const
options
:
VoteOption
[]
=
JSON
.
parse
(
vote
.
options
);
await
Promise
.
all
(
options
.
map
((
option
)
=>
this
.
fetchVoteOptionCount
(
voteId
,
option
.
key
,
optionCountMap
),
),
);
const
optionIdStrings
=
options
.
map
((
option
)
=>
option
.
key
.
toString
());
const
voteCountResult
=
await
repo
.
createQueryBuilder
()
.
select
(
'
count(DISTINCT userid)
'
,
'
voteCount
'
)
.
where
(
'
vote_id = :voteId
'
,
{
voteId
:
voteId
.
toString
()
})
.
andWhere
(
'
option_id in (:...optionIdStrings)
'
,
{
optionIdStrings
})
.
getRawOne
();
const
voteCount
:
number
=
parseInt
(
voteCountResult
.
voteCount
);
voteCountMap
[
voteId
]
=
voteCount
;
}
async
getVotes
(
query
:
any
)
{
const
username
=
query
.
username
;
const
type
=
query
.
type
;
let
status
:
boolean
=
undefined
;
if
(
type
===
'
1
'
)
{
status
=
true
;
}
if
(
type
===
'
2
'
)
{
status
=
false
;
}
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
countQuery
=
repo
.
createQueryBuilder
();
if
(
status
!==
undefined
)
{
countQuery
.
where
(
'
status = :status
'
,
{
status
});
}
const
total
=
await
countQuery
.
getCount
();
const
voteQuery
=
repo
.
createQueryBuilder
();
if
(
status
!==
undefined
)
{
voteQuery
.
where
(
'
status = :status
'
,
{
status
});
}
voteQuery
.
orderBy
(
'
create_time
'
,
'
DESC
'
).
limit
(
page_num
).
offset
(
offset
);
const
votes
=
await
voteQuery
.
getMany
();
const
optionCountMap
:
any
=
{};
const
voteCountMap
:
any
=
{};
await
Promise
.
all
(
votes
.
map
((
vote
)
=>
this
.
fetchVoteInfo
(
vote
,
optionCountMap
,
voteCountMap
),
),
);
return
{
total
,
data
:
votes
,
voteCountMap
,
optionCountMap
,
};
}
}
src/entities/mycard/Votes.ts
View file @
3f851a16
...
...
@@ -24,7 +24,7 @@ export class Votes {
@
Column
(
'
timestamp without time zone
'
,
{
name
:
'
end_time
'
,
nullable
:
true
})
endTime
:
Date
;
@
Column
(
'
boolean
'
,
{
name
:
'
status
'
,
nullable
:
true
,
default
:
'
false
'
})
@
Column
(
'
boolean
'
,
{
name
:
'
status
'
,
nullable
:
true
,
default
:
false
})
status
:
boolean
;
@
Column
(
'
boolean
'
,
{
...
...
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