Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cbdiscord
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Geovanny E. Vera Pazmino
cbdiscord
Commits
19f69801
Commit
19f69801
authored
Mar 14, 2020
by
Geovera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit routing cleanup
parent
827cd3d9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
36 deletions
+26
-36
units.js
server/models/units.js
+19
-16
units.js
server/routes/units.js
+4
-19
users.js
server/routes/users.js
+3
-1
No files found.
server/models/units.js
View file @
19f69801
...
...
@@ -4,23 +4,22 @@ const units = {};
const
unit_columns
=
[
'name'
,
'type'
,
'stars'
,
'hp'
,
'pap'
,
'pd'
,
'sap'
,
'sd'
,
'bap'
,
'bp'
,
'pdf'
,
'sdf'
,
'bdf'
,
'leadership'
,
'troop_count'
,
'hero_level'
];
units
.
getAll
=
async
(
context
)
=>
{
units
.
getAll
=
async
(
context
,
next
)
=>
{
let
sql_text
=
'SELECT * FROM units'
;
try
{
let
data
=
await
db
.
con
.
query
(
sql_text
);
return
{
units
:
data
};
context
.
response
.
body
=
{
units
:
data
};
}
catch
(
error
){
console
.
log
(
error
);
context
.
throw
(
400
,
'INVALID_DATA'
);
}
}
units
.
getUnit
=
async
(
context
,
id
)
=>
{
let
sql_text
=
`SELECT * FROM units WHERE id=
${
id
}
`
;
units
.
getUnit
=
async
(
context
,
next
)
=>
{
let
sql_text
=
`SELECT * FROM units WHERE id=
${
context
.
params
.
id
}
`
;
try
{
let
data
=
await
db
.
con
.
query
(
sql_text
);
return
{
unit
:
data
};
context
.
response
.
body
=
{
unit
:
data
};
}
catch
(
error
){
console
.
log
(
error
);
context
.
throw
(
400
,
'INVALID_DATA'
);
...
...
@@ -28,12 +27,13 @@ units.getUnit = async (context, id) =>{
}
units
.
insertUnit
=
async
(
context
,
body
)
=>
{
units
.
insertUnit
=
async
(
context
,
next
)
=>
{
let
body
=
context
.
request
.
body
;
let
column_text
=
'name, type'
;
let
value_text
=
`'
${
body
.
name
}
', '
${
body
.
type
}
'`
;
for
(
let
i
=
2
;
i
<
unit_columns
.
length
;
i
++
)
{
const
element
=
unit_columns
[
i
];
if
(
body
[
element
]){
if
(
body
[
element
]
!==
undefined
){
column_text
+=
', '
+
element
;
value_text
+=
', '
+
body
[
element
];
}
...
...
@@ -42,7 +42,7 @@ units.insertUnit = async (context, body) =>{
try
{
let
data
=
await
db
.
con
.
query
(
sql_query
);
return
{
status
:
'success'
};
context
.
response
.
body
=
{
status
:
'success'
};
}
catch
(
error
){
console
.
log
(
error
);
context
.
throw
(
400
,
'INVALID_DATA'
);
...
...
@@ -50,10 +50,11 @@ units.insertUnit = async (context, body) =>{
}
units
.
modifyUnit
=
async
(
context
,
body
)
=>
{
units
.
modifyUnit
=
async
(
context
,
next
)
=>
{
let
body
=
context
.
request
.
body
;
let
set_text
=
''
;
if
(
body
.
name
&&
body
.
type
){
set_text
+=
`name = '
${
body
.
name
}
' type = '
${
body
.
type
}
'`
;
set_text
+=
`name = '
${
body
.
name
}
'
,
type = '
${
body
.
type
}
'`
;
}
else
if
(
body
.
name
){
set_text
+=
`name = '
${
body
.
name
}
'`
;
}
else
if
(
body
.
type
){
...
...
@@ -61,17 +62,19 @@ units.modifyUnit = async (context, body) => {
}
for
(
let
i
=
2
;
i
<
unit_columns
.
length
;
i
++
)
{
const
element
=
unit_columns
[
i
];
if
(
set_text
===
''
){
set_text
=
`
${
element
}
=
${
body
[
element
]}
`
;
}
else
if
(
body
[
element
]){
set_text
=
`,
${
element
}
=
${
body
[
element
]}
`
;
if
(
body
[
element
]
!==
undefined
){
if
(
set_text
===
''
){
set_text
+=
`
${
element
}
=
${
body
[
element
]}
`
;
}
else
{
set_text
+=
`,
${
element
}
=
${
body
[
element
]}
`
;
}
}
}
let
sql_query
=
`UPDATE units SET
${
set_text
}
WHERE id =
${
body
.
id
}
`
;
try
{
let
data
=
await
db
.
con
.
query
(
sql_query
);
return
{
status
:
'success'
};
context
.
response
.
body
=
{
status
:
'success'
};
}
catch
(
error
){
console
.
log
(
error
);
context
.
throw
(
400
,
'INVALID_DATA'
);
...
...
server/routes/units.js
View file @
19f69801
...
...
@@ -3,28 +3,13 @@ const Router = require('@koa/router');
const
router
=
new
Router
();
const
unitsModel
=
require
(
'../models/units'
);
router
.
get
(
'/unit/all'
,
async
(
context
,
next
)
=>
{
let
data
=
await
unitsModel
.
getAll
(
context
);
context
.
response
.
body
=
data
;
router
.
get
(
'/unit/all'
,
unitsModel
.
getAll
);
});
router
.
get
(
'/unit/:id'
,
async
(
context
,
next
)
=>
{
let
data
=
await
unitsModel
.
getUnit
(
context
,
context
.
params
.
id
);
context
.
response
.
body
=
data
;
router
.
get
(
'/unit/:id'
,
unitsModel
.
getUnit
);
}
);
router
.
post
(
'/unit/insert'
,
unitsModel
.
insertUnit
);
router
.
post
(
'/unit/insert'
,
async
(
context
,
next
)
=>
{
let
data
=
await
unitsModel
.
insertUnit
(
context
,
context
.
request
.
body
);
context
.
response
.
body
=
data
;
});
router
.
post
(
'/unit/modify'
,
async
(
context
,
next
)
=>
{
let
data
=
await
unitsModel
.
modifyUnit
(
context
,
context
.
request
.
body
);
context
.
response
.
body
=
data
;
});
router
.
post
(
'/unit/modify'
,
unitsModel
.
modifyUnit
);
module
.
exports
=
router
;
\ No newline at end of file
server/routes/users.js
View file @
19f69801
...
...
@@ -4,6 +4,8 @@ const Router = require('@koa/router');
const
router
=
new
Router
();
const
usersModel
=
require
(
'../models/users'
);
router
.
get
(
'/user/:id'
,
(
context
,
next
)
=>
{
})
module
.
exports
=
router
;
\ 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