tikzs.js
1.71 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
46
47
48
49
50
51
52
53
54
55
56
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;