File

libs/users/application/src/lib/users.service.ts

Index

Methods

Constructor

constructor(usersRepository: UsersRepository)
Parameters :
Name Type Optional
usersRepository UsersRepository No

Methods

Async findOneByEmail
findOneByEmail(email: string)
Parameters :
Name Type Optional
email string No
Returns : Promise<User>
Async findOneById
findOneById(id: string)
Parameters :
Name Type Optional
id string No
Returns : Promise<User>
import { Inject, Injectable, NotFoundException } from '@nestjs/common';
import { User, USERS_REPOSITORY, UsersRepository } from '@users/domain';
import { userError } from '@zhumeisong/common-error-exception';

@Injectable()
export class UsersService {
  constructor(
    @Inject(USERS_REPOSITORY)
    private readonly usersRepository: UsersRepository,
  ) {}

  async findOneById(id: string): Promise<User> {
    const user = await this.usersRepository.findOneById(id);
    if (!user) {
      throw new NotFoundException(userError.NOT_FOUND);
    }

    return user;
  }

  async findOneByEmail(email: string): Promise<User> {
    const user = await this.usersRepository.findOneByEmail(email);
    if (!user) {
      throw new NotFoundException(userError.NOT_FOUND);
    }

    return user;
  }
}

results matching ""

    No results matching ""