Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
5
59110440259
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
senior-prj-62
59110440259
Commits
3e455993
Commit
3e455993
authored
Feb 06, 2020
by
Piyaphorn Arphornsri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add db
parent
3783f660
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
6 deletions
+72
-6
index.js
Backend/controllers/list/index.js
+62
-2
index.js
Backend/controllers/shop/index.js
+1
-1
index.js
Backend/routers/list/index.js
+8
-2
server.js
Backend/server.js
+1
-1
No files found.
Backend/controllers/list/index.js
View file @
3e455993
...
...
@@ -4,10 +4,70 @@ const config = require("../../config");
createToken
=
id
=>
{
return
JWT
.
sign
({
id
},
config
.
JWT_SECRET
);
};
exports
.
list
=
async
(
req
,
res
)
=>
{
exports
.
addlist
=
async
(
req
,
res
)
=>
{
try
{
const
addlistData
=
req
.
body
;
await
List
.
create
({
name
:
addlistData
.
name
,
price
:
addlistData
.
price
,
time
:
addlistData
.
time
,
shop
:
addlistData
.
shop
});
res
.
send
(
"create"
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
sendStatus
(
401
);
}
};
exports
.
getList
=
async
(
req
,
res
)
=>
{
try
{
let
list
=
await
List
.
findAll
();
res
.
status
(
200
).
send
(
list
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
sendStatus
(
401
);
}
};
exports
.
deletelist
=
async
(
req
,
res
)
=>
{
try
{
const
listId
=
req
.
params
.
listId
;
let
list
=
await
List
.
findOne
({
where
:
{
id
:
listId
}
});
res
.
status
(
200
).
send
(
list
.
dataValues
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
sendStatus
(
401
);
}
};
exports
.
getListId
=
async
(
req
,
res
)
=>
{
try
{
const
listId
=
req
.
params
.
id
;
let
list
=
await
List
.
findOne
({
where
:
{
id
:
listId
}
});
res
.
status
(
200
).
send
(
list
.
dataValues
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
sendStatus
(
401
);
}
};
exports
.
updateList
=
async
(
req
,
res
)
=>
{
try
{
const
listData
=
req
.
body
;
List
.
create
(
listData
);
const
id
=
req
.
params
.
id
;
await
List
.
update
(
listData
,
{
where
:
{
id
:
id
}
});
res
.
status
(
200
).
send
({
status
:
"done"
});
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
sendStatus
(
401
);
...
...
Backend/controllers/shop/index.js
View file @
3e455993
...
...
@@ -5,7 +5,7 @@ createToken = id => {
return
JWT
.
sign
({
id
},
config
.
JWT_SECRET
);
};
exports
.
Shop
=
async
(
req
,
res
)
=>
{
exports
.
add
Shop
=
async
(
req
,
res
)
=>
{
try
{
const
shopData
=
req
.
body
;
Shop
.
create
(
shopData
);
...
...
Backend/routers/list/index.js
View file @
3e455993
const
express
=
require
(
"express"
);
const
router
=
express
.
Router
();
const
authController
=
require
(
"../../controllers/list"
);
const
listController
=
require
(
"../../controllers/list"
);
router
.
post
(
"/add"
,
listController
.
addlist
);
router
.
get
(
'/all'
,
listController
.
getList
);
router
.
delete
(
'/delete/:listId'
,
listController
.
deletelist
);
router
.
get
(
'/getListId/:id'
,
listController
.
getListId
);
router
.
put
(
'/updateList/id'
,
listController
.
updateList
);
router
.
post
(
"/list"
,
authController
.
list
);
module
.
exports
=
router
;
Backend/server.js
View file @
3e455993
...
...
@@ -11,7 +11,7 @@ app.use(bodyParser.json());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}))
app
.
use
(
'/api/auth'
,
router
.
auth
);
app
.
use
(
'/api/list'
,
router
.
list
);
app
.
use
(
'/api/shop'
,
router
.
shop
);
//
app.use('/api/shop', router.shop);
app
.
listen
(
port
,
()
=>
{
console
.
log
(
'Express server listening on port '
+
port
)
...
...
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