agrs-sequelize-sdk 1.0.8 → 1.0.10
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/models/Folders.js +18 -0
- package/package.json +1 -1
package/models/Folders.js
CHANGED
|
@@ -35,6 +35,8 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
35
35
|
// Function to count files and subfolders for each parent folder in ParentFolders array
|
|
36
36
|
Folders.countFilesAndSubfolders = async function (parentFolderIds) {
|
|
37
37
|
try {
|
|
38
|
+
const { Files } = sequelize.models; // Move the reference inside the function
|
|
39
|
+
|
|
38
40
|
// Loop through each parent folder ID
|
|
39
41
|
for (const parentFolderId of parentFolderIds) {
|
|
40
42
|
// Find the parent folder by ID
|
|
@@ -111,5 +113,21 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
111
113
|
}
|
|
112
114
|
});
|
|
113
115
|
|
|
116
|
+
// Add a hook before saving the folder to check ParentFolders
|
|
117
|
+
Folders.addHook('beforeSave', (folder, options) => {
|
|
118
|
+
// If ParentFolders is an empty array or contains only nulls, set it to null
|
|
119
|
+
if (folder.ParentFolders && (folder.ParentFolders.length === 0 || folder.ParentFolders.every(f => f === null))) {
|
|
120
|
+
folder.ParentFolders = null;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// You can also add this hook for files
|
|
125
|
+
sequelize.models.Files.addHook('beforeSave', (file, options) => {
|
|
126
|
+
// If ParentFolders is an empty array or contains only nulls, set it to null
|
|
127
|
+
if (file.ParentFolders && (file.ParentFolders.length === 0 || file.ParentFolders.every(f => f === null))) {
|
|
128
|
+
file.ParentFolders = null;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
114
132
|
return Folders;
|
|
115
133
|
};
|