import { Injectable, NotFoundException } from "@nestjs/common"; import { Prisma, PrismaClient } from "@prisma/client"; import { PrismaService } from "src/prisma/prisma.service"; type Tx = Prisma.TransactionClient | PrismaClient; @Injectable() export class FullNameResolver { constructor(private readonly prisma: PrismaService){} readonly resolveFullName = async (employee_id: number, client?: Tx): Promise =>{ const db = client ?? this.prisma; const employee = await db.employees.findUnique({ where: { id: employee_id }, select: { user: { select: {first_name: true, last_name: true} } }, }); if(!employee) throw new NotFoundException(`Unknown user with name: ${employee_id}`) const full_name = ( employee.user.first_name + " " + employee.user.last_name ) || " "; return full_name; } }