this issue started of as a TS issue but it seems nest made it tougher to solve so gues this can count as a nestjs issue now?
i have this prisma issue have been stuck on for weeks now where i have my prisma/database service (call it what ever you want)
where i extend prisma with a custom findbyId method docs here
but that caused typescript to not regonize this custom method, prisma has a solution for this found here and that is to create a typing at run type (hate it) but then the issue with nest
i cant really create this typing at run time because i cant define it in the class but outside is not going to work either
so when i got another service that uses this databaseService i should be using this extended version but if i cant define it in the class our outside
let alone use it in the constructor of another service what am i supposed to do?
ps: I left out the onModuleInit and enableShutdownHooks out to keep things relative
@Injectable()
export class DatabaseService extends PrismaClient implements OnModuleInit {
private readonly logger = new Logger(DatabaseService.name)
constructor() {
super()
this.$extends({
model: {
$allModels: {
async findById<T, A>(
this: T,
id: Prisma.Exact<A, Prisma.Args<T, 'findUniqueOrThrow'>['where']>,
): Promise<Prisma.Result<T, A, 'findUniqueOrThrow'>> {
const context = Prisma.getExtensionContext(this)
const result = await (context as any).findUniqueOrThrow({ where: { id } })
return result
},
},
},
})
}
}
so not only am i stuck with a TS issue i also got the nestjs problem where i can not create the typing because i'm working in a class here
