Skip to content

Commit

Permalink
Merge branch 'main' into feature/event-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
DankaMarci committed Sep 27, 2024
2 parents ef883f1 + b310b4f commit 59eadf9
Show file tree
Hide file tree
Showing 13 changed files with 590 additions and 332 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:
- A unique constraint covering the columns `[username]` on the table `User` will be added. If there are existing duplicate values, this will fail.
- Added the required column `username` to the `User` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "User" ADD COLUMN "username" TEXT NOT NULL;

-- CreateIndex
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
3 changes: 2 additions & 1 deletion apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ enum Role {

model User {
id Int @id @default(autoincrement())
authSchId String //Ez majd a belepeshez kell
authSchId String // Ez majd a belepeshez kell
email String @unique
username String @unique
profilePicture String?
groups GroupMembers[]
events Event[]
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { PrismaModule } from 'nestjs-prisma';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { EventModule } from './event/event.module';
import { UserModule } from './user/user.module';

@Module({
imports: [PrismaModule.forRoot({ isGlobal: true }), EventModule],
imports: [UserModule, PrismaModule.forRoot({ isGlobal: true })],
controllers: [AppController],
providers: [AppService],
})
Expand Down
10 changes: 0 additions & 10 deletions apps/backend/src/event/event.module.ts

This file was deleted.

5 changes: 5 additions & 0 deletions apps/backend/src/user/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { OmitType } from '@nestjs/swagger';

import { User } from '../entities/user.entity';

export class CreateUserDto extends OmitType(User, ['id']) {}
5 changes: 5 additions & 0 deletions apps/backend/src/user/dto/update-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { PartialType } from '@nestjs/swagger';

import { CreateUserDto } from './create-user.dto';

export class UpdateUserDto extends PartialType(CreateUserDto) {}
23 changes: 23 additions & 0 deletions apps/backend/src/user/entities/user.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsString, Min } from 'class-validator';

export class User {
@IsString()
@IsNotEmpty()
username: string;

@IsInt()
@Min(1)
id: number;

@IsString()
@IsNotEmpty()
authSchId: string;

@IsNotEmpty()
@IsEmail()
email: string;

@IsString()
@IsOptional()
profilePicture: string;
}
35 changes: 35 additions & 0 deletions apps/backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';

import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { UserService } from './user.service';

@Controller('user')
export class UserController {
constructor(private readonly userService: UserService) {}

@Post()
create(@Body() data: CreateUserDto) {
return this.userService.create(data);
}

@Get()
findAll() {
return this.userService.findAll();
}

@Get(':id')
findOne(@Param('id') id: number) {
return this.userService.findOne(Number(id));
}

@Patch(':id')
update(@Param('id') id: number, @Body() data: UpdateUserDto) {
return this.userService.update(Number(id), data);
}

@Delete(':id')
remove(@Param('id') id: number) {
return this.userService.remove(Number(id));
}
}
10 changes: 10 additions & 0 deletions apps/backend/src/user/user.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';

import { UserController } from './user.controller';
import { UserService } from './user.service';

@Module({
controllers: [UserController],
providers: [UserService],
})
export class UserModule {}
52 changes: 52 additions & 0 deletions apps/backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { User } from '@prisma/client';
import { PrismaService } from 'nestjs-prisma';

import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';

@Injectable()
export class UserService {
constructor(private readonly prisma: PrismaService) {}
async create(data: CreateUserDto): Promise<User> {
try {
const newUser = await this.prisma.user.create({ data: data });
return newUser;
} catch (error) {
throw new Error(`User not created ${error.message}`);
}
}

async findOne(id: number): Promise<User> {
try {
const user = await this.prisma.user.findUnique({ where: { id } });
return user;
} catch (error) {
throw new NotFoundException(`User with ID ${id} not found ${error.message}`);
}
}

findAll(): Promise<User[]> {
try {
return this.prisma.user.findMany();
} catch (error) {
throw new NotFoundException(`Users not found ${error.message}`);
}
}

async update(id: number, data: UpdateUserDto): Promise<User> {
try {
return await this.prisma.user.update({ where: { id }, data: data });
} catch (error) {
throw new NotFoundException(`User with ID ${id} not found ${error.message}`);
}
}

async remove(id: number): Promise<User> {
try {
return await this.prisma.user.delete({ where: { id } });
} catch (error) {
throw new NotFoundException(`User with ID ${id} not found ${error.message}`);
}
}
}
7 changes: 4 additions & 3 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
"lint": "next lint"
},
"dependencies": {
"@radix-ui/react-switch": "^1.1.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"lucide-react": "^0.372.0",
"next": "14.2.2",
"next": "14.2.10",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwind-merge": "^2.3.0",
Expand All @@ -25,9 +26,9 @@
"@types/node": "^20.12.7",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"eslint-plugin-react": "^7.34.1",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5",
"eslint-plugin-react": "^7.34.1"
"typescript": "^5.4.5"
}
}
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@
},
"devDependencies": {
"eslint": "^8.57.0",
"eslint-config-next": "14.2.2",
"eslint-config-next": "14.2.3",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-simple-import-sort": "^12.1.0",
"prettier": "^3.2.5"
"prettier": "^3.3.0"
},
"workspaces": [
"apps/*"
]
],
"dependencies": {
"@nestjs/swagger": "^7.3.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1"
}
}
Loading

0 comments on commit 59eadf9

Please sign in to comment.