Skip to content

Commit

Permalink
chore: Remove prisma client from service
Browse files Browse the repository at this point in the history
  • Loading branch information
Rowan-Paul committed Jul 9, 2024
1 parent 7bf55ea commit fd0884e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion apps/api/src/movies/movies.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class MoviesController {

@Get()
findAll() {
return this.moviesService.findMany({});
return this.moviesService.findMany();
}

@Get(':id')
Expand Down
36 changes: 12 additions & 24 deletions apps/api/src/movies/movies.service.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,34 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from 'src/prisma/prisma.service';

import { Movies, Prisma } from '@prisma/client';
import { Movies } from './entities/movies.entity';
import { CreateMoviesDto } from './dto/create-movies.dto';
import { UpdateMoviesDto } from './dto/update-movies.dto';

@Injectable()
export class MoviesService {
constructor(private prisma: PrismaService) {}

async findUnique(
moviesWhereUniqueInput: Prisma.MoviesWhereUniqueInput,
): Promise<Movies | null> {
async findUnique(moviesWhereUniqueInput: {
id: number;
}): Promise<Movies | null> {
return this.prisma.movies.findUnique({
where: moviesWhereUniqueInput,
});
}

async findMany(params: {
skip?: number;
take?: number;
cursor?: Prisma.MoviesWhereUniqueInput;
where?: Prisma.MoviesWhereInput;
orderBy?: Prisma.MoviesOrderByWithRelationInput;
}): Promise<Movies[]> {
const { skip, take, cursor, where, orderBy } = params;
return this.prisma.movies.findMany({
skip,
take,
cursor,
where,
orderBy,
});
async findMany(): Promise<Movies[]> {
return this.prisma.movies.findMany();
}

async create(data: Prisma.MoviesCreateInput): Promise<Movies> {
async create(data: CreateMoviesDto): Promise<Movies> {
return this.prisma.movies.create({
data,
});
}

async update(params: {
where: Prisma.MoviesWhereUniqueInput;
data: Prisma.MoviesUpdateInput;
where: { id: number };
data: UpdateMoviesDto;
}): Promise<Movies> {
const { data, where } = params;
return this.prisma.movies.update({
Expand All @@ -49,7 +37,7 @@ export class MoviesService {
});
}

async delete(where: Prisma.MoviesWhereUniqueInput): Promise<Movies> {
async delete(where: { id: number }): Promise<Movies> {
return this.prisma.movies.delete({
where,
});
Expand Down

0 comments on commit fd0884e

Please sign in to comment.