@kipicore/dbcore 1.1.299 → 1.1.301

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.
@@ -13,6 +13,7 @@ module.exports = {
13
13
  const newModules = [];
14
14
  const newFeatures = [];
15
15
  const newActions = [];
16
+ const makeKey = (code, app_type) => `${code}_${app_type}`; //
16
17
  const allModulesListCode = {
17
18
  modules: new Set(),
18
19
  features: new Set(),
@@ -23,11 +24,12 @@ module.exports = {
23
24
  console.error(`Invalid module detected:`, module.name);
24
25
  continue;
25
26
  }
26
- allModulesListCode.modules.add(module.code);
27
+ // allModulesListCode.modules.add(module.code);
27
28
  const moduleAppTypes = module.appType && Array.isArray(module.appType) ? module.appType : [null];
28
29
  for (const appType of moduleAppTypes) {
29
30
  // const moduleUniqueKey = `${module.code}-${appType}`;
30
31
  let moduleId = existingModules.find(m => m.code === module.code && m.app_type === appType)?.id;
32
+ allModulesListCode.modules.add(makeKey(module.code, appType)); //
31
33
  if (!moduleId) {
32
34
  const newModule = {
33
35
  id: uuidv4(),
@@ -49,10 +51,11 @@ module.exports = {
49
51
  console.error(`Invalid feature detected in module ${module.name}:`, feature.name);
50
52
  continue;
51
53
  }
52
- allModulesListCode.features.add(feature.code);
54
+ // allModulesListCode.features.add(feature.code);
53
55
  const featureAppTypes = feature.appType && Array.isArray(feature.appType) ? feature.appType : [appType];
54
56
  for (const fAppType of featureAppTypes) {
55
57
  const featureId = existingFeatures.find(f => f.code === feature.code && f.module_id === moduleId && f.app_type === fAppType)?.id;
58
+ allModulesListCode.features.add(makeKey(feature.code, appType)); //
56
59
  let currentFeatureId = featureId;
57
60
  if (!featureId) {
58
61
  const newFeature = {
@@ -76,10 +79,11 @@ module.exports = {
76
79
  console.error(`Invalid action in feature ${feature.name}:`, action);
77
80
  continue;
78
81
  }
79
- allModulesListCode.actions.add(action.code);
82
+ // allModulesListCode.actions.add(action.code);
80
83
  const actionAppTypes = action.appType && Array.isArray(action.appType) ? action.appType : [fAppType];
81
84
  for (const aAppType of actionAppTypes) {
82
85
  const alreadyExists = existingActions.some(a => a.code === action.code && a.feature_id === currentFeatureId && a.app_type === aAppType);
86
+ allModulesListCode.actions.add(makeKey(action.code, appType)); //
83
87
  if (!alreadyExists) {
84
88
  const newAction = {
85
89
  id: uuidv4(),
@@ -104,26 +108,56 @@ module.exports = {
104
108
  if (newActions.length > 0) {
105
109
  await queryInterface.bulkInsert('feature_actions', newActions, { transaction });
106
110
  }
107
- const modulesToDelete = existingModules.filter(m => !allModulesListCode.modules.has(m.code)).map(m => m.code);
108
- const featuresToDelete = existingFeatures.filter(f => !allModulesListCode.features.has(f.code)).map(f => f.code);
109
- const actionsToDelete = existingActions.filter(a => !allModulesListCode.actions.has(a.code)).map(a => a.code);
110
- if (actionsToDelete.length) {
111
- await queryInterface.sequelize.query(`DELETE FROM feature_actions WHERE code IN (:codes)`, {
112
- replacements: { codes: actionsToDelete },
113
- transaction,
114
- });
111
+ const modulesToDelete = existingModules.filter(m => !allModulesListCode.modules.has(makeKey(m.code, m.app_type)));
112
+ const featuresToDelete = existingFeatures.filter(f => !allModulesListCode.features.has(makeKey(f.code, f.app_type)));
113
+ const actionsToDelete = existingActions.filter(a => !allModulesListCode.actions.has(makeKey(a.code, a.app_type)));
114
+ // const modulesToDelete = existingModules.filter(m => !allModulesListCode.modules.has(m.code)).map(m => m.code);
115
+ // const featuresToDelete = existingFeatures.filter(f => !allModulesListCode.features.has(f.code)).map(f => f.code);
116
+ // const actionsToDelete = existingActions.filter(a => !allModulesListCode.actions.has(a.code)).map(a => a.code);
117
+ // if (actionsToDelete.length) {
118
+ // await queryInterface.sequelize.query(`DELETE FROM feature_actions WHERE code IN (:codes)`, {
119
+ // replacements: { codes: actionsToDelete },
120
+ // transaction,
121
+ // });
122
+ // }
123
+ // if (featuresToDelete.length) {
124
+ // await queryInterface.sequelize.query(`DELETE FROM module_features WHERE code IN (:codes)`, {
125
+ // replacements: { codes: featuresToDelete },
126
+ // transaction,
127
+ // });
128
+ // }
129
+ // if (modulesToDelete.length) {
130
+ // await queryInterface.sequelize.query(`DELETE FROM modules WHERE code IN (:codes)`, {
131
+ // replacements: { codes: modulesToDelete },
132
+ // transaction,
133
+ // });
134
+ // }
135
+ if (modulesToDelete.length) {
136
+ const conditions = modulesToDelete.map((_, i) => `(code = :code${i} AND "app_type" = :appType${i})`).join(' OR ');
137
+ const replacements = modulesToDelete.reduce((acc, item, i) => {
138
+ acc[`code${i}`] = item.code;
139
+ acc[`appType${i}`] = item.app_type;
140
+ return acc;
141
+ }, {});
142
+ await queryInterface.sequelize.query(`DELETE FROM modules WHERE ${conditions}`, { replacements, transaction });
115
143
  }
116
144
  if (featuresToDelete.length) {
117
- await queryInterface.sequelize.query(`DELETE FROM module_features WHERE code IN (:codes)`, {
118
- replacements: { codes: featuresToDelete },
119
- transaction,
120
- });
145
+ const conditions = featuresToDelete.map((_, i) => `(code = :code${i} AND "app_type" = :appType${i})`).join(' OR ');
146
+ const replacements = featuresToDelete.reduce((acc, item, i) => {
147
+ acc[`code${i}`] = item.code;
148
+ acc[`appType${i}`] = item.app_type;
149
+ return acc;
150
+ }, {});
151
+ await queryInterface.sequelize.query(`DELETE FROM module_features WHERE ${conditions}`, { replacements, transaction });
121
152
  }
122
- if (modulesToDelete.length) {
123
- await queryInterface.sequelize.query(`DELETE FROM modules WHERE code IN (:codes)`, {
124
- replacements: { codes: modulesToDelete },
125
- transaction,
126
- });
153
+ if (actionsToDelete.length) {
154
+ const conditions = actionsToDelete.map((_, i) => `(code = :code${i} AND "app_type" = :appType${i})`).join(' OR ');
155
+ const replacements = actionsToDelete.reduce((acc, item, i) => {
156
+ acc[`code${i}`] = item.code;
157
+ acc[`appType${i}`] = item.app_type;
158
+ return acc;
159
+ }, {});
160
+ await queryInterface.sequelize.query(`DELETE FROM feature_actions WHERE ${conditions}`, { replacements, transaction });
127
161
  }
128
162
  await transaction.commit();
129
163
  }
@@ -3,7 +3,7 @@ const appTypeEnum = require('./appType');
3
3
  const DashboardManagementModule = {
4
4
  name: 'Dashboard Management',
5
5
  code: 'DASHBOARD',
6
- appType: [appTypeEnum.INSTITUTE_APP, appTypeEnum.SCHOOL_APP],
6
+ appType: [appTypeEnum.SCHOOL_APP],
7
7
  features: [
8
8
  // {
9
9
  // name: 'Quick Actions',
@@ -257,24 +257,28 @@ const createOrUpdateHook = async (examGroup) => {
257
257
  // }
258
258
  }
259
259
  //*********** days array remove duplicate date from date if multiple date empty ********///
260
- examGroup.standardByDays = examGroup.standardByDays.map(standard => ({
261
- ...standard,
262
- days: standard.days.reduce((acc, day) => {
263
- const existingIndex = acc.findIndex(d => new Date(d.date).getTime() === new Date(day.date).getTime());
264
- if (Object.keys(day.examDetails || {}).length > 0) {
265
- // If an empty object exists for this date, remove it
266
- if (existingIndex !== -1 && Object.keys(acc[existingIndex].examDetails || {}).length === 0) {
267
- acc.splice(existingIndex, 1);
260
+ const dateListTimestamp = dateList.map(date => new Date(date).getTime());
261
+ examGroup.standardByDays = examGroup.standardByDays.map(standard => {
262
+ standard.days = standard.days.filter(day => dateListTimestamp.includes(new Date(day.date).getTime()));
263
+ return {
264
+ ...standard,
265
+ days: standard.days.reduce((acc, day) => {
266
+ const existingIndex = acc.findIndex(d => new Date(d.date).getTime() === new Date(day.date).getTime());
267
+ if (Object.keys(day.examDetails || {}).length > 0) {
268
+ // If an empty object exists for this date, remove it
269
+ if (existingIndex !== -1 && Object.keys(acc[existingIndex].examDetails || {}).length === 0) {
270
+ acc.splice(existingIndex, 1);
271
+ }
272
+ acc.push(day);
268
273
  }
269
- acc.push(day);
270
- }
271
- else if (existingIndex === -1) {
272
- // Push empty examDetails object only if there's no existing entry
273
- acc.push(day);
274
- }
275
- return acc;
276
- }, []),
277
- }));
274
+ else if (existingIndex === -1) {
275
+ // Push empty examDetails object only if there's no existing entry
276
+ acc.push(day);
277
+ }
278
+ return acc;
279
+ }, []),
280
+ };
281
+ });
278
282
  }
279
283
  }
280
284
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kipicore/dbcore",
3
- "version": "1.1.299",
3
+ "version": "1.1.301",
4
4
  "description": "Reusable DB core package with Postgres, MongoDB, models, services, interfaces, and types",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",