users.js
1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var express = require('express');
var router = express.Router();
var models = require('../models');
const { text } = require('express');
/* GET users listing. */
router.post('/',async function(req, res, next) {
try{
const {userid, userpwd} =req.body;
const result =await models.User.findOne({where:{id:userid, pwd:userpwd}});
if(result){
const values= result.get({plain:true});
console.log(values);
res.status(200).json({data:values});
}else {
res.status(500).json({message:"Fail"});
}}catch(e){
console.log(e);
res.status(500).json({message:"Fail"});
}
});
//생성 이였으면 경로와 함께 findall을 수정해주면 된다.
router.post('/create',async function(req, res, next) {
try{
const {userid, userpwd} =req.body;
const result =await models.User.findOne({where:{id:userid, pwd:userpwd}});
if(result==null){
const values= result.get({plain:true});
//const values= result.map(x => x.get({plain:true}))
console.log(values);
res.status(200).json({data:values});
}else{
res.status(500).json({message:"Fail"});
}}catch(e){
console.log(e);
res.status(500).json({message:"Fail"});
}
});
//만약 REST api중 get으로 넘긴다면 req.query 가 되며 Url 뒤에 추가가 된다.
// ex) uers?id=200&pwd=200
module.exports = router;