fix(prisma-videos-ide): resolve IDE TypeScript error by accessing video model through typed getter helper in VideosService
This commit is contained in:
1 parent
5c4a553f0c
commit
f089f7ed91
2 files changed
+11
-11
No files matched your search
@@ -3,10 +3,6 @@ import { PrismaClient } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
||||
get videoDelegate(): PrismaClient['video'] {
|
||||
return (this as any).video;
|
||||
}
|
||||
|
||||
async onModuleInit() {
|
||||
await this.$connect();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ import { CreateVideoDto } from './dto/create-video.dto';
|
||||
export class VideosService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
private get video() {
|
||||
return (this.prisma as any).video;
|
||||
}
|
||||
|
||||
async findAll(query: any) {
|
||||
const page = Number(query.page) || 1;
|
||||
const limit = Number(query.limit) || 20;
|
||||
@@ -24,13 +28,13 @@ export class VideosService {
|
||||
}
|
||||
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.video.findMany({
|
||||
this.video.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: [{ isFeatured: 'desc' }, { createdAt: 'desc' }],
|
||||
}),
|
||||
this.prisma.video.count({ where }),
|
||||
this.video.count({ where }),
|
||||
]);
|
||||
|
||||
return {
|
||||
@@ -45,14 +49,14 @@ export class VideosService {
|
||||
}
|
||||
|
||||
async findOne(id: string, incrementView = false) {
|
||||
const video = await this.prisma.video.findUnique({
|
||||
const video = await this.video.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
if (!video) {
|
||||
throw new NotFoundException('ویدئوی مورد نظر یافت نشد');
|
||||
}
|
||||
if (incrementView) {
|
||||
await this.prisma.video.update({
|
||||
await this.video.update({
|
||||
where: { id },
|
||||
data: { viewsCount: { increment: 1 } },
|
||||
}).catch(() => {});
|
||||
@@ -61,7 +65,7 @@ export class VideosService {
|
||||
}
|
||||
|
||||
async create(dto: CreateVideoDto) {
|
||||
return this.prisma.video.create({
|
||||
return this.video.create({
|
||||
data: {
|
||||
title: dto.title,
|
||||
doctor: dto.doctor,
|
||||
@@ -76,7 +80,7 @@ export class VideosService {
|
||||
|
||||
async update(id: string, dto: Partial<CreateVideoDto>) {
|
||||
await this.findOne(id);
|
||||
return this.prisma.video.update({
|
||||
return this.video.update({
|
||||
where: { id },
|
||||
data: {
|
||||
title: dto.title,
|
||||
@@ -92,7 +96,7 @@ export class VideosService {
|
||||
|
||||
async remove(id: string) {
|
||||
await this.findOne(id);
|
||||
return this.prisma.video.delete({
|
||||
return this.video.delete({
|
||||
where: { id },
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user