tikzs.js 1.71 KB
var express = require('express');
var router = express.Router();
var models = require('../models');
const { text } = require('express');
/* GET users listing. */
const { Op } = require("sequelize");

router.post('/',async function(req, res, next) {
  const {user, pageSize, currentPage,orderWhat,orderKind} = req.body;
  const offset = pageSize*(currentPage-1);
  const limit=pageSize;
console.log(pageSize,currentPage,orderWhat,orderKind);
  const result = await models.Tikz.findAndCountAll({where:{creator:user}, order:[[orderWhat,orderKind]], limit , offset}); 
  if(result){
    const total=result.count;
    const values= result.rows.map(x => x.get({plain:true}))
    res.status(200).json({tikzs:values,total});
  }
});
//  const result = await models.Tikz.findAndCountAll({where:{creator:user}, order:[['qno','desc']], limit , offset}); 
router.get('/removeItem', async function(req,res,next){
  const {id} =req.query;
  
  if(id ==null){
    return res.status(500).json({message:"id를 확인해 주세요."});
  }try{
  const result = await models.Tikz.destroy({where:{id}});
  if(result){
    res.status(200).json({message:"삭제되었습니다."});
  }
}catch(e){
  console.log(e);
  res.status(500).json({message:"알 수 없는 오류입니다."})
}
});

router.post('/removeItems', async function(req,res,next){
  const {ids} =req.body;
  
  if(ids ==null){
    return res.status(500).json({message:"ids를 확인해 주세요."});
  }
  console.log(ids);
  try{
  const result = await models.Tikz.destroy({where:{ id:[...ids]}});
  if(result){
    res.status(200).json({message:"삭제되었습니다."});
  }
}catch(e){
  console.log(e);
  res.status(500).json({message:"알 수 없는 오류입니다."})
}
});


module.exports = router;