Skip to content

Commit

Permalink
Merge pull request #44 from Greenstand/pr-36
Browse files Browse the repository at this point in the history
Pr 36
  • Loading branch information
Mohmn authored Aug 16, 2024
2 parents 4f23f3c + c56f785 commit dcd2517
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
17 changes: 16 additions & 1 deletion apps/like/src/prisma/prisma.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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>(PrismaService);
Expand Down
14 changes: 7 additions & 7 deletions apps/like/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ import {
Get,
Param,
ParseIntPipe,
ValidationPipe
ValidationPipe,
} from '@nestjs/common';
import { UserService } from './user.service';
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',
Expand All @@ -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);
}


}
10 changes: 5 additions & 5 deletions apps/like/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3'
services:
postgres:
image: postgres:12
ports:
- 5432:5432
volumes:
- ~/apps/postgres:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=easypassword
- POSTGRES_USER=easyuser
- POSTGRES_DB=treetracker-like

0 comments on commit dcd2517

Please sign in to comment.