create-sip 1.5.0 → 1.5.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.
|
@@ -1,12 +1,10 @@
|
|
|
1
|
+
// import sequelize from '../database/database.js'
|
|
1
2
|
import User from './user.js';
|
|
2
|
-
import sequelize from '../database/database.js'
|
|
3
3
|
|
|
4
4
|
const db = {};
|
|
5
5
|
|
|
6
6
|
db.User = User;
|
|
7
7
|
|
|
8
|
-
await sequelize.sync({
|
|
9
|
-
alter: true
|
|
10
|
-
})
|
|
8
|
+
// await sequelize.sync({ alter: true })
|
|
11
9
|
|
|
12
10
|
export default db;
|
package/package.json
CHANGED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import Thing from '../models/thing.js'
|
|
2
|
-
|
|
3
|
-
const ThingController = {
|
|
4
|
-
async index(req, res) {
|
|
5
|
-
try {
|
|
6
|
-
await ThingController.tryIndex(req, res)
|
|
7
|
-
}catch(error) {
|
|
8
|
-
res.status(500)
|
|
9
|
-
res.json({
|
|
10
|
-
success: false,
|
|
11
|
-
message: 'Error! The query is failed!',
|
|
12
|
-
error: error.message
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
async tryIndex(req, res) {
|
|
17
|
-
const things = await Thing.findAll()
|
|
18
|
-
res.status(200)
|
|
19
|
-
res.json({
|
|
20
|
-
success: true,
|
|
21
|
-
data: things
|
|
22
|
-
})
|
|
23
|
-
},
|
|
24
|
-
async show(req, res) {
|
|
25
|
-
try {
|
|
26
|
-
await ThingController.tryShow(req, res)
|
|
27
|
-
}catch(error) {
|
|
28
|
-
res.status(500)
|
|
29
|
-
res.json({
|
|
30
|
-
success: false,
|
|
31
|
-
message: 'Error! The query is failed!',
|
|
32
|
-
error: error.message
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
async tryShow(req, res) {
|
|
37
|
-
const thing = await Thing.findByPk(req.params.id)
|
|
38
|
-
res.status(200)
|
|
39
|
-
res.json({
|
|
40
|
-
success: true,
|
|
41
|
-
data: thing
|
|
42
|
-
})
|
|
43
|
-
},
|
|
44
|
-
async store(req, res) {
|
|
45
|
-
try {
|
|
46
|
-
await ThingController.tryStore(req, res)
|
|
47
|
-
}catch(error) {
|
|
48
|
-
res.status(500)
|
|
49
|
-
res.json({
|
|
50
|
-
success: false,
|
|
51
|
-
message: 'Error! The query is failed!',
|
|
52
|
-
error: error.message
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
async tryStore(req, res) {
|
|
57
|
-
if(req.body.id) {
|
|
58
|
-
delete req.body.id
|
|
59
|
-
}
|
|
60
|
-
const thing = await Thing.create(req.body)
|
|
61
|
-
res.status(201)
|
|
62
|
-
res.json({
|
|
63
|
-
success: true,
|
|
64
|
-
data: thing
|
|
65
|
-
})
|
|
66
|
-
},
|
|
67
|
-
async update(req, res) {
|
|
68
|
-
try {
|
|
69
|
-
await ThingController.tryUpdate(req, res)
|
|
70
|
-
}catch(error) {
|
|
71
|
-
let actualMessage = '';
|
|
72
|
-
if(error.message == 'Fail! Record not found!') {
|
|
73
|
-
actualMessage = error.message
|
|
74
|
-
res.status(404)
|
|
75
|
-
}else {
|
|
76
|
-
res.status(500)
|
|
77
|
-
actualMessage = 'Fail! The query is failed!'
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
res.json({
|
|
81
|
-
success: false,
|
|
82
|
-
message: actualMessage
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
async tryUpdate(req, res) {
|
|
87
|
-
if(req.body.id) {
|
|
88
|
-
delete req.body.id
|
|
89
|
-
}
|
|
90
|
-
const recordNumber = await Thing.update(req.body, {
|
|
91
|
-
where: { id: req.params.id }
|
|
92
|
-
})
|
|
93
|
-
if(recordNumber == 0) {
|
|
94
|
-
throw new Error('Fail! Record not found!')
|
|
95
|
-
}
|
|
96
|
-
const thing = await Thing.findByPk(req.params.id)
|
|
97
|
-
res.status(200)
|
|
98
|
-
res.json({
|
|
99
|
-
success: true,
|
|
100
|
-
data: thing
|
|
101
|
-
})
|
|
102
|
-
},
|
|
103
|
-
async destroy(req, res) {
|
|
104
|
-
try {
|
|
105
|
-
await ThingController.tryDestroy(req, res)
|
|
106
|
-
}catch(error) {
|
|
107
|
-
res.status(500)
|
|
108
|
-
res.json({
|
|
109
|
-
success: false,
|
|
110
|
-
message: 'Error! The query is failed!',
|
|
111
|
-
error: error.message
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
async tryDestroy(req, res) {
|
|
116
|
-
const thing = await Thing.destroy({
|
|
117
|
-
where: { id: req.params.id }
|
|
118
|
-
})
|
|
119
|
-
res.status(200)
|
|
120
|
-
res.json({
|
|
121
|
-
success: true,
|
|
122
|
-
data: thing
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export default ThingController
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { DataTypes } from 'sequelize';
|
|
2
|
-
|
|
3
|
-
async function up({context: QueryInterface}) {
|
|
4
|
-
await QueryInterface.createTable('things', {
|
|
5
|
-
id: {
|
|
6
|
-
allowNull: false,
|
|
7
|
-
autoIncrement: true,
|
|
8
|
-
primaryKey: true,
|
|
9
|
-
type: DataTypes.INTEGER
|
|
10
|
-
},
|
|
11
|
-
name: {
|
|
12
|
-
type: DataTypes.STRING
|
|
13
|
-
},
|
|
14
|
-
createdAt: { type: DataTypes.DATE },
|
|
15
|
-
updatedAt: { type: DataTypes.DATE }
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async function down({context: QueryInterface}) {
|
|
20
|
-
await QueryInterface.dropTable('things');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { up, down }
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import db from '../../app/models/modrels.js';
|
|
2
|
-
|
|
3
|
-
async function up({context: QueryInterface}) {
|
|
4
|
-
if(db.Employee) {
|
|
5
|
-
await db.Employee.bulkCreate([
|
|
6
|
-
|
|
7
|
-
]);
|
|
8
|
-
}else {
|
|
9
|
-
const now = new Date()
|
|
10
|
-
await QueryInterface.bulkInsert('things', [
|
|
11
|
-
|
|
12
|
-
]);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async function down({context: QueryInterface}) {
|
|
17
|
-
await QueryInterface.bulkDelete('things', null, {});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { up, down }
|