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
984f68cb
Commit
984f68cb
authored
Jan 30, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some of vote apis
parent
74cab697
Pipeline
#2276
passed with stages
in 48 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
114 additions
and
0 deletions
+114
-0
src/app.service.ts
src/app.service.ts
+114
-0
No files found.
src/app.service.ts
View file @
984f68cb
...
...
@@ -16,6 +16,8 @@ import axios from 'axios';
import
{
config
}
from
'
./config
'
;
import
qs
from
'
qs
'
;
import
{
EloUtility
}
from
'
./EloUtility
'
;
import
{
Votes
}
from
'
./entities/mycard/Votes
'
;
import
{
VoteResult
}
from
'
./entities/mycard/VoteResult
'
;
const
attrOffset
=
1010
;
const
raceOffset
=
1020
;
...
...
@@ -800,4 +802,116 @@ export class AppService {
return
null
;
}
async
updateVotes
(
body
:
any
)
{
const
id
=
parseInt
(
body
.
id
)
||
null
;
const
title
=
body
.
title
as
string
;
const
options
=
body
.
options
as
string
;
const
start_time
=
moment
(
body
.
start_time
).
toDate
();
const
end_time
=
moment
(
body
.
end_time
).
toDate
();
const
status
=
!!
body
.
status
||
false
;
const
multiple
=
!!
body
.
multiple
||
false
;
const
max
=
body
.
max
?
parseInt
(
body
.
max
)
:
2
;
const
now
=
moment
().
toDate
();
const
repo
=
this
.
mcdb
.
getRepository
(
Votes
);
let
vote
;
if
(
id
)
{
vote
=
await
repo
.
findOne
({
id
,
});
}
if
(
!
vote
)
{
vote
=
new
Votes
();
}
vote
.
title
=
title
;
vote
.
options
=
options
;
vote
.
startTime
=
start_time
;
vote
.
endTime
=
end_time
;
vote
.
status
=
status
;
vote
.
multiple
=
multiple
;
vote
.
max
=
max
;
try
{
await
repo
.
save
(
vote
);
return
200
;
}
catch
(
e
)
{
this
.
log
.
error
(
`Errored updating votes:
${
e
.
toString
()}
`
);
return
500
;
}
}
async
updateVoteStatus
(
body
:
any
)
{
const
id
=
parseInt
(
body
.
id
)
||
null
;
const
status
=
!!
body
.
status
;
if
(
!
id
)
{
return
401
;
}
const
repo
=
this
.
mcdb
.
getRepository
(
Votes
);
try
{
const
result
=
await
repo
.
update
({
id
},
{
status
});
return
result
.
affected
?
200
:
404
;
}
catch
(
e
)
{
this
.
log
.
error
(
`Errored updating vote status for
${
id
}
:
${
e
.
toString
()}
`
);
return
500
;
}
}
async
submitVote
(
body
:
any
)
{
const
user
:
string
=
body
.
user
;
const
username
:
string
=
body
.
username
;
if
(
!
user
||
!
username
||
user
==
'
undefined
'
||
username
==
'
undefined
'
)
{
return
400
;
}
const
voteid
:
string
=
body
.
voteid
;
const
opid
:
string
=
body
.
opid
;
const
opids
:
string
[]
=
body
.
opids
;
const
multiple
=
body
.
multiple
===
'
true
'
;
const
date_time
=
moment
().
format
(
'
YYYY-MM-DD
'
);
const
create_time
=
moment
().
toDate
();
const
repo
=
this
.
mcdb
.
getRepository
(
VoteResult
);
try
{
if
(
multiple
)
{
if
(
!
opids
)
{
return
400
;
}
const
voteResults
=
opids
.
map
((
opid
)
=>
{
const
voteResult
=
new
VoteResult
();
voteResult
.
voteId
=
voteid
;
voteResult
.
optionId
=
opid
;
voteResult
.
userid
=
user
;
voteResult
.
dateTime
=
date_time
;
voteResult
.
createTime
=
create_time
;
return
voteResult
;
});
await
Promise
.
all
(
voteResults
.
map
((
voteResult
)
=>
repo
.
save
(
voteResult
)),
);
}
else
{
const
voteResult
=
new
VoteResult
();
voteResult
.
voteId
=
voteid
;
voteResult
.
optionId
=
opid
;
voteResult
.
userid
=
user
;
voteResult
.
dateTime
=
date_time
;
voteResult
.
createTime
=
create_time
;
await
repo
.
save
(
voteResult
);
}
if
(
username
)
{
await
this
.
mcdb
.
getRepository
(
UserInfo
)
.
update
({
username
},
{
exp
:
()
=>
'
exp + 1
'
,
id
:
parseInt
(
user
)
});
}
return
200
;
}
catch
(
e
)
{
this
.
log
.
error
(
`Failed updating vote result:
${
e
.
toString
()}
`
);
return
500
;
}
}
}
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