@almatar/branding 0.1.3 → 0.1.5

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.
@@ -1,10 +1,13 @@
1
- export default class ContextNamespace {
2
- static bindENamespace(req: any, res: any, next: any): void;
3
- static setEBrand(req: any, res: any, next: any): Promise<void>;
4
- static bindHNamespace(req: any, reply: any): void;
5
- static setHBrand(req: any, reply: any): Promise<void>;
6
- static setBrand(brnad: string | string[]): any;
7
- static getBrand(): any;
8
- static getEmployeeBrands(): any;
9
- static getNamespace(): any;
10
- }
1
+ export default class ContextNamespace {
2
+ static bindENamespace(req: any, res: any, next: any): void;
3
+ static setEBrand(req: any, res: any, next: any): Promise<void>;
4
+ static bindHNamespace(req: any, reply: any): void;
5
+ static setHBrand(req: any, reply: any): Promise<void>;
6
+ static setBrand(brand: string | string[]): any;
7
+ static getBrand(): any;
8
+ static getEmployeeBrands(): any;
9
+ static getNamespace(): any;
10
+ static setBrands(brands: any): any;
11
+ static getBrands(): Promise<any>;
12
+ static getDefaultBrand(): any;
13
+ }
@@ -1,135 +1,161 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- var BrandIdentifier_1 = require("./BrandIdentifier");
40
- var createNamespace = require('cls-hooked').createNamespace;
41
- var namespaceName = 'request';
42
- var ns = createNamespace(namespaceName);
43
- var ContextNamespace = /** @class */ (function () {
44
- function ContextNamespace() {
45
- }
46
- /* Express Start */
47
- ContextNamespace.bindENamespace = function (req, res, next) {
48
- ns.bindEmitter(req);
49
- ns.bindEmitter(res);
50
- ns.run(function () {
51
- next();
52
- });
53
- };
54
- ContextNamespace.setEBrand = function (req, res, next) {
55
- return __awaiter(this, void 0, void 0, function () {
56
- var brandIdentifier, brand;
57
- return __generator(this, function (_a) {
58
- switch (_a.label) {
59
- case 0:
60
- brandIdentifier = new BrandIdentifier_1.BrandIdentifier('express');
61
- return [4 /*yield*/, brandIdentifier.getBrand(req)];
62
- case 1:
63
- brand = _a.sent();
64
- if (Array.isArray(brand)) {
65
- ns.set('employeeBrands', brand);
66
- next();
67
- }
68
- else if (typeof brand === 'string') {
69
- ns.set('brand', brand);
70
- next();
71
- }
72
- else {
73
- next(brand);
74
- }
75
- return [2 /*return*/];
76
- }
77
- });
78
- });
79
- };
80
- /* Express End */
81
- /* Hapi Start */
82
- ContextNamespace.bindHNamespace = function (req, reply) {
83
- ns.bindEmitter(req.raw.req);
84
- ns.bindEmitter(req.raw.res);
85
- ns.run(function () {
86
- reply();
87
- });
88
- };
89
- ContextNamespace.setHBrand = function (req, reply) {
90
- return __awaiter(this, void 0, void 0, function () {
91
- var brandIdentifier, brand;
92
- return __generator(this, function (_a) {
93
- switch (_a.label) {
94
- case 0:
95
- brandIdentifier = new BrandIdentifier_1.BrandIdentifier('hapi');
96
- return [4 /*yield*/, brandIdentifier.getBrand(req)];
97
- case 1:
98
- brand = _a.sent();
99
- if (Array.isArray(brand)) {
100
- ns.set('employeeBrands', brand);
101
- reply();
102
- }
103
- else if (typeof brand === 'string') {
104
- ns.set('brand', brand);
105
- reply();
106
- }
107
- else {
108
- reply(brand);
109
- }
110
- return [2 /*return*/];
111
- }
112
- });
113
- });
114
- };
115
- /* Hapi End */
116
- ContextNamespace.setBrand = function (brnad) {
117
- if (Array.isArray(brnad)) {
118
- return ns.set('employeeBrands', brnad);
119
- }
120
- else {
121
- return ns.set('brand', brnad);
122
- }
123
- };
124
- ContextNamespace.getBrand = function () {
125
- return ns.get('brand');
126
- };
127
- ContextNamespace.getEmployeeBrands = function () {
128
- return ns.get('employeeBrands');
129
- };
130
- ContextNamespace.getNamespace = function () {
131
- return ns;
132
- };
133
- return ContextNamespace;
134
- }());
135
- exports.default = ContextNamespace;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var BrandIdentifier_1 = require("./BrandIdentifier");
40
+ var createNamespace = require('cls-hooked').createNamespace;
41
+ var namespaceName = 'request';
42
+ var ns = createNamespace(namespaceName);
43
+ var ContextNamespace = /** @class */ (function () {
44
+ function ContextNamespace() {
45
+ }
46
+ /* Express Start */
47
+ ContextNamespace.bindENamespace = function (req, res, next) {
48
+ ns.bindEmitter(req);
49
+ ns.bindEmitter(res);
50
+ ns.run(function () {
51
+ next();
52
+ });
53
+ };
54
+ ContextNamespace.setEBrand = function (req, res, next) {
55
+ return __awaiter(this, void 0, void 0, function () {
56
+ var brandIdentifier, brand;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0:
60
+ brandIdentifier = new BrandIdentifier_1.BrandIdentifier('express');
61
+ return [4 /*yield*/, brandIdentifier.getBrand(req)];
62
+ case 1:
63
+ brand = _a.sent();
64
+ if (Array.isArray(brand)) {
65
+ ns.set('employeeBrands', brand);
66
+ next();
67
+ }
68
+ else if (typeof brand === 'string') {
69
+ ns.set('brand', brand);
70
+ next();
71
+ }
72
+ else {
73
+ next(brand);
74
+ }
75
+ return [2 /*return*/];
76
+ }
77
+ });
78
+ });
79
+ };
80
+ /* Express End */
81
+ /* Hapi Start */
82
+ ContextNamespace.bindHNamespace = function (req, reply) {
83
+ ns.bindEmitter(req.raw.req);
84
+ ns.bindEmitter(req.raw.res);
85
+ ns.run(function () {
86
+ reply();
87
+ });
88
+ };
89
+ ContextNamespace.setHBrand = function (req, reply) {
90
+ return __awaiter(this, void 0, void 0, function () {
91
+ var brandIdentifier, brand;
92
+ return __generator(this, function (_a) {
93
+ switch (_a.label) {
94
+ case 0:
95
+ brandIdentifier = new BrandIdentifier_1.BrandIdentifier('hapi');
96
+ return [4 /*yield*/, brandIdentifier.getBrand(req)];
97
+ case 1:
98
+ brand = _a.sent();
99
+ if (Array.isArray(brand)) {
100
+ ns.set('employeeBrands', brand);
101
+ reply();
102
+ }
103
+ else if (typeof brand === 'string') {
104
+ ns.set('brand', brand);
105
+ reply();
106
+ }
107
+ else {
108
+ reply(brand);
109
+ }
110
+ return [2 /*return*/];
111
+ }
112
+ });
113
+ });
114
+ };
115
+ /* Hapi End */
116
+ ContextNamespace.setBrand = function (brand) {
117
+ if (Array.isArray(brand)) {
118
+ return ns.set('employeeBrands', brand);
119
+ }
120
+ else {
121
+ return ns.set('brand', brand);
122
+ }
123
+ };
124
+ ContextNamespace.getBrand = function () {
125
+ return ns.get('brand');
126
+ };
127
+ ContextNamespace.getEmployeeBrands = function () {
128
+ return ns.get('employeeBrands');
129
+ };
130
+ ContextNamespace.getNamespace = function () {
131
+ return ns;
132
+ };
133
+ ContextNamespace.setBrands = function (brands) {
134
+ return ns.set('brands', brands);
135
+ };
136
+ ContextNamespace.getBrands = function () {
137
+ return __awaiter(this, void 0, void 0, function () {
138
+ var brandIdentifier;
139
+ return __generator(this, function (_a) {
140
+ switch (_a.label) {
141
+ case 0:
142
+ if (!!ns.get('brands')) return [3 /*break*/, 2];
143
+ brandIdentifier = new BrandIdentifier_1.BrandIdentifier('hapi');
144
+ return [4 /*yield*/, brandIdentifier.getBrands()];
145
+ case 1:
146
+ _a.sent();
147
+ _a.label = 2;
148
+ case 2: return [2 /*return*/, ns.get('brands')];
149
+ }
150
+ });
151
+ });
152
+ };
153
+ ContextNamespace.getDefaultBrand = function () {
154
+ var brandIdentifier = new BrandIdentifier_1.BrandIdentifier('hapi');
155
+ var defaultBrand = brandIdentifier.getDefaultBrand();
156
+ ns.set('defaultBrand', defaultBrand);
157
+ return ns.get('defaultBrand');
158
+ };
159
+ return ContextNamespace;
160
+ }());
161
+ exports.default = ContextNamespace;
@@ -1,8 +1,8 @@
1
- declare class MultiTenant {
2
- private mongoose;
3
- private models;
4
- constructor(mongoose: any);
5
- tenantModel(name: string, schema: any, options?: any): (props?: {}) => any;
6
- tenantlessModel(name: string, schema: any, options?: any): () => any;
7
- }
8
- export default MultiTenant;
1
+ declare class MultiTenant {
2
+ private mongoose;
3
+ private models;
4
+ constructor(mongoose: any);
5
+ tenantModel(name: string, schema: any, options?: any): (props?: {}) => any;
6
+ tenantlessModel(name: string, schema: any, options?: any): () => any;
7
+ }
8
+ export default MultiTenant;
@@ -1,24 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var MongooseModel_1 = require("../MongooseModel");
4
- var MultiTenant = /** @class */ (function () {
5
- function MultiTenant(mongoose) {
6
- this.mongoose = mongoose;
7
- this.models = {};
8
- }
9
- MultiTenant.prototype.tenantModel = function (name, schema, options) {
10
- var _this = this;
11
- return function (props) {
12
- if (props === void 0) { props = {}; }
13
- var skipBrand = props.skipBrand;
14
- var mongooseModel = new MongooseModel_1.MongooseModel(_this.mongoose);
15
- return mongooseModel.createModel(name, schema, options, _this.models, skipBrand);
16
- };
17
- };
18
- MultiTenant.prototype.tenantlessModel = function (name, schema, options) {
19
- var _this = this;
20
- return function () { return _this.mongoose.model(name, schema, options); };
21
- };
22
- return MultiTenant;
23
- }());
24
- exports.default = MultiTenant;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var MongooseModel_1 = require("../MongooseModel");
4
+ var MultiTenant = /** @class */ (function () {
5
+ function MultiTenant(mongoose) {
6
+ this.mongoose = mongoose;
7
+ this.models = {};
8
+ }
9
+ MultiTenant.prototype.tenantModel = function (name, schema, options) {
10
+ var _this = this;
11
+ return function (props) {
12
+ if (props === void 0) { props = {}; }
13
+ var skipBrand = props.skipBrand;
14
+ var mongooseModel = new MongooseModel_1.MongooseModel(_this.mongoose);
15
+ return mongooseModel.createModel(name, schema, options, _this.models, skipBrand);
16
+ };
17
+ };
18
+ MultiTenant.prototype.tenantlessModel = function (name, schema, options) {
19
+ var _this = this;
20
+ return function () { return _this.mongoose.model(name, schema, options); };
21
+ };
22
+ return MultiTenant;
23
+ }());
24
+ exports.default = MultiTenant;
@@ -1,13 +1,13 @@
1
- export declare class MongooseModel {
2
- private mongoose;
3
- constructor(mongoose: any);
4
- createModel(name: string, schema: any, options?: any, existingModels?: any, skipBrand?: boolean): any;
5
- private addPreCondition;
6
- private addPreReadQueries;
7
- private addPreAggregate;
8
- private addPreAggregateQueries;
9
- private addPreSave;
10
- private addPreSaveQueries;
11
- private addPreInsertMany;
12
- private addPreInsertManyQueries;
13
- }
1
+ export declare class MongooseModel {
2
+ private mongoose;
3
+ constructor(mongoose: any);
4
+ createModel(name: string, schema: any, options?: any, existingModels?: any, skipBrand?: boolean): any;
5
+ private addPreCondition;
6
+ private addPreReadQueries;
7
+ private addPreAggregate;
8
+ private addPreAggregateQueries;
9
+ private addPreSave;
10
+ private addPreSaveQueries;
11
+ private addPreInsertMany;
12
+ private addPreInsertManyQueries;
13
+ }
@@ -1,84 +1,84 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongooseModel = void 0;
4
- var Storage_1 = require("../Storage");
5
- var MongooseModel = /** @class */ (function () {
6
- function MongooseModel(mongoose) {
7
- this.mongoose = mongoose;
8
- }
9
- MongooseModel.prototype.createModel = function (name, schema, options, existingModels, skipBrand) {
10
- var brands = [];
11
- if (!skipBrand) {
12
- brands = (Storage_1.default.getEmployeeBrands()) ? Storage_1.default.getEmployeeBrands() : [Storage_1.default.getBrand()];
13
- schema.add({ brand: String });
14
- this.addPreReadQueries(schema);
15
- this.addPreAggregateQueries(schema);
16
- this.addPreSaveQueries(schema);
17
- this.addPreInsertManyQueries(schema);
18
- }
19
- var modelName = (skipBrand || !Array.isArray(brands)) ? name : name + "-" + brands.join("-");
20
- if (!existingModels[modelName]) {
21
- existingModels[modelName] = this.mongoose.model(modelName, schema, options);
22
- }
23
- return existingModels[modelName];
24
- };
25
- MongooseModel.prototype.addPreCondition = function (next) {
26
- var brands = (Storage_1.default.getEmployeeBrands()) ? Storage_1.default.getEmployeeBrands() : [Storage_1.default.getBrand()];
27
- if (Array.isArray(brands)) {
28
- // @ts-ignore
29
- this.where({ brand: { $in: brands } });
30
- }
31
- next();
32
- };
33
- MongooseModel.prototype.addPreReadQueries = function (schema) {
34
- schema.pre('count', this.addPreCondition);
35
- schema.pre('find', this.addPreCondition);
36
- schema.pre('findOne', this.addPreCondition);
37
- schema.pre('update', this.addPreCondition);
38
- schema.pre('findOneAndUpdate', this.addPreCondition);
39
- schema.pre('updateOne', this.addPreCondition);
40
- schema.pre('updateMany', this.addPreCondition);
41
- schema.pre('findOneAndDelete', this.addPreCondition);
42
- schema.pre('findOneAndRemove', this.addPreCondition);
43
- schema.pre('deleteMany', this.addPreCondition);
44
- schema.pre('deleteOne', this.addPreCondition);
45
- schema.pre('remove', this.addPreCondition);
46
- };
47
- MongooseModel.prototype.addPreAggregate = function (next) {
48
- var brands = (Storage_1.default.getEmployeeBrands()) ? Storage_1.default.getEmployeeBrands() : [Storage_1.default.getBrand()];
49
- if (Array.isArray(brands)) {
50
- // @ts-ignore
51
- this.pipeline().unshift({ $match: { brand: { $in: brands } } });
52
- }
53
- next();
54
- };
55
- MongooseModel.prototype.addPreAggregateQueries = function (schema) {
56
- schema.pre('aggregate', this.addPreAggregate);
57
- };
58
- MongooseModel.prototype.addPreSave = function (next) {
59
- var brand = Storage_1.default.getBrand();
60
- // @ts-ignore
61
- if (!this.brand && brand) {
62
- // @ts-ignore
63
- this.brand = brand;
64
- }
65
- next();
66
- };
67
- MongooseModel.prototype.addPreSaveQueries = function (schema) {
68
- schema.pre('save', this.addPreSave);
69
- };
70
- MongooseModel.prototype.addPreInsertMany = function (next, dataArray) {
71
- var brand = Storage_1.default.getBrand();
72
- dataArray.forEach(function (data) {
73
- if (!data.tanentId && brand) {
74
- data.brand = brand;
75
- }
76
- });
77
- next();
78
- };
79
- MongooseModel.prototype.addPreInsertManyQueries = function (schema) {
80
- schema.pre('insertMany', this.addPreInsertMany);
81
- };
82
- return MongooseModel;
83
- }());
84
- exports.MongooseModel = MongooseModel;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongooseModel = void 0;
4
+ var Storage_1 = require("../Storage");
5
+ var MongooseModel = /** @class */ (function () {
6
+ function MongooseModel(mongoose) {
7
+ this.mongoose = mongoose;
8
+ }
9
+ MongooseModel.prototype.createModel = function (name, schema, options, existingModels, skipBrand) {
10
+ var brands = [];
11
+ if (!skipBrand) {
12
+ brands = (Storage_1.default.getEmployeeBrands()) ? Storage_1.default.getEmployeeBrands() : [Storage_1.default.getBrand()];
13
+ schema.add({ brand: String });
14
+ this.addPreReadQueries(schema);
15
+ this.addPreAggregateQueries(schema);
16
+ this.addPreSaveQueries(schema);
17
+ this.addPreInsertManyQueries(schema);
18
+ }
19
+ var modelName = (skipBrand || !Array.isArray(brands)) ? name : name + "-" + brands.join("-");
20
+ if (!existingModels[modelName]) {
21
+ existingModels[modelName] = this.mongoose.model(modelName, schema, options);
22
+ }
23
+ return existingModels[modelName];
24
+ };
25
+ MongooseModel.prototype.addPreCondition = function (next) {
26
+ var brands = (Storage_1.default.getEmployeeBrands()) ? Storage_1.default.getEmployeeBrands() : [Storage_1.default.getBrand()];
27
+ if (Array.isArray(brands)) {
28
+ // @ts-ignore
29
+ this.where({ brand: { $in: brands } });
30
+ }
31
+ next();
32
+ };
33
+ MongooseModel.prototype.addPreReadQueries = function (schema) {
34
+ schema.pre('count', this.addPreCondition);
35
+ schema.pre('find', this.addPreCondition);
36
+ schema.pre('findOne', this.addPreCondition);
37
+ schema.pre('update', this.addPreCondition);
38
+ schema.pre('findOneAndUpdate', this.addPreCondition);
39
+ schema.pre('updateOne', this.addPreCondition);
40
+ schema.pre('updateMany', this.addPreCondition);
41
+ schema.pre('findOneAndDelete', this.addPreCondition);
42
+ schema.pre('findOneAndRemove', this.addPreCondition);
43
+ schema.pre('deleteMany', this.addPreCondition);
44
+ schema.pre('deleteOne', this.addPreCondition);
45
+ schema.pre('remove', this.addPreCondition);
46
+ };
47
+ MongooseModel.prototype.addPreAggregate = function (next) {
48
+ var brands = (Storage_1.default.getEmployeeBrands()) ? Storage_1.default.getEmployeeBrands() : [Storage_1.default.getBrand()];
49
+ if (Array.isArray(brands)) {
50
+ // @ts-ignore
51
+ this.pipeline().unshift({ $match: { brand: { $in: brands } } });
52
+ }
53
+ next();
54
+ };
55
+ MongooseModel.prototype.addPreAggregateQueries = function (schema) {
56
+ schema.pre('aggregate', this.addPreAggregate);
57
+ };
58
+ MongooseModel.prototype.addPreSave = function (next) {
59
+ var brand = Storage_1.default.getBrand();
60
+ // @ts-ignore
61
+ if (!this.brand && brand) {
62
+ // @ts-ignore
63
+ this.brand = brand;
64
+ }
65
+ next();
66
+ };
67
+ MongooseModel.prototype.addPreSaveQueries = function (schema) {
68
+ schema.pre('save', this.addPreSave);
69
+ };
70
+ MongooseModel.prototype.addPreInsertMany = function (next, dataArray) {
71
+ var brand = Storage_1.default.getBrand();
72
+ dataArray.forEach(function (data) {
73
+ if (!data.tanentId && brand) {
74
+ data.brand = brand;
75
+ }
76
+ });
77
+ next();
78
+ };
79
+ MongooseModel.prototype.addPreInsertManyQueries = function (schema) {
80
+ schema.pre('insertMany', this.addPreInsertMany);
81
+ };
82
+ return MongooseModel;
83
+ }());
84
+ exports.MongooseModel = MongooseModel;
@@ -1,9 +1,9 @@
1
- import { DynamicModule } from '@nestjs/common';
2
- import { MongooseModule } from '@nestjs/mongoose';
3
- export default class TenantMongooseModule extends MongooseModule {
4
- static forFeature(models?: {
5
- name: string;
6
- schema: any;
7
- collection?: string;
8
- }[], connectionName?: string): DynamicModule;
9
- }
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { MongooseModule } from '@nestjs/mongoose';
3
+ export default class TenantMongooseModule extends MongooseModule {
4
+ static forFeature(models?: {
5
+ name: string;
6
+ schema: any;
7
+ collection?: string;
8
+ }[], connectionName?: string): DynamicModule;
9
+ }