@kipicore/dbcore 1.1.34 → 1.1.36
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.
- package/dist/models/psql/index.js +16 -8
- package/package.json +1 -1
|
@@ -28,20 +28,28 @@ const sequelize = new sequelize_1.Sequelize(database, username, password, {
|
|
|
28
28
|
});
|
|
29
29
|
exports.sequelize = sequelize;
|
|
30
30
|
// Load models
|
|
31
|
+
// Load all models except index.js
|
|
31
32
|
fs_1.default.readdirSync(__dirname)
|
|
32
|
-
.filter(file =>
|
|
33
|
+
.filter(file => {
|
|
34
|
+
return (file.indexOf('.') !== 0 &&
|
|
35
|
+
file !== path_1.default.basename(__filename) && // exclude index.js
|
|
36
|
+
(file.slice(-3) === '.js' || file.slice(-3) === '.ts'));
|
|
37
|
+
})
|
|
33
38
|
.forEach(file => {
|
|
34
|
-
const modelDefiner = require(path_1.default.join(__dirname, file));
|
|
35
|
-
|
|
39
|
+
const modelDefiner = require(path_1.default.join(__dirname, file)).default;
|
|
40
|
+
if (!modelDefiner)
|
|
41
|
+
return;
|
|
42
|
+
// Store model class in db with its modelName
|
|
43
|
+
db[modelDefiner.name] = modelDefiner;
|
|
36
44
|
});
|
|
37
|
-
//
|
|
45
|
+
// Attach Sequelize instance
|
|
46
|
+
db.sequelize = sequelize;
|
|
47
|
+
db.Sequelize = sequelize_1.Sequelize;
|
|
48
|
+
// Run associations
|
|
38
49
|
Object.keys(db).forEach(modelName => {
|
|
39
|
-
if (
|
|
50
|
+
if (typeof db[modelName].associate === 'function') {
|
|
40
51
|
db[modelName].associate(db);
|
|
41
52
|
}
|
|
42
|
-
if (db[modelName].addHooks && typeof db[modelName].addHooks === 'function') {
|
|
43
|
-
db[modelName].addHooks(db);
|
|
44
|
-
}
|
|
45
53
|
});
|
|
46
54
|
sequelize.addHook('beforeBulkDestroy', async (options) => {
|
|
47
55
|
const userId = options.userId; // Pass the user ID through options
|
package/package.json
CHANGED