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
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
28 deletions
+78
-28
index.js
Backend/controllers/list/index.js
+4
-8
index.js
Backend/controllers/shop/index.js
+60
-11
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
List
=
require
(
"../../models/list"
);
const
config
=
require
(
"../../config"
);
const
config
=
require
(
"../../config"
);
createToken
=
id
=>
{
return
JWT
.
sign
({
id
},
config
.
JWT_SECRET
);
};
exports
.
addlist
=
async
(
req
,
res
)
=>
{
exports
.
addlist
=
async
(
req
,
res
)
=>
{
try
{
try
{
const
addlistData
=
req
.
body
;
const
addlistData
=
req
.
body
;
...
@@ -25,7 +21,7 @@ exports.getList = async (req, res) => {
...
@@ -25,7 +21,7 @@ exports.getList = async (req, res) => {
try
{
try
{
let
list
=
await
List
.
findAll
();
let
list
=
await
List
.
findAll
();
res
.
status
(
200
).
send
(
list
);
res
.
status
(
200
).
send
(
"success"
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
res
.
sendStatus
(
401
);
res
.
sendStatus
(
401
);
...
@@ -35,12 +31,12 @@ exports.getList = async (req, res) => {
...
@@ -35,12 +31,12 @@ exports.getList = async (req, res) => {
exports
.
deletelist
=
async
(
req
,
res
)
=>
{
exports
.
deletelist
=
async
(
req
,
res
)
=>
{
try
{
try
{
const
listId
=
req
.
params
.
listId
;
const
listId
=
req
.
params
.
listId
;
let
list
=
await
List
.
findOne
({
await
List
.
destroy
({
where
:
{
where
:
{
id
:
listId
id
:
listId
}
}
});
});
res
.
status
(
200
).
send
(
list
.
dataValues
);
res
.
status
(
200
).
send
(
"success"
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
res
.
sendStatus
(
401
);
res
.
sendStatus
(
401
);
...
@@ -55,7 +51,7 @@ exports.getListId = async (req, res) => {
...
@@ -55,7 +51,7 @@ exports.getListId = async (req, res) => {
id
:
listId
id
:
listId
}
}
});
});
res
.
status
(
200
).
send
(
list
.
dataValues
);
res
.
status
(
200
).
send
(
"success"
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
res
.
sendStatus
(
401
);
res
.
sendStatus
(
401
);
...
...
Backend/controllers/shop/index.js
View file @
d94ba383
const
Shop
=
require
(
"../../models/shop"
);
const
Shop
=
require
(
"../../models/shop"
);
const
config
=
require
(
"../../config"
);
createToken
=
id
=>
{
exports
.
addShop
=
async
(
req
,
res
)
=>
{
return
JWT
.
sign
({
id
},
config
.
JWT_SECRET
);
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
)
=>
{
exports
.
getShop
=
async
(
req
,
res
)
=>
{
try
{
try
{
const
shopData
=
req
.
body
;
let
shop
=
await
Shop
.
findAll
();
Shop
.
create
(
shopData
);
res
.
status
(
200
).
send
(
"success"
);
}
catch
(
err
){
}
catch
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
res
.
sendStatus
(
401
);
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", {
...
@@ -12,22 +12,22 @@ module.exports = db.sequelize.define("shops", {
type
:
Sequelize
.
INTEGER
type
:
Sequelize
.
INTEGER
},
},
timeopen
:
{
timeopen
:
{
type
:
Sequelize
.
TIME
type
:
Sequelize
.
STRING
},
},
timeclose
:
{
timeclose
:
{
type
:
Sequelize
.
TIME
type
:
Sequelize
.
STRING
},
},
address
:
{
address
:
{
type
:
Sequelize
.
STRING
type
:
Sequelize
.
TEXT
},
},
tel
:
{
tel
:
{
type
:
Sequelize
.
STRING
type
:
Sequelize
.
STRING
},
},
det
ia
l
:
{
det
ai
l
:
{
type
:
Sequelize
.
STRING
type
:
Sequelize
.
TEXT
},
},
map
:
{
map
:
{
type
:
Sequelize
.
STRING
type
:
Sequelize
.
TEXT
},
},
type
:
{
type
:
{
type
:
Sequelize
.
ENUM
(
type
:
Sequelize
.
ENUM
(
...
...
Backend/routers/shop/index.js
View file @
d94ba383
const
express
=
require
(
"express"
);
const
express
=
require
(
"express"
);
const
router
=
express
.
Router
();
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
;
module
.
exports
=
router
;
Backend/server.js
View file @
d94ba383
...
@@ -11,7 +11,7 @@ app.use(bodyParser.json());
...
@@ -11,7 +11,7 @@ app.use(bodyParser.json());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}))
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}))
app
.
use
(
'/api/auth'
,
router
.
auth
);
app
.
use
(
'/api/auth'
,
router
.
auth
);
app
.
use
(
'/api/list'
,
router
.
list
);
app
.
use
(
'/api/list'
,
router
.
list
);
//
app.use('/api/shop', router.shop);
app
.
use
(
'/api/shop'
,
router
.
shop
);
app
.
listen
(
port
,
()
=>
{
app
.
listen
(
port
,
()
=>
{
console
.
log
(
'Express server listening on port '
+
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