Open Rhig opened 1 month ago
I'm not sure if firebase-admin
's firestore is compatible with @google-cloud/firestore
. Also I can't help finding the issue without seeing what's in UserService
as the error originates there.
Here's UserService
:
import { Injectable, Logger } from '@nestjs/common';
import { BaseFirestoreRepository } from 'fireorm';
import { InjectRepository } from 'nestjs-fireorm';
import { User } from './entities/user.entity';
import { Timestamp } from '@google-cloud/firestore';
@Injectable()
export class UserService {
private logger: Logger = new Logger(UserService.name);
constructor(
@InjectRepository(User)
private users: BaseFirestoreRepository<User>,
) {}
async create({ username, email }): Promise<User> {
const displayName = username;
return this.users.create({
displayName,
email,
createdAt: Timestamp.now(), // Use server-side timestamp
});
}
async findOne(email: string): Promise<User | null> {
return await this.users.whereEqualTo('email', email).findOne();
}
async getOrCreateUser(email: string, displayName: string): Promise<User> {
const user = await this.findOne(email);
if (user) {
this.logger.log(`User with email ${email} already exists`);
return user;
}
this.logger.log(`User with email ${email} not found, creating a new user`);
const newUser = await this.create({
username: displayName,
email,
});
return newUser;
}
async findAll(): Promise<User[]> {
return this.users.find();
}
}
Yeah, not sure what the problem is here. Have you tried running the example but using your firestore instance?
I get the following dependency error: `Error: Nest can't resolve dependencies of the UserService (?). Please make sure that the argument "UserRepository" at index [0] is available in the AppModule context.
Potential solutions:
I'm sure that I did something wrong/stupid but I can't figure out what it is.
My user.module.ts file:
My User entity:
My app.module.ts file:
Is it because I used forRootAsync? When I try to use console.log from inside the useFactory function in the AppModule I don't see the text being printed to the terminal, so it might hint that the FireormModule isn't initialized properly?