create-sip 0.14.0 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,7 +3,7 @@ import Thing from '../models/thing.js'
|
|
|
3
3
|
const ThingController = {
|
|
4
4
|
async index(req, res) {
|
|
5
5
|
try {
|
|
6
|
-
ThingController.tryIndex(req, res)
|
|
6
|
+
await ThingController.tryIndex(req, res)
|
|
7
7
|
}catch(error) {
|
|
8
8
|
res.status(500)
|
|
9
9
|
res.json({
|
|
@@ -22,7 +22,7 @@ const ThingController = {
|
|
|
22
22
|
},
|
|
23
23
|
async show(req, res) {
|
|
24
24
|
try {
|
|
25
|
-
ThingController.tryShow(req, res)
|
|
25
|
+
await ThingController.tryShow(req, res)
|
|
26
26
|
}catch(error) {
|
|
27
27
|
res.status(500)
|
|
28
28
|
res.json({
|
|
@@ -41,7 +41,7 @@ const ThingController = {
|
|
|
41
41
|
},
|
|
42
42
|
async create(req, res) {
|
|
43
43
|
try {
|
|
44
|
-
ThingController.tryCreate(req, res)
|
|
44
|
+
await ThingController.tryCreate(req, res)
|
|
45
45
|
}catch(error) {
|
|
46
46
|
res.status(500)
|
|
47
47
|
res.json({
|
|
@@ -60,19 +60,31 @@ const ThingController = {
|
|
|
60
60
|
},
|
|
61
61
|
async update(req, res) {
|
|
62
62
|
try {
|
|
63
|
-
ThingController.tryUpdate(req, res)
|
|
63
|
+
await ThingController.tryUpdate(req, res)
|
|
64
64
|
}catch(error) {
|
|
65
|
-
|
|
65
|
+
let actualMessage = '';
|
|
66
|
+
if(error.message == 'Fail! Record not found!') {
|
|
67
|
+
actualMessage = error.message
|
|
68
|
+
res.status(404)
|
|
69
|
+
}else {
|
|
70
|
+
res.status(500)
|
|
71
|
+
actualMessage = 'Fail! The query is failed!'
|
|
72
|
+
}
|
|
73
|
+
|
|
66
74
|
res.json({
|
|
67
75
|
success: false,
|
|
68
|
-
message:
|
|
76
|
+
message: actualMessage
|
|
69
77
|
})
|
|
70
78
|
}
|
|
71
79
|
},
|
|
72
80
|
async tryUpdate(req, res) {
|
|
73
|
-
const
|
|
81
|
+
const recordNumber = await Thing.update(req.body, {
|
|
74
82
|
where: { id: req.params.id }
|
|
75
83
|
})
|
|
84
|
+
if(recordNumber == 0) {
|
|
85
|
+
throw new Error('Fail! Record not found!')
|
|
86
|
+
}
|
|
87
|
+
const thing = await Thing.findByPk(req.params.id)
|
|
76
88
|
res.status(200)
|
|
77
89
|
res.json({
|
|
78
90
|
success: true,
|
|
@@ -81,7 +93,7 @@ const ThingController = {
|
|
|
81
93
|
},
|
|
82
94
|
async destroy(req, res) {
|
|
83
95
|
try {
|
|
84
|
-
ThingController.tryDestroy(req, res)
|
|
96
|
+
await ThingController.tryDestroy(req, res)
|
|
85
97
|
}catch(error) {
|
|
86
98
|
res.status(500)
|
|
87
99
|
res.json({
|
package/manager.js
CHANGED
|
@@ -63,13 +63,18 @@ const genMockApi = (target) => {
|
|
|
63
63
|
const genExpressApi = (target) => {
|
|
64
64
|
copyDir(`${dir}/expressapi`, target);
|
|
65
65
|
updatePackageName(`${target}/package.json`, target);
|
|
66
|
-
console.log('ExpressJS REST API
|
|
66
|
+
console.log('ExpressJS REST API skeleton created');
|
|
67
67
|
console.log('Read docs/user_doc.md');
|
|
68
68
|
console.log('Run next commands:');
|
|
69
69
|
console.log(` cd ${target}`);
|
|
70
70
|
console.log(' npm install');
|
|
71
71
|
console.log(' node op key:generate');
|
|
72
72
|
console.log(' npm run dev');
|
|
73
|
+
console.log('Usable commands:');
|
|
74
|
+
console.log(' node op create model thing');
|
|
75
|
+
console.log(' node op create controller thing');
|
|
76
|
+
console.log('The model and controller names must be');
|
|
77
|
+
console.log('given in the singular');
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
module.exports = {
|