Skip to content

Commit

Permalink
Merge pull request #1448 from peixotoleonardo/refactor/schedule.explorer
Browse files Browse the repository at this point in the history
refactor: use getAllMethodNames method
  • Loading branch information
kamilmysliwiec committed Oct 23, 2023
2 parents 62bb95b + 00922c4 commit a66dc3e
Showing 1 changed file with 21 additions and 8 deletions.
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

0 comments on commit a66dc3e

Please sign in to comment.