-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.ts
108 lines (105 loc) · 2.69 KB
/
api.ts
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import {NextFunction, Request, Response} from "express";
var express = require('express');
var router = express.Router();
var models = require("../models");
/* GET users listing. */
router.get('/', function(req: Request, res: Response, next: NextFunction) {
res.send('respond with a resource-1234');
});
/********************************
*
*********************************/
router.get('/tasks_index', function(req: Request, res: Response, next: NextFunction ) {
models.Task.findAll({
order: [
['id', 'DESC'],
],
}).then((result:any) => {
var items = result
items.forEach( function (item: any[]) {
// console.log( item);
});
var param = {"result": result};
res.json(param);
});
});
/********************************
*
*********************************/
router.post('/tasks_new', (req: Request, res: Response) => {
var obj = req.body;
console.log(obj );
models.Task.create({
title: obj.title,
content: obj.content,
})
.then((result:any) => {
res.json(req.body);
});
});
/********************************
*
*********************************/
router.get('/tasks_show/:id', function(req: Request, res: Response) {
console.log( req.params.id );
models.Task.findOne({
where: {
id: req.params.id,
}
})
.then((result: any) => {
var param = {"result": result};
res.json(param);
});
});
/********************************
*
*********************************/
router.post('/tasks_update', (req: Request, res: Response) => {
var obj = req.body;
models.Task.update({
title: obj.title,
content: obj.content,
}, {
where: {
id: req.body.id
},
fields: [
"title",
"content"
]
}).then(() => {
res.json(req.body);
});
});
/********************************
*
*********************************/
router.get('/tasks_delete/:id', function(req: Request, res: Response) {
models.Task.destroy({
where: {
id: req.params.id
}
})
.then(() => {
res.json( req.params.id);
});
});
/********************************
*
*********************************/
router.get('/test1', function(req: Request, res: Response, next: NextFunction ) {
models.User.findAll({
order: [
['id', 'DESC'],
],
}).then((result:any) => {
var items = result
items.forEach( function (item: any[]) {
console.log( item);
});
var param = {"result": result};
res.json(param);
});
});
export {router as apiRouter}