import { Injectable } from '@nestjs/common' import { RpcException } from '@nestjs/microservices' import { Role } from '@prisma/generated/enums' import { convertEnum, RpcStatus } from '@teacinema/common' import type { GetAccountRequest, GetAccountResponse } from '@teacinema/contracts/gen/account' import { AccountRepository } from './account.repository' @Injectable() export class AccountService { public constructor(private readonly accountRepository: AccountRepository) {} public async getAccount( data: GetAccountRequest ): Promise { const { id } = data const account = await this.accountRepository.findById(id) if (!account) { throw new RpcException({ code: RpcStatus.NOT_FOUND, details: 'Account not found' }) } return { email: account.email, id: account.id, phone: account.phone, isEmailVerified: account.isEmailVerified, isPhoneVerified: account.isPhoneVerified, // @ts-ignore role: convertEnum(Role, account.role) } } }