Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Voting
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dennis Willers
Voting
Commits
c857d223
Commit
c857d223
authored
Aug 23, 2021
by
Matthieu - Greep
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix player check
parent
bdb7089f
Pipeline
#460
passed with stage
in 51 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
42 deletions
+41
-42
setVote.js
route/setVote.js
+41
-42
No files found.
route/setVote.js
View file @
c857d223
...
@@ -20,49 +20,48 @@ module.exports = function(app, sql, tokenCheck, errorHandler) {
...
@@ -20,49 +20,48 @@ module.exports = function(app, sql, tokenCheck, errorHandler) {
if
(
vote
<
0
||
vote
>
100
)
return
errorHandler
(
res
,
400
,
'
Vote must be between 0 and 100
'
);
if
(
vote
<
0
||
vote
>
100
)
return
errorHandler
(
res
,
400
,
'
Vote must be between 0 and 100
'
);
// check if player exists (tmio API check)
// check if player exists (tmio API check)
tmioPlayer
.
player
(
player
).
then
((
playerData
)
=>
{
tmioPlayer
.
player
(
player
).
then
(()
=>
{
if
(
playerData
.
error
)
return
errorHandler
(
res
,
400
,
playerData
.
error
);
sql
.
query
(
'
SELECT * FROM votes WHERE map = ? AND player = ?
'
,
[
mapId
,
player
],
(
err
,
sqlRes
)
=>
{
});
if
(
err
)
{
console
.
log
(
err
);
sql
.
query
(
'
SELECT * FROM votes WHERE map = ? AND player = ?
'
,
[
mapId
,
player
],
(
err
,
sqlRes
)
=>
{
errorHandler
(
res
,
500
,
'
Internal server error
'
);
if
(
err
)
{
}
else
{
console
.
log
(
err
);
const
voteDate
=
new
Date
();
errorHandler
(
res
,
500
,
'
Internal server error
'
);
if
(
sqlRes
.
length
===
0
)
{
// Create a new vote for this player
}
else
{
sql
.
query
(
'
INSERT INTO votes (map, player, vote, date) VALUES (?, ?, ?, ?)
'
,
[
mapId
,
player
,
vote
,
voteDate
],
(
err
)
=>
{
const
voteDate
=
new
Date
();
if
(
err
)
{
if
(
sqlRes
.
length
===
0
)
{
// Create a new vote for this player
console
.
error
(
err
);
sql
.
query
(
'
INSERT INTO votes (map, player, vote, date) VALUES (?, ?, ?, ?)
'
,
[
mapId
,
player
,
vote
,
voteDate
],
(
err
)
=>
{
errorHandler
(
res
,
500
,
'
Internal server error
'
);
if
(
err
)
{
}
else
{
console
.
error
(
err
);
res
.
json
({
errorHandler
(
res
,
500
,
'
Internal server error
'
);
mapUid
:
mapId
,
}
else
{
player
:
player
,
res
.
json
({
vote
:
vote
,
mapUid
:
mapId
,
date
:
voteDate
,
player
:
player
,
type
:
"
new
"
vote
:
vote
,
});
date
:
voteDate
,
}
type
:
"
new
"
});
});
}
else
{
// Update the vote for this player
}
sql
.
query
(
'
UPDATE votes SET vote = ?, date = ? WHERE map = ? AND player = ?
'
,
[
vote
,
voteDate
,
mapId
,
player
],
(
err
)
=>
{
});
if
(
err
)
{
}
else
{
// Update the vote for this player
console
.
error
(
err
);
sql
.
query
(
'
UPDATE votes SET vote = ?, date = ? WHERE map = ? AND player = ?
'
,
[
vote
,
voteDate
,
mapId
,
player
],
(
err
)
=>
{
errorHandler
(
res
,
500
,
'
Internal server error
'
);
if
(
err
)
{
}
else
{
console
.
error
(
err
);
res
.
json
({
errorHandler
(
res
,
500
,
'
Internal server error
'
);
mapUid
:
mapId
,
}
else
{
player
:
player
,
res
.
json
({
vote
:
vote
,
mapUid
:
mapId
,
date
:
voteDate
,
player
:
player
,
type
:
"
update
"
vote
:
vote
,
});
date
:
voteDate
,
}
type
:
"
update
"
});
});
}
}
});
}
}
}
});
});
})
.
catch
((
err
)
=>
errorHandler
(
res
,
400
,
err
));
// player not found
//});
//});
});
});
};
};
\ No newline at end of file
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