@kipicore/dbcore 1.1.298 → 1.1.300

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',
@@ -26,6 +26,7 @@ export interface IUserInstituteMetaAttributes extends IDefaultAttributes, Docume
26
26
  additionalField?: object;
27
27
  userId: string;
28
28
  instituteId?: string;
29
+ isInquiryStudent?: boolean;
29
30
  userType: USER_TYPES;
30
31
  status?: USER_INSTITUTE_META_STATUS;
31
32
  endTime?: Date;
@@ -159,6 +159,10 @@ const userInstituteMetaSchema = new mongoose_1.Schema({
159
159
  enum: Object.values(app_1.BOOLEAN_STATUS),
160
160
  default: app_1.BOOLEAN_STATUS.NO,
161
161
  },
162
+ isInquiryStudent: {
163
+ type: Boolean,
164
+ default: false,
165
+ },
162
166
  startTime: {
163
167
  type: Date,
164
168
  required: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kipicore/dbcore",
3
- "version": "1.1.298",
3
+ "version": "1.1.300",
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",