All files / src/modules/api/user user.service.ts

33.33% Statements 3/9
0% Branches 0/4
25% Functions 1/4
25% Lines 2/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28                2x 2x                                    
import { UserEntity } from "@/modules/shared/database/entities";
import { IAPIUserRepository } from "@/modules/shared/database/repositories/interfaces/IAPIUserRepository";
import { Repositories } from "@/modules/shared/database/types/constants";
import { Inject, Injectable } from "@nestjs/common";
import { IUserService } from "./interfaces/IUserService";
import { UserDTO } from "./user.dto";
 
@Injectable()
export class UserService implements IUserService {
	public constructor(@Inject(Repositories.APIUser) private readonly apiUserRepo: IAPIUserRepository) {}
 
	public async get(userId: string): Promise<UserEntity> {
		return await this.apiUserRepo.get(userId);
	}
 
	public async create(details: UserDTO): Promise<UserEntity> {
		const user = await this.get(details.id);
		if (!user) {
			await this.apiUserRepo.create(details);
		}
		return user ? user : await this.get(details.id);
	}
 
	public async update(details: UserDTO): Promise<UserEntity> {
		return await this.apiUserRepo.update(details);
	}
}