@nsix/nsix-prisma-types
v1.0.2
Published
Пакет для спільного використання типів Prisma між мікросервісами NestJS.
Readme
@nsix/nsix-prisma-types
Пакет для спільного використання типів Prisma між мікросервісами NestJS.
Як використовувати
import { Inject, Injectable, InternalServerErrorException, Logger } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import { firstValueFrom } from 'rxjs';
import { PrismaClientSvcMongo } from '@nsix/nsix-prisma-types';
@Injectable()
export class ProductMicroservice {
//
constructor(@Inject('CLIENT_SERVICE') private readonly clientService: ClientProxy) {
}
//
private readonly log = new Logger();
async find(options?: PrismaClientSvcMongo.Prisma.ClientProductFindManyArgs): Promise<PrismaClientSvcMongo.ClientProduct[]> {
try {
return await firstValueFrom<PrismaClientSvcMongo.ClientProduct[]>(
this.clientService.send('client.product.find', options),
);
} catch (e) {
this.log.error(e);
throw new InternalServerErrorException(e);
}
}
// Використання в любому сервіс коді
async exampleUse() {
const example = await this.find({
where: {
id: '0000000',
},
});
return example.map(value => {
return value.product.name_translate
})
}
}