In my Nest.js setup have a mod.service.ts
in which i want to call project.controller.ts
‘s api endpoints, i was able to call it by doing something like this
// mode.service.ts
class MockRequest implements Partial<Request> {
headers: Headers;
constructor(headers: Record<string, string> ) {
for (const[key, value] of Object.entries(headers)) {
// this.headers.set(key, value); // this fails
}
}
}
const requestConfig = new MockRequest({
...mod.headers,
'activity': 4235534,
'access_token': xxxxxxxxxx,
});
const response = await projectsController['abandonedProjects'].apply(projectsController, requestConfig);
I am able to get the response but the headers.set()
call fails with Cannot read properties of undefined (reading 'set')
resulting in failed call overall (because it’s unauthorized, so gets blocked by JWT guard).
Any idea how i can inject headers and params to it?
I have 100s of controller functions and i would like to avoid refactoring all of that logic to be in proper service methods.