Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr 36 #44

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading