Как обернуть декоратор другим декоратором в typescript?
Есть такой код:
@Injectable()
export class UsersService {
constructor(
@InjectRepository(User)
private usersRepository: Repository<User>,
) {}
findAll(): Promise<User[]> {
return this.usersRepository.find();
}
}
Основная задача - обернуть репозиторий, что инжектится через @InjectRepository(User) в единую обертку над базой данных.
Вот обертка:
class Wrapper {
private repository: any;
constructor(repository: any) {
this.repository = repository;
}
async find() {
const result = await this.repository.find();
return [result, 'Test'];
}
}
Как ее подключить через декоратор?
Пытался так:
function testDecorator(a: any): any {
return () => {
const test = InjectRepository(a);
return new UniversalRepository(test);
};
}
Вызов его:
@(testDecorator(User)());
Да только не работает это все - var decorated = decorator(target). TypeError: decorator is not a function.
Работает, только, если сделать так:
function work(a: any):any {
return InjectRepository(a);
}
Но нужна обертка. Как решить?