@almatar/branding 0.1.6 → 0.1.8

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.
@@ -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 + 'dictionary/brands',
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];
@@ -4,5 +4,6 @@ export declare class BrandModel {
4
4
  name: string;
5
5
  description: string;
6
6
  isActive: boolean;
7
+ products: string[];
7
8
  constructor(init?: Partial<BrandModel>);
8
9
  }
@@ -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
  }
@@ -53,7 +53,7 @@ var ContextNamespace = /** @class */ (function () {
53
53
  return __generator(this, function (_a) {
54
54
  switch (_a.label) {
55
55
  case 0:
56
- brandIdentifier = new BrandIdentifier_1.BrandIdentifier('hapi');
56
+ brandIdentifier = new BrandIdentifier_1.BrandIdentifier('express');
57
57
  return [4 /*yield*/, brandIdentifier.getBrands()];
58
58
  case 1:
59
59
  _a.sent();
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almatar/branding",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
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
  ```