diff --git a/apps/like/src/prisma/prisma.service.spec.ts b/apps/like/src/prisma/prisma.service.spec.ts index a68cb9e..7b5786a 100644 --- a/apps/like/src/prisma/prisma.service.spec.ts +++ b/apps/like/src/prisma/prisma.service.spec.ts @@ -1,12 +1,27 @@ import { Test, TestingModule } from '@nestjs/testing'; import { PrismaService } from './prisma.service'; +import { ConfigModule, ConfigService } from '@nestjs/config'; describe('PrismaService', () => { let service: PrismaService; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ - providers: [PrismaService], + imports: [ConfigModule], + providers: [ + PrismaService, + { + provide: ConfigService, + useValue: { + get: jest.fn().mockImplementation((key: string) => { + if (key === 'DATABASE_URL') { + return 'mock_database_url'; // Provide a mock value for DATABASE_URL + } + return null; + }), + }, + }, + ], }).compile(); service = module.get(PrismaService); diff --git a/apps/like/src/user/user.controller.ts b/apps/like/src/user/user.controller.ts index a4dc298..c74b2ab 100644 --- a/apps/like/src/user/user.controller.ts +++ b/apps/like/src/user/user.controller.ts @@ -5,7 +5,7 @@ import { Get, Param, ParseIntPipe, - ValidationPipe + ValidationPipe, } from '@nestjs/common'; import { UserService } from './user.service'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @@ -13,11 +13,10 @@ import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('user') @ApiTags('user') export class UserController { - constructor(private userService: UserService) { - } + constructor(private userService: UserService) {} @Get(':user_uuid/types/:type_uuid') - @ApiOperation({ summary: 'Get user likes on type by user id'}) + @ApiOperation({ summary: 'Get user likes on type by user id' }) @ApiResponse({ status: 200, description: 'Successfully retrieved user activities', @@ -26,9 +25,10 @@ export class UserController { status: 404, description: 'Not Found', }) - async handleGetUserLikes(@Param('user_uuid') user_uuid: string, @Param('type_uuid') type_uuid: string) { + async handleGetUserLikes( + @Param('user_uuid') user_uuid: string, + @Param('type_uuid') type_uuid: string + ) { return this.userService.getUserLikesOnType(user_uuid, type_uuid); } - - } diff --git a/apps/like/src/user/user.service.ts b/apps/like/src/user/user.service.ts index 091236d..c4219cb 100644 --- a/apps/like/src/user/user.service.ts +++ b/apps/like/src/user/user.service.ts @@ -6,14 +6,14 @@ import { PrismaService } from '../prisma/prisma.service'; export class UserService { constructor(private prismaService: PrismaService) {} - async getUserLikesOnType(user_id_: string, type_id: string){ + async getUserLikesOnType(user_id_: string, type_id: string) { const user_id = Number(user_id_); return await this.prismaService.like.findMany({ - where: {user_id, type_id}, + where: { user_id, type_id }, include: { - Type: true - } - }) + Type: true, + }, + }); } // async createUser(createUserDto: CreateUserDto) { // const existedUser = await prisma.user.findFirst({ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f269732 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +services: + postgres: + image: postgres:latest + ports: + - 5432:5432 + volumes: + - ~/apps/postgres:/var/lib/postgresql/data + environment: + - POSTGRES_PASSWORD=easypassword + - POSTGRES_USER=easyuser + - POSTGRES_DB=treetracker-like