@almatar/branding 0.1.6 → 0.1.7
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.
- package/lib/lib/BrandManager.js +2 -1
- package/lib/lib/Models/BrandModel.d.ts +1 -0
- package/lib/lib/Storage.d.ts +3 -0
- package/lib/lib/Storage.js +8 -0
- package/package.json +1 -1
- package/readme.md +47 -0
package/lib/lib/BrandManager.js
CHANGED
|
@@ -116,12 +116,13 @@ var BrandManager = /** @class */ (function () {
|
|
|
116
116
|
case 0:
|
|
117
117
|
_a.trys.push([0, 2, , 3]);
|
|
118
118
|
option = {
|
|
119
|
-
url: AlmatarBranding_1.default.dictionaryService + '
|
|
119
|
+
url: AlmatarBranding_1.default.dictionaryService + 'brands',
|
|
120
120
|
};
|
|
121
121
|
return [4 /*yield*/, PromiseRequest_1.PromiseRequest.request(option)];
|
|
122
122
|
case 1:
|
|
123
123
|
brandsResponse = _a.sent();
|
|
124
124
|
if (brandsResponse.status === 200) {
|
|
125
|
+
Storage_1.default.setBrandsList(brandsResponse.data.list);
|
|
125
126
|
brands = brandsResponse.data.list.map(function (brand) { return brand.key; });
|
|
126
127
|
Storage_1.default.setBrands(brands);
|
|
127
128
|
return [2 /*return*/, brands];
|
package/lib/lib/Storage.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BrandModel } from './Models/BrandModel';
|
|
1
2
|
export default class ContextNamespace {
|
|
2
3
|
static bindENamespace(req: any, res: any, next: any): void;
|
|
3
4
|
static setEBrand(req: any, res: any, next: any): Promise<void>;
|
|
@@ -7,8 +8,10 @@ export default class ContextNamespace {
|
|
|
7
8
|
static getBrand(): any;
|
|
8
9
|
static getEmployeeBrands(): any;
|
|
9
10
|
static getNamespace(): any;
|
|
11
|
+
static setBrandsList(brandList: BrandModel[]): any;
|
|
10
12
|
static setBrands(brands: string[]): any;
|
|
11
13
|
static getBrands(): string[] | null;
|
|
12
14
|
static getDefaultBrand(): string | null;
|
|
13
15
|
static isValidBrand(brand: string): boolean;
|
|
16
|
+
static isBrandIncludesProduct(brandKey: string, product: string): boolean;
|
|
14
17
|
}
|
package/lib/lib/Storage.js
CHANGED
|
@@ -154,6 +154,9 @@ var ContextNamespace = /** @class */ (function () {
|
|
|
154
154
|
ContextNamespace.getNamespace = function () {
|
|
155
155
|
return ns;
|
|
156
156
|
};
|
|
157
|
+
ContextNamespace.setBrandsList = function (brandList) {
|
|
158
|
+
return ns.set('brandsList', brandList);
|
|
159
|
+
};
|
|
157
160
|
ContextNamespace.setBrands = function (brands) {
|
|
158
161
|
return ns.set('brands', brands);
|
|
159
162
|
};
|
|
@@ -168,6 +171,11 @@ var ContextNamespace = /** @class */ (function () {
|
|
|
168
171
|
var _a;
|
|
169
172
|
return (_a = ns.get('brands')) === null || _a === void 0 ? void 0 : _a.includes(brand);
|
|
170
173
|
};
|
|
174
|
+
ContextNamespace.isBrandIncludesProduct = function (brandKey, product) {
|
|
175
|
+
var _a, _b;
|
|
176
|
+
var brand = (_a = ns.get('brandsList')) === null || _a === void 0 ? void 0 : _a.filter(function (b) { return b.key === brandKey; })[0];
|
|
177
|
+
return (_b = brand.products) === null || _b === void 0 ? void 0 : _b.includes(product);
|
|
178
|
+
};
|
|
171
179
|
return ContextNamespace;
|
|
172
180
|
}());
|
|
173
181
|
exports.default = ContextNamespace;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -77,6 +77,53 @@ handler: (request, reply) => {
|
|
|
77
77
|
}
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
### get brand
|
|
81
|
+
|
|
82
|
+
get brand from current context
|
|
83
|
+
```
|
|
84
|
+
import { ContextNamespace } from '@almatar/branding';
|
|
85
|
+
|
|
86
|
+
handler: (request, reply) => {
|
|
87
|
+
const brand = ContextNamespace.getBrand();
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### get default brand
|
|
92
|
+
|
|
93
|
+
get default brand
|
|
94
|
+
```
|
|
95
|
+
import { ContextNamespace } from '@almatar/branding';
|
|
96
|
+
|
|
97
|
+
handler: (request, reply) => {
|
|
98
|
+
const defaultBrand = ContextNamespace.getDefaultBrand();
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
### validate brand
|
|
102
|
+
|
|
103
|
+
validate brand
|
|
104
|
+
```
|
|
105
|
+
import { ContextNamespace } from '@almatar/branding';
|
|
106
|
+
|
|
107
|
+
handler: (request, reply) => {
|
|
108
|
+
/** use isValidBrand to validate if the incoming brand is valid */
|
|
109
|
+
if(ContextNamespace.isValidBrand(brand: string): boolean{
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** use isBrandIncludesProduct function to validate if product is related to brand*/
|
|
113
|
+
if(ContextNamespace.isBrandIncludesProduct(brandKey: string, product: string): boolean{
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
### get all available brands
|
|
118
|
+
|
|
119
|
+
get all available brands
|
|
120
|
+
```
|
|
121
|
+
import { ContextNamespace } from '@almatar/branding';
|
|
122
|
+
|
|
123
|
+
handler: (request, reply) => {
|
|
124
|
+
const brands = ContextNamespace.getBrands();
|
|
125
|
+
}
|
|
126
|
+
```
|
|
80
127
|
### build mongoose model
|
|
81
128
|
|
|
82
129
|
```
|