generated from kir-dev/next-nest-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/event-validation
- Loading branch information
Showing
13 changed files
with
590 additions
and
332 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
apps/backend/prisma/migrations/20240529163137_add_username/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.