From 8d84b2d74393365f6647e7de8bc65cc6b715d984 Mon Sep 17 00:00:00 2001 From: Shpendiiiii Date: Wed, 31 Jul 2024 11:12:37 +0200 Subject: [PATCH 1/4] created docker compose --- docker-compose.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 docker-compose.yml 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 From 7c6f59dcc77f3bcb55c0abf262edb4c5b53e1ad7 Mon Sep 17 00:00:00 2001 From: Shpendiiiii Date: Wed, 31 Jul 2024 11:32:20 +0200 Subject: [PATCH 2/4] formatting and fixing ConfigModule error from test --- apps/like/src/prisma/prisma.service.spec.ts | 2 ++ apps/like/src/user/user.controller.ts | 14 +++++++------- apps/like/src/user/user.service.ts | 10 +++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/apps/like/src/prisma/prisma.service.spec.ts b/apps/like/src/prisma/prisma.service.spec.ts index a68cb9e..407157f 100644 --- a/apps/like/src/prisma/prisma.service.spec.ts +++ b/apps/like/src/prisma/prisma.service.spec.ts @@ -1,5 +1,6 @@ import { Test, TestingModule } from '@nestjs/testing'; import { PrismaService } from './prisma.service'; +import { ConfigModule } from '@nestjs/config'; describe('PrismaService', () => { let service: PrismaService; @@ -7,6 +8,7 @@ describe('PrismaService', () => { beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ providers: [PrismaService], + imports: [ConfigModule] }).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({ From 456e9d695e9f6fcf44dd26dd069d29211b055758 Mon Sep 17 00:00:00 2001 From: Shpendiiiii Date: Wed, 31 Jul 2024 11:39:21 +0200 Subject: [PATCH 3/4] mocking connection string --- apps/like/src/prisma/prisma.service.spec.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/like/src/prisma/prisma.service.spec.ts b/apps/like/src/prisma/prisma.service.spec.ts index 407157f..7b5786a 100644 --- a/apps/like/src/prisma/prisma.service.spec.ts +++ b/apps/like/src/prisma/prisma.service.spec.ts @@ -1,14 +1,27 @@ import { Test, TestingModule } from '@nestjs/testing'; import { PrismaService } from './prisma.service'; -import { ConfigModule } from '@nestjs/config'; +import { ConfigModule, ConfigService } from '@nestjs/config'; describe('PrismaService', () => { let service: PrismaService; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ - providers: [PrismaService], - imports: [ConfigModule] + 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); From c56f785a96c8361b8b689abdbe9f25d9658efcb3 Mon Sep 17 00:00:00 2001 From: Mohmn Date: Fri, 16 Aug 2024 22:09:46 +0530 Subject: [PATCH 4/4] fix: use docker version 12 and and version in compose file [skip-ci] --- docker-compose.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index f269732..69e15f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,7 @@ +version: '3' services: postgres: - image: postgres:latest + image: postgres:12 ports: - 5432:5432 volumes: