@resolveio/server-lib 1.1.0-newrole → 1.1.1

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,6 +21,13 @@ 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
+ },
24
31
  attempts: {
25
32
  type: Number,
26
33
  optional: true
@@ -57,73 +64,60 @@ var schema = {
57
64
  type: String
58
65
  },
59
66
  roles: {
60
- type: Object
61
- },
62
- 'roles.super_admin': {
63
- type: Boolean
64
- },
65
- 'roles.approvals': {
66
67
  type: Array
67
68
  },
68
- 'roles.approvals.$': {
69
- type: Object
70
- },
71
- 'roles.approvals.$.name': {
69
+ 'roles.$': {
72
70
  type: String
73
71
  },
74
- 'roles.approvals.$.type': {
75
- type: String
72
+ phonenumber: {
73
+ type: String,
74
+ optional: true
76
75
  },
77
- 'roles.approvals.$.accounting_code': {
78
- type: String
76
+ other: {
77
+ type: Object,
78
+ blackbox: true,
79
+ optional: true
79
80
  },
80
- 'roles.groups': {
81
- type: Array
81
+ assets: {
82
+ type: Array,
83
+ optional: true
82
84
  },
83
- 'roles.groups.$': {
85
+ 'assets.$': {
84
86
  type: Object
85
87
  },
86
- 'roles.groups.$.name': {
88
+ 'assets.$.type': {
87
89
  type: String
88
90
  },
89
- 'roles.groups.$.views': {
90
- type: Array
91
- },
92
- 'roles.groups.$.views.$': {
91
+ 'assets.$.id_asset': {
93
92
  type: String
94
93
  },
95
- 'roles.groups.$.yard': {
96
- type: String,
97
- optional: true
98
- },
99
- 'roles.notifications': {
100
- type: Array
101
- },
102
- 'roles.notifications.$': {
94
+ 'assets.$.asset_number': {
103
95
  type: String
104
96
  },
105
- 'roles.miscs': {
106
- type: Array
97
+ 'assets.$.ownership': {
98
+ type: String
107
99
  },
108
- 'roles.miscs.$': {
100
+ 'assets.$.ownership_driver': {
109
101
  type: String
110
102
  },
111
- active: Boolean,
112
- id_customer: {
113
- type: String,
103
+ 'assets.$.date_start': {
104
+ type: Date
105
+ },
106
+ 'assets.$.date_end': {
107
+ type: Date,
114
108
  optional: true
115
109
  },
116
- customer: {
110
+ id_function: {
117
111
  type: String,
118
112
  optional: true
119
113
  },
120
- customer_type: {
114
+ customer: {
121
115
  type: String,
122
- optional: true
116
+ optional: true,
123
117
  },
124
- phonenumber: {
118
+ id_customer: {
125
119
  type: String,
126
- optional: true
120
+ optional: true,
127
121
  }
128
122
  };
129
123
  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,58 @@ 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
+ return new Promise(function (resolve, reject) {
109
+ users.forEach(function (user) {
110
+ user_collection_1.ClientUsers.updateOne({ _id: user._id }, { $setOnInsert: { _id: mongoose_1.Types.ObjectId().toHexString(), __v: 0 }, $set: user }, { upsert: true }).exec();
111
+ });
112
+ resolve();
113
+ });
114
+ }
60
115
  }
61
116
  });
62
117
  }
@@ -1,30 +1,14 @@
1
1
  import { CollectionDocument } from './collection-document.model';
2
2
  export interface UserModel extends CollectionDocument {
3
+ attempts: number;
4
+ last: Date;
5
+ services?: any;
3
6
  fullname: string;
4
- roles: UserRoleModel;
5
7
  username?: string;
6
8
  email?: string;
9
+ roles?: string[];
7
10
  active?: boolean;
8
- services?: any;
9
- id_customer?: string;
10
- customer?: string;
11
- customer_type?: string;
11
+ readonly?: boolean;
12
12
  phonenumber?: string;
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;
13
+ other?: object;
30
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "1.1.0-newrole",
3
+ "version": "1.1.1",
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;