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
d94ba383
Commit
d94ba383
authored
Feb 07, 2020
by
Piyaphorn Arphornsri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add db
parent
3e455993
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
25 deletions
+75
-25
index.js
Backend/controllers/list/index.js
+4
-8
index.js
Backend/controllers/shop/index.js
+57
-8
index.js
Backend/models/shop/index.js
+6
-6
index.js
Backend/routers/shop/index.js
+7
-2
server.js
Backend/server.js
+1
-1
No files found.
Backend/controllers/list/index.js
View file @
d94ba383
const
List
=
require
(
"../../models/list"
);
const
config
=
require
(
"../../config"
);
createToken
=
id
=>
{
return
JWT
.
sign
({
id
},
config
.
JWT_SECRET
);
};
exports
.
addlist
=
async
(
req
,
res
)
=>
{
try
{
const
addlistData
=
req
.
body
;
...
...
@@ -25,7 +21,7 @@ exports.getList = async (req, res) => {
try
{
let
list
=
await
List
.
findAll
();
res
.
status
(
200
).
send
(
list
);
res
.
status
(
200
).
send
(
"success"
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
sendStatus
(
401
);
...
...
@@ -35,12 +31,12 @@ exports.getList = async (req, res) => {
exports
.
deletelist
=
async
(
req
,
res
)
=>
{
try
{
const
listId
=
req
.
params
.
listId
;
let
list
=
await
List
.
findOne
({
await
List
.
destroy
({
where
:
{
id
:
listId
}
});
res
.
status
(
200
).
send
(
list
.
dataValues
);
res
.
status
(
200
).
send
(
"success"
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
sendStatus
(
401
);
...
...
@@ -55,7 +51,7 @@ exports.getListId = async (req, res) => {
id
:
listId
}
});
res
.
status
(
200
).
send
(
list
.
dataValues
);
res
.
status
(
200
).
send
(
"success"
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
sendStatus
(
401
);
...
...
Backend/controllers/shop/index.js
View file @
d94ba383
const
Shop
=
require
(
"../../models/shop"
);
const
config
=
require
(
"../../config"
);
createToken
=
id
=>
{
return
JWT
.
sign
({
id
},
config
.
JWT_SECRET
);
exports
.
addShop
=
async
(
req
,
res
)
=>
{
try
{
const
addshopData
=
req
.
body
;
console
.
log
(
addshopData
);
await
Shop
.
create
(
addshopData
);
res
.
send
(
"create"
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
sendStatus
(
401
);
}
};
exports
.
addShop
=
async
(
req
,
res
)
=>
{
try
{
const
shopData
=
req
.
body
;
Shop
.
create
(
shopData
);
}
catch
(
err
){
exports
.
getShop
=
async
(
req
,
res
)
=>
{
try
{
let
shop
=
await
Shop
.
findAll
();
res
.
status
(
200
).
send
(
"success"
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
sendStatus
(
401
);
}
};
exports
.
deleteshop
=
async
(
req
,
res
)
=>
{
try
{
const
shopId
=
req
.
params
.
shopId
;
await
Shop
.
destroy
({
where
:
{
id
:
shopId
}
});
res
.
status
(
200
).
send
(
"success"
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
sendStatus
(
401
);
}
};
exports
.
getShopId
=
async
(
req
,
res
)
=>
{
try
{
const
shopId
=
req
.
params
.
id
;
let
shop
=
await
Shop
.
findOne
({
where
:
{
id
:
shopId
}
});
res
.
status
(
200
).
send
(
"success"
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
sendStatus
(
401
);
}
};
exports
.
updateShop
=
async
(
req
,
res
)
=>
{
try
{
const
shopData
=
req
.
body
;
const
id
=
req
.
params
.
id
;
await
Shop
.
update
(
shopData
,
{
where
:
{
id
:
id
}
});
res
.
status
(
200
).
send
({
status
:
"done"
});
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
sendStatus
(
401
);
}
...
...
Backend/models/shop/index.js
View file @
d94ba383
...
...
@@ -12,22 +12,22 @@ module.exports = db.sequelize.define("shops", {
type
:
Sequelize
.
INTEGER
},
timeopen
:
{
type
:
Sequelize
.
TIME
type
:
Sequelize
.
STRING
},
timeclose
:
{
type
:
Sequelize
.
TIME
type
:
Sequelize
.
STRING
},
address
:
{
type
:
Sequelize
.
STRING
type
:
Sequelize
.
TEXT
},
tel
:
{
type
:
Sequelize
.
STRING
},
det
ia
l
:
{
type
:
Sequelize
.
STRING
det
ai
l
:
{
type
:
Sequelize
.
TEXT
},
map
:
{
type
:
Sequelize
.
STRING
type
:
Sequelize
.
TEXT
},
type
:
{
type
:
Sequelize
.
ENUM
(
...
...
Backend/routers/shop/index.js
View file @
d94ba383
const
express
=
require
(
"express"
);
const
router
=
express
.
Router
();
const
authController
=
require
(
"../../controllers/shop"
);
const
shopController
=
require
(
"../../controllers/shop"
);
router
.
post
(
"/add"
,
shopController
.
addShop
);
router
.
get
(
'/all'
,
shopController
.
getShop
);
router
.
delete
(
'/delete/:shopId'
,
shopController
.
updateShop
);
router
.
get
(
'/getListId/:id'
,
shopController
.
getShopId
);
router
.
put
(
'/updateList/id'
,
shopController
.
updateShop
);
router
.
post
(
"/shop"
,
authController
.
shop
);
module
.
exports
=
router
;
Backend/server.js
View file @
d94ba383
...
...
@@ -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