I am working with NestJSproject. I make an entity Client and a DTO for the "inscrit()" function
when I ran the project, I got the following:
ERROR [ExceptionHandler] Nest can't resolve dependencies of the ClientService (?). Please make sure that the argument ClientRepository at index [0] is available in the ClientModule context.
Potential solutions:
- If ClientRepository is a provider, is it part of the current ClientModule?
- If ClientRepository is exported from a separate @Module, is that module imported within ClientModule?
@Module({
imports: [ /* the Module containing ClientRepository */ ]
})
this is the client.service.ts
file
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ClientInscritDto } from './dto/client-inscrit.dto';
import { Client } from './entity/client.entity';
import * as bcrypt from 'bcrypt';
import { ConflictException } from '@nestjs/common/exceptions';
@Injectable()
export class ClientService {
constructor(
@InjectRepository(Client)
private clientRepository : Repository<Client>
){}
async inscrit(clientData: ClientInscritDto) : Promise<Partial<Client>>{
const client = this.clientRepository.create({...clientData});
client.salt = await bcrypt.genSalt();
client.mdp = await bcrypt.hash(clientData.mdp, client.salt);
try{
await this.clientRepository.save(client);
}catch(err){
throw new ConflictException(`le surname ${clientData.surname} ou l'email ${clientData.email} existe déjà`);
}
return client;
}
}