-
-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't inject services which extend RepositoryService #36
Comments
Ok, could you please create a service as you normally do (not a RepositoryService, but just a dummy service) and inject it to your |
I created the following Service: import { Injectable } from '@nestjs/common';
@Injectable()
export class UsersTestService {
constructor() {
console.log('UsersTestService');
}
} added the service to the ...
constructor(private usersTestService: UsersTestService) {}
... Everything works fine with this dummy service. Is there another way to execute repository methods? |
@kairauer |
I changed the dummy service: import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { User } from './user.entity';
@Injectable()
export class UsersTestService {
constructor(private userRepository: Repository<User>) {
console.log('UsersTestService', this.userRepository);
}
} Now I get an error again:
But I am pretty sure, that I injected a service (which injected the repository) in the past like its mentioned in the docs: https://docs.nestjs.com/recipes/sql-typeorm |
Now you get another error, and it's not what I'm trying to get. We need to reproduce the first error. import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { User } from './user.entity';
@Injectable()
export class UsersTestService {
constructor(@InjectRepository(User) private userRepository: Repository<User>) {
console.log('UsersTestService', this.userRepository);
}
} |
Yes, you are right, that wasn't the right way to inject the repository. I tried it with your solution, now I get nearly the same error as in my first post: TypeError: Cannot read property 'name' of undefined
at Object.getRepositoryToken (/Users/kai/Development/NodeJS/crud/integration/typeorm/node_modules/@nestjs/typeorm/dist/common/typeorm.utils.js:8:22)
at Object.exports.InjectRepository (/Users/kai/Development/NodeJS/crud/integration/typeorm/node_modules/@nestjs/typeorm/dist/common/typeorm.decorators.js:5:72)
at Object.<anonymous> (/Users/kai/Development/NodeJS/crud/integration/typeorm/src/users/test.service.ts:8:16)
at Module._compile (internal/modules/cjs/loader.js:738:30)
at Module.m._compile (/Users/kai/Development/NodeJS/crud/integration/typeorm/node_modules/ts-node/src/index.ts:439:23)
at Module._extensions..js (internal/modules/cjs/loader.js:749:10)
at Object.require.extensions.(anonymous function) [as .ts] (/Users/kai/Development/NodeJS/crud/integration/typeorm/node_modules/ts-node/src/index.ts:442:12)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3) So, it seems like it's not caused by the extended |
Yes, that was my point. And, in general, I think it has nothing to do with |
To anyone else who gets a similar issue, I think this is related to this issue: nestjs/nest#528 |
I tried to implement a custom validator with class-validator https://github.com/typestack/class-validator#custom-validation-classes. I used the example project from this repository.
I added the following class:
And added the validator to the User class (Entity):
I get the following error:
If I remove the injected
UsersService
dependency injection from theDoesUserAlreadyExist
class everything works again.Is it not possible to use the services which extends the
RepositoryService
service? Or is there another way to execute the repository methods (getMany, getOne, etc.)?The text was updated successfully, but these errors were encountered: