users.js 1.29 KB
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;