Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor: use getAllMethodNames method #1448

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions lib/schedule.explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,30 @@ export class ScheduleExplorer implements OnModuleInit {
];
instanceWrappers.forEach((wrapper: InstanceWrapper) => {
const { instance } = wrapper;

if (!instance || !Object.getPrototypeOf(instance)) {
return;
}
this.metadataScanner.scanFromPrototype(
instance,
Object.getPrototypeOf(instance),
(key: string) =>
wrapper.isDependencyTreeStatic()
? this.lookupSchedulers(instance, key)
: this.warnForNonStaticProviders(wrapper, instance, key),
);

const processMethod = (name: string) =>
wrapper.isDependencyTreeStatic()
? this.lookupSchedulers(instance, name)
: this.warnForNonStaticProviders(wrapper, instance, name);

// TODO(v4): remove this after dropping support for nestjs v9.3.2
if (!Reflect.has(this.metadataScanner, 'getAllMethodNames')) {
this.metadataScanner.scanFromPrototype(
instance,
Object.getPrototypeOf(instance),
processMethod,
);

return;
}

this.metadataScanner
.getAllMethodNames(Object.getPrototypeOf(instance))
.forEach(processMethod);
});
}

Expand Down