@resolveio/server-lib 1.1.0 → 1.1.2-newrole

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.
@@ -21,13 +21,6 @@ var schema = {
21
21
  type: Date,
22
22
  optional: true
23
23
  },
24
- readonly: {
25
- type: Boolean,
26
- optional: true
27
- },
28
- active: {
29
- type: Boolean
30
- },
31
24
  attempts: {
32
25
  type: Number,
33
26
  optional: true
@@ -64,60 +57,73 @@ var schema = {
64
57
  type: String
65
58
  },
66
59
  roles: {
60
+ type: Object
61
+ },
62
+ 'roles.super_admin': {
63
+ type: Boolean
64
+ },
65
+ 'roles.approvals': {
67
66
  type: Array
68
67
  },
69
- 'roles.$': {
68
+ 'roles.approvals.$': {
69
+ type: Object
70
+ },
71
+ 'roles.approvals.$.name': {
70
72
  type: String
71
73
  },
72
- phonenumber: {
73
- type: String,
74
- optional: true
74
+ 'roles.approvals.$.type': {
75
+ type: String
75
76
  },
76
- other: {
77
- type: Object,
78
- blackbox: true,
79
- optional: true
77
+ 'roles.approvals.$.accounting_code': {
78
+ type: String
80
79
  },
81
- assets: {
82
- type: Array,
83
- optional: true
80
+ 'roles.groups': {
81
+ type: Array
84
82
  },
85
- 'assets.$': {
83
+ 'roles.groups.$': {
86
84
  type: Object
87
85
  },
88
- 'assets.$.type': {
86
+ 'roles.groups.$.name': {
89
87
  type: String
90
88
  },
91
- 'assets.$.id_asset': {
92
- type: String
89
+ 'roles.groups.$.views': {
90
+ type: Array
93
91
  },
94
- 'assets.$.asset_number': {
92
+ 'roles.groups.$.views.$': {
95
93
  type: String
96
94
  },
97
- 'assets.$.ownership': {
98
- type: String
95
+ 'roles.groups.$.yard': {
96
+ type: String,
97
+ optional: true
99
98
  },
100
- 'assets.$.ownership_driver': {
99
+ 'roles.notifications': {
100
+ type: Array
101
+ },
102
+ 'roles.notifications.$': {
101
103
  type: String
102
104
  },
103
- 'assets.$.date_start': {
104
- type: Date
105
+ 'roles.miscs': {
106
+ type: Array
105
107
  },
106
- 'assets.$.date_end': {
107
- type: Date,
108
- optional: true
108
+ 'roles.miscs.$': {
109
+ type: String
109
110
  },
110
- id_function: {
111
+ active: Boolean,
112
+ id_customer: {
111
113
  type: String,
112
114
  optional: true
113
115
  },
114
116
  customer: {
115
117
  type: String,
116
- optional: true,
118
+ optional: true
117
119
  },
118
- id_customer: {
120
+ customer_type: {
119
121
  type: String,
120
- optional: true,
122
+ optional: true
123
+ },
124
+ phonenumber: {
125
+ type: String,
126
+ optional: true
121
127
  }
122
128
  };
123
129
  var DefaultSchema = new mongoose_1.Schema(schema, {
@@ -19,7 +19,6 @@ var method_response_collection_1 = require("../collections/method-response.colle
19
19
  var mongoose_1 = require("mongoose");
20
20
  var common_1 = require("../util/common");
21
21
  var log_collection_1 = require("../collections/log.collection");
22
- var cron_jobs_3 = require("../support-methods/cron-jobs");
23
22
  var support_manager_1 = require("./support.manager");
24
23
  var MethodManager = /** @class */ (function () {
25
24
  function MethodManager(mainServer, serverConfig, clientDir) {
@@ -43,7 +42,6 @@ var MethodManager = /** @class */ (function () {
43
42
  pdf_1.loadPDFMethods(this);
44
43
  cron_jobs_2.loadCronJobMethods(this);
45
44
  flags_1.loadFlagMethods(this);
46
- cron_jobs_3.loadSupportCronJobMethods(this);
47
45
  this._mailer = nodemailer.createTransport({
48
46
  SES: new aws.SES({
49
47
  apiVersion: '2010-12-01',
@@ -36,6 +36,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  var queue_method_collection_1 = require("../collections/queue-method.collection");
39
+ var user_collection_1 = require("../collections/user.collection");
40
+ var simpl_schema_1 = require("simpl-schema");
41
+ var mongoose_1 = require("mongoose");
39
42
  function loadCronJobMethods(methodManager) {
40
43
  methodManager.methods({
41
44
  methodQueue: {
@@ -57,6 +60,60 @@ function loadCronJobMethods(methodManager) {
57
60
  });
58
61
  }); });
59
62
  }
63
+ },
64
+ updateClientUsers: {
65
+ function: function () {
66
+ var _this = this;
67
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
68
+ var users, count, interval;
69
+ var _this = this;
70
+ return __generator(this, function (_a) {
71
+ switch (_a.label) {
72
+ case 0:
73
+ if (!user_collection_1.ClientUsers) {
74
+ resolve();
75
+ return [2 /*return*/];
76
+ }
77
+ return [4 /*yield*/, user_collection_1.Users.find({})];
78
+ case 1:
79
+ users = _a.sent();
80
+ count = 0;
81
+ interval = setInterval(function () {
82
+ var updateChunk = users.slice(count * 10, Math.min(users.length, (count + 1) * 10));
83
+ _this.callSupportMethodInternal.call(_this, 'updateClientUserChunk', updateChunk);
84
+ count++;
85
+ if (count * 10 > users.length) {
86
+ clearInterval(interval);
87
+ resolve(true);
88
+ }
89
+ }, 1000);
90
+ resolve();
91
+ return [2 /*return*/];
92
+ }
93
+ });
94
+ }); });
95
+ }
96
+ },
97
+ updateClientUserChunk: {
98
+ check: new simpl_schema_1.default({
99
+ users: {
100
+ type: Array
101
+ },
102
+ 'users.$': {
103
+ type: Object,
104
+ blackbox: true
105
+ }
106
+ }),
107
+ function: function (users) {
108
+ var _this = this;
109
+ return new Promise(function (resolve, reject) {
110
+ users.forEach(function (user) {
111
+ user['client'] = _this.serverConfig['CLIENT_NAME'];
112
+ user_collection_1.ClientUsers.updateOne({ _id: user._id }, { $setOnInsert: { _id: mongoose_1.Types.ObjectId().toHexString(), __v: 0 }, $set: user }, { upsert: true }).exec();
113
+ });
114
+ resolve();
115
+ });
116
+ }
60
117
  }
61
118
  });
62
119
  }
@@ -1,14 +1,30 @@
1
1
  import { CollectionDocument } from './collection-document.model';
2
2
  export interface UserModel extends CollectionDocument {
3
- attempts: number;
4
- last: Date;
5
- services?: any;
6
3
  fullname: string;
4
+ roles: UserRoleModel;
7
5
  username?: string;
8
6
  email?: string;
9
- roles?: string[];
10
7
  active?: boolean;
11
- readonly?: boolean;
8
+ services?: any;
9
+ id_customer?: string;
10
+ customer?: string;
11
+ customer_type?: string;
12
12
  phonenumber?: string;
13
- other?: object;
13
+ }
14
+ export interface UserRoleModel {
15
+ super_admin: boolean;
16
+ approvals: UserRoleApprovalModel[];
17
+ groups: UserRoleGroupModel[];
18
+ notifications: string[];
19
+ miscs: string[];
20
+ }
21
+ export interface UserRoleApprovalModel {
22
+ accounting_code: string;
23
+ type: string;
24
+ name: string;
25
+ }
26
+ export interface UserRoleGroupModel {
27
+ name: string;
28
+ views: string[];
29
+ yard?: string;
14
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "1.1.0",
3
+ "version": "1.1.2-newrole",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -1,2 +0,0 @@
1
- import { MethodManager } from '../managers/method.manager';
2
- export declare function loadSupportCronJobMethods(methodManager: MethodManager): void;
@@ -1,97 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- var user_collection_1 = require("../collections/user.collection");
39
- var simpl_schema_1 = require("simpl-schema");
40
- var mongoose_1 = require("mongoose");
41
- function loadSupportCronJobMethods(methodManager) {
42
- methodManager.methods({
43
- updateClientUsers: {
44
- function: function () {
45
- var _this = this;
46
- return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
47
- var users, count, interval;
48
- var _this = this;
49
- return __generator(this, function (_a) {
50
- switch (_a.label) {
51
- case 0:
52
- if (!user_collection_1.ClientUsers) {
53
- resolve();
54
- return [2 /*return*/];
55
- }
56
- return [4 /*yield*/, user_collection_1.Users.find({})];
57
- case 1:
58
- users = _a.sent();
59
- count = 0;
60
- interval = setInterval(function () {
61
- var updateChunk = users.slice(count * 10, Math.min(users.length, (count + 1) * 10));
62
- _this.callSupportMethodInternal.call(_this, 'updateClientUserChunk', updateChunk);
63
- count++;
64
- if (count * 10 > users.length) {
65
- clearInterval(interval);
66
- resolve(true);
67
- }
68
- }, 1000);
69
- resolve();
70
- return [2 /*return*/];
71
- }
72
- });
73
- }); });
74
- }
75
- },
76
- updateClientUserChunk: {
77
- check: new simpl_schema_1.default({
78
- users: {
79
- type: Array
80
- },
81
- 'users.$': {
82
- type: Object,
83
- blackbox: true
84
- }
85
- }),
86
- function: function (users) {
87
- return new Promise(function (resolve, reject) {
88
- users.forEach(function (user) {
89
- user_collection_1.ClientUsers.updateOne({ _id: user._id }, { $setOnInsert: { _id: mongoose_1.Types.ObjectId().toHexString(), __v: 0 }, $set: user }, { upsert: true }).exec();
90
- });
91
- resolve();
92
- });
93
- }
94
- }
95
- });
96
- }
97
- exports.loadSupportCronJobMethods = loadSupportCronJobMethods;