identity-admin 1.28.16 → 1.28.17

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.
@@ -41,4 +41,5 @@ export default class DashboardController {
41
41
  deleteAll(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
42
42
  delete(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
43
43
  getNeighbors(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
44
+ import(req: any, res: Response): Promise<void>;
44
45
  }
@@ -43,6 +43,10 @@ const UserActionsLog_1 = __importDefault(require("../models/userActionsLog/UserA
43
43
  const PermissionResource_1 = require("../helpers/Permissions/PermissionResource");
44
44
  const RecordsCounter_1 = require("../helpers/RecordsCounter");
45
45
  const FilterQueryHelper_1 = require("../helpers/FilterQueryHelper");
46
+ const multer = require('multer');
47
+ const upload = multer({ dest: 'uploads/' });
48
+ var fs = require('fs');
49
+ const xlsx = require('node-xlsx');
46
50
  let DashboardController = DashboardController_1 = class DashboardController {
47
51
  constructor(resource, repository, resources, modelConfigurations) {
48
52
  this.resource = resource;
@@ -730,6 +734,37 @@ let DashboardController = DashboardController_1 = class DashboardController {
730
734
  });
731
735
  });
732
736
  }
737
+ import(req, res) {
738
+ var _a, _b;
739
+ return __awaiter(this, void 0, void 0, function* () {
740
+ if (!this.validateRequest(req, res)) {
741
+ return;
742
+ }
743
+ const filePath = req.file.path;
744
+ const modelName = req.params.resource;
745
+ const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
746
+ const currentUser = req.user;
747
+ if (!resource) {
748
+ return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
749
+ }
750
+ if (!currentUser) {
751
+ return ResponseUtils_1.default.unauthorized(res);
752
+ }
753
+ var data = [];
754
+ const sheets = xlsx.parse(fs.readFileSync(filePath));
755
+ if (!sheets.length)
756
+ data = [];
757
+ else
758
+ data = sheets[0].data || [];
759
+ if (resource && resource.properties.afterImport) {
760
+ yield resource.properties.afterImport(req, currentUser, data);
761
+ }
762
+ fs.rmSync(req.file.path, {
763
+ force: true,
764
+ });
765
+ return ResponseUtils_1.default.created(res, {});
766
+ });
767
+ }
733
768
  };
734
769
  DashboardController.DEFAULT_PAGE = 1;
735
770
  DashboardController.DEFAULT_PER_PAGE = 30;
@@ -777,6 +812,11 @@ __decorate([
777
812
  __param(0, (0, inversify_express_utils_1.request)()),
778
813
  __param(1, (0, inversify_express_utils_1.response)())
779
814
  ], DashboardController.prototype, "getNeighbors", null);
815
+ __decorate([
816
+ (0, inversify_express_utils_1.httpPost)('/import', upload.single('file')),
817
+ __param(0, (0, inversify_express_utils_1.request)()),
818
+ __param(1, (0, inversify_express_utils_1.response)())
819
+ ], DashboardController.prototype, "import", null);
780
820
  DashboardController = DashboardController_1 = __decorate([
781
821
  (0, inversify_1.injectable)(),
782
822
  __param(0, (0, inversify_1.unmanaged)()),
@@ -41,13 +41,13 @@ interface Action {
41
41
  /**
42
42
  * Specify if this action is accessible or not.
43
43
  * @default True for show, edit, delete, and new.
44
- * @default false for bulk delete.
45
- * You can ovveride any of these values here.
44
+ * @default false for bulk delete and import.
45
+ * You can override any of these values here.
46
46
  */
47
47
  isAccessible?: boolean;
48
48
  /**
49
49
  * Specify if the page requires to be reloaded after executing the action
50
- * @default Fale for show, edit, delete, and new.
50
+ * @default False for show, edit, delete, and new.
51
51
  */
52
52
  reloadAfterAction?: boolean;
53
53
  /**
@@ -695,6 +695,11 @@ export interface IResourceFile {
695
695
  subject: string;
696
696
  html: string;
697
697
  }) => Promise<void>;
698
+ /**
699
+ * The function called after importing the data from the imported file
700
+ * @default undefined
701
+ */
702
+ afterImport?: (req: IRequest, currentUser: Document, data: string[][]) => Promise<any>;
698
703
  };
699
704
  /**
700
705
  * Array of properties that should be appeared in the list action.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identity-admin",
3
- "version": "1.28.16",
3
+ "version": "1.28.17",
4
4
  "description": "",
5
5
  "main": "lib/Dashboard.js",
6
6
  "types": "lib/Dashbord.d.ts",
@@ -52,6 +52,7 @@
52
52
  "express-session": "^1.17.3",
53
53
  "lodash": "^4.17.21",
54
54
  "memory-cache": "^0.2.0",
55
+ "multer": "^2.0.2",
55
56
  "node-xlsx": "^0.21.0",
56
57
  "passport": "^0.6.0",
57
58
  "passport-local": "^1.0.0",