Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-arena-api
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-api
Commits
452a580c
Commit
452a580c
authored
Feb 11, 2017
by
ganjingcun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asd
parent
2ca638be
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
4 deletions
+50
-4
routes/api.js
routes/api.js
+44
-2
test.js
test.js
+6
-2
No files found.
routes/api.js
View file @
452a580c
...
@@ -213,7 +213,7 @@ router.post('/score', function (req, res) {
...
@@ -213,7 +213,7 @@ router.post('/score', function (req, res) {
}
}
queries
.
map
(
function
(
q
)
{
queries
.
map
(
function
(
q
)
{
console
.
log
(
q
)
//
console.log(q)
return
client
.
query
(
q
)
return
client
.
query
(
q
)
}).
pop
().
on
(
'
end
'
,
function
()
{
}).
pop
().
on
(
'
end
'
,
function
()
{
console
.
log
(
"
finished update score !
"
)
console
.
log
(
"
finished update score !
"
)
...
@@ -277,6 +277,48 @@ router.get('/users', function (req, res) {
...
@@ -277,6 +277,48 @@ router.get('/users', function (req, res) {
});
});
router
.
get
(
'
/history
'
,
function
(
req
,
res
)
{
// to run a query we c
an
acquire
a
client
from
the
pool
,
// run a query on the client, and then return the client to the pool
pool
.
connect
(
function
(
err
,
client
,
done
)
{
if
(
err
)
{
return
console
.
error
(
'
error fetching client from pool
'
,
err
);
}
// order by what ? default pt
var
o
=
req
.
query
.
o
||
'
pt
'
;
// page_no 当前页数 page_num 每页展示数
// offset = (page_no - 1) * page_num
// select * from battle_history limit 5 offset 15;
var
page_no
=
req
.
query
.
page_no
||
1
var
page_num
=
req
.
query
.
page_num
||
15
var
offset
=
(
page_no
-
1
)
*
page_num
var
sql
=
'
SELECT count(*) from battle_history
'
console
.
log
(
sql
);
client
.
query
(
sql
,
function
(
err
,
result
)
{
var
total
=
result
.
rows
[
0
].
count
var
sql2
=
`SELECT * from battle_history order by start_time desc limit
${
page_num
}
offset
${
offset
}
`
client
.
query
(
sql2
,
function
(
err
,
result
)
{
//call `done()` to release the client back to the pool
done
()
if
(
err
)
{
return
console
.
error
(
'
error running query
'
,
err
)
}
res
.
json
({
total
:
total
-
0
,
data
:
result
.
rows
});
});
});
});
});
router
.
get
(
'
/user
'
,
function
(
req
,
res
)
{
router
.
get
(
'
/user
'
,
function
(
req
,
res
)
{
// to run a query we can acquire a client from the pool,
// to run a query we can acquire a client from the pool,
...
@@ -349,7 +391,7 @@ router.get('/user', function (req, res) {
...
@@ -349,7 +391,7 @@ router.get('/user', function (req, res) {
var
ep
=
new
eventproxy
()
var
ep
=
new
eventproxy
()
ep
.
after
(
'
delay
'
,
2
,
function
(
row
)
{
ep
.
after
(
'
delay
'
,
2
,
function
(
row
)
{
console
.
log
(
resultData
)
//
console.log(resultData)
res
.
json
(
resultData
)
res
.
json
(
resultData
)
});
});
...
...
test.js
View file @
452a580c
...
@@ -2,8 +2,12 @@
...
@@ -2,8 +2,12 @@
var
superagent
=
require
(
'
superagent
'
)
var
superagent
=
require
(
'
superagent
'
)
// var url = 'https://mycard.moe/ygopro/api/score'
var
url
=
'
http://localhost:3000/api/score
'
superagent
superagent
.
post
(
'
http://localhost:3000/api/score
'
)
.
post
(
url
)
.
send
({
.
send
({
accesskey
:
"
XnvGjNG8jttfjYWhtqtgRfWBtyEwjMaF
"
,
accesskey
:
"
XnvGjNG8jttfjYWhtqtgRfWBtyEwjMaF
"
,
usernameA
:
"
Joe1991
"
,
usernameA
:
"
Joe1991
"
,
...
@@ -12,7 +16,7 @@ superagent
...
@@ -12,7 +16,7 @@ superagent
userscoreB
:
2
,
userscoreB
:
2
,
start
:
'
2016-12-19T12:31:13+08:00
'
,
start
:
'
2016-12-19T12:31:13+08:00
'
,
end
:
'
2016-12-19T12:41:13+08:00
'
,
end
:
'
2016-12-19T12:41:13+08:00
'
,
arena
:
'
athletic
'
// '
entertain
' 竞技 or 'entertain' 娱乐
arena
:
'
athletic
'
// '
athletic
' 竞技 or 'entertain' 娱乐
})
})
.
end
(
function
(
err
,
res
)
{
.
end
(
function
(
err
,
res
)
{
if
(
err
)
{
if
(
err
)
{
...
...
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