-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequired-brand.ts
32 lines (29 loc) · 969 Bytes
/
required-brand.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { getOwnConfig } from '@embroider/macros';
import { assert } from '@ember/debug';
import { inject as service } from '@ember/service';
interface Constructable {
new (...args: any[]): any;
}
export function requiredBrand(brand: string, fallbackRoute: string) {
return function extendClass<T extends Constructable>(BaseClass: T) {
return class extends BaseClass {
// @ts-ignore;
@service declare router;
beforeModel() {
assert(
'[EBM][Decorators][requiredBrand] The @brand parameter of type string is mandatory',
typeof brand === 'string'
);
assert(
'[EBM][Decorators][requiredBrand] The @fallbackRoute parameter of type string is mandatory',
typeof fallbackRoute === 'string'
);
if ((getOwnConfig() as any).brand !== brand) {
this.router.transitionTo(fallbackRoute);
} else {
super.beforeModel()
}
}
}
};
}