generated from kir-dev/next-nest-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* done with loginscreen * . * rename files * done with loginscreen * rename files * user resource legenerálása * Registration form on the way * user a jo helyre * prisma file irkalasa * HomePage, routing, RegistrationPage update * schema migartion and crud * Cors in backend * createUserDTO * fetch path update * CORS update, GreetingsPage, Navbar, fetch path update * db schema changes * HomePage, AfteLogin page update * sto-s * javitas * ureate uset dto update * update-user-dto update * merge-hez * sign in, sign up methods * Navbar, AfterLogin, Reporting periods, Home page * hibajavitas * compare problem fixing * CurrentJobs, Login update * user controllerben login fv * ugyeskedes * everything works --------- Co-authored-by: Mikola Bálint István <[email protected]> Co-authored-by: Trisztán Piller <[email protected]>
- Loading branch information
1 parent
31c9a83
commit 666842b
Showing
44 changed files
with
12,691 additions
and
840 deletions.
There are no files selected for viewing
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,7 @@ | ||
# Environment variables declared in this file are automatically made available to Prisma. | ||
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema | ||
|
||
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. | ||
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings | ||
|
||
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public" |
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
18 changes: 18 additions & 0 deletions
18
apps/backend/prisma/migrations/20240706165250_init/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,18 @@ | ||
/* | ||
Warnings: | ||
- The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint. | ||
- The `id` column on the `User` table would be dropped and recreated. This will lead to data loss if there is data in the column. | ||
- A unique constraint covering the columns `[password]` on the table `User` will be added. If there are existing duplicate values, this will fail. | ||
- Added the required column `password` to the `User` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "User" DROP CONSTRAINT "User_pkey", | ||
ADD COLUMN "password" TEXT NOT NULL, | ||
DROP COLUMN "id", | ||
ADD COLUMN "id" SERIAL NOT NULL, | ||
ADD CONSTRAINT "User_pkey" PRIMARY KEY ("id"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_password_key" ON "User"("password"); |
16 changes: 16 additions & 0 deletions
16
apps/backend/prisma/migrations/20240714182617_/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,16 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[confirmPassword]` on the table `User` will be added. If there are existing duplicate values, this will fail. | ||
- Added the required column `confirmPassword` to the `User` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `firstname` to the `User` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `lastname` to the `User` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "User" ADD COLUMN "confirmPassword" TEXT NOT NULL, | ||
ADD COLUMN "firstname" TEXT NOT NULL, | ||
ADD COLUMN "lastname" TEXT NOT NULL; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_confirmPassword_key" ON "User"("confirmPassword"); |
14 changes: 14 additions & 0 deletions
14
apps/backend/prisma/migrations/20240909163326_removeconfirmpassword/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,14 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `confirmPassword` on the `User` table. All the data in the column will be lost. | ||
*/ | ||
-- DropIndex | ||
DROP INDEX "User_confirmPassword_key"; | ||
|
||
-- DropIndex | ||
DROP INDEX "User_password_key"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "User" DROP COLUMN "confirmPassword"; |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class CreateSprintDto {} |
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,4 @@ | ||
import { PartialType } from '@nestjs/mapped-types'; | ||
import { CreateSprintDto } from './create-sprint.dto'; | ||
|
||
export class UpdateSprintDto extends PartialType(CreateSprintDto) {} |
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 @@ | ||
export class Sprint {} |
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,34 @@ | ||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; | ||
import { SprintService } from './sprint.service'; | ||
import { CreateSprintDto } from './dto/create-sprint.dto'; | ||
import { UpdateSprintDto } from './dto/update-sprint.dto'; | ||
|
||
@Controller('sprint') | ||
export class SprintController { | ||
constructor(private readonly sprintService: SprintService) {} | ||
|
||
@Post() | ||
create(@Body() createSprintDto: CreateSprintDto) { | ||
return this.sprintService.create(createSprintDto); | ||
} | ||
|
||
@Get() | ||
findAll() { | ||
return this.sprintService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
findOne(@Param('id') id: string) { | ||
return this.sprintService.findOne(+id); | ||
} | ||
|
||
@Patch(':id') | ||
update(@Param('id') id: string, @Body() updateSprintDto: UpdateSprintDto) { | ||
return this.sprintService.update(+id, updateSprintDto); | ||
} | ||
|
||
@Delete(':id') | ||
remove(@Param('id') id: string) { | ||
return this.sprintService.remove(+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,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { SprintService } from './sprint.service'; | ||
import { SprintController } from './sprint.controller'; | ||
|
||
@Module({ | ||
controllers: [SprintController], | ||
providers: [SprintService], | ||
}) | ||
export class SprintModule {} |
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,27 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { CreateSprintDto } from './dto/create-sprint.dto'; | ||
import { UpdateSprintDto } from './dto/update-sprint.dto'; | ||
|
||
@Injectable() | ||
export class SprintService { | ||
create(createSprintDto: CreateSprintDto) { | ||
return 'This action adds a new sprint'; | ||
} | ||
|
||
findAll() { | ||
return `This action returns all sprint`; | ||
} | ||
|
||
findOne(id: number) { | ||
return `This action returns a #${id} sprint`; | ||
} | ||
|
||
update(id: number, updateSprintDto: UpdateSprintDto) { | ||
return `This action updates a #${id} sprint`; | ||
} | ||
|
||
remove(id: number) { | ||
return `This action removes a #${id} sprint`; | ||
} | ||
} |
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,45 @@ | ||
import { Injectable, UnauthorizedException } from '@nestjs/common'; | ||
import * as bcrypt from 'bcrypt'; | ||
import { CreateUserDto } from 'src/user/dto/create-user.dto'; | ||
import { UserService } from 'src/user/user.service'; | ||
|
||
@Injectable() | ||
export class AuthService { | ||
saltOrRounds: number = 10; | ||
|
||
constructor(private usersService: UserService) {} | ||
|
||
async signIn(email, pass) { | ||
const user = await this.usersService.findOneByEMail(email); | ||
|
||
if (!user) { | ||
throw new UnauthorizedException(); | ||
} | ||
|
||
const isMatch = await bcrypt.compare(pass, user?.password); | ||
|
||
if (!isMatch) { | ||
throw new UnauthorizedException(); | ||
} | ||
|
||
return user; | ||
} | ||
|
||
async signUp(payload: CreateUserDto) { | ||
const hashPass = await bcrypt.hash(payload.password, this.saltOrRounds); | ||
|
||
const user = { | ||
surName: payload.surName, | ||
foreName: payload.foreName, | ||
password: hashPass, | ||
email: payload.email, | ||
}; | ||
|
||
await this.usersService.create({ | ||
email: user.email, | ||
password: user.password, | ||
firstname: user.foreName, | ||
lastname: user.surName, | ||
}); | ||
} | ||
} |
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,7 @@ | ||
export class CreateUserDto { | ||
surName: string; | ||
foreName: string; | ||
password: string; | ||
email: string; | ||
//TODO: user adatelemei | ||
} |
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/mapped-types'; | ||
|
||
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 @@ | ||
export class User {} |
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,21 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
|
||
import { UserController } from './user.controller'; | ||
import { UserService } from './user.service'; | ||
|
||
describe('UserController', () => { | ||
let controller: UserController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [UserController], | ||
providers: [UserService], | ||
}).compile(); | ||
|
||
controller = module.get<UserController>(UserController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
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,49 @@ | ||
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'; | ||
import { User } from '@prisma/client'; | ||
import { AuthService } from 'src/user/auth.service'; | ||
|
||
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, | ||
private readonly authService: AuthService | ||
) {} | ||
|
||
@Post() | ||
create(@Body() createUserDto: CreateUserDto) { | ||
return this.authService.signUp(createUserDto); | ||
} | ||
|
||
@Post('login') | ||
async logIn(@Body() loginDto: { email: string; password: string }): Promise<User & { isRegistered: boolean }> { | ||
const user = await this.authService.signIn(loginDto.email, loginDto.password); | ||
return { | ||
...user, | ||
isRegistered: user ? true : false, | ||
}; | ||
} | ||
|
||
@Get() | ||
findAll() { | ||
return this.userService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
findOne(@Param('id') id: string) { | ||
return this.userService.findOne(Number(id)); | ||
} | ||
|
||
@Patch(':id') | ||
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) { | ||
return this.userService.update(Number(id), updateUserDto); | ||
} | ||
|
||
@Delete(':id') | ||
remove(@Param('id') id: string) { | ||
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,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { AuthService } from './auth.service'; | ||
import { UserController } from './user.controller'; | ||
import { UserService } from './user.service'; | ||
|
||
@Module({ | ||
controllers: [UserController], | ||
providers: [UserService, AuthService], | ||
}) | ||
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,19 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
|
||
import { UserService } from './user.service'; | ||
|
||
describe('UserService', () => { | ||
let service: UserService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [UserService], | ||
}).compile(); | ||
|
||
service = module.get<UserService>(UserService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
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,33 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Prisma, User } from '@prisma/client'; | ||
import { PrismaService } from 'nestjs-prisma'; | ||
|
||
@Injectable() | ||
export class UserService { | ||
constructor(private readonly prisma: PrismaService) {} | ||
|
||
async create(data: Prisma.UserCreateInput): Promise<User> { | ||
//Itt kell megoldani a jelszó hashelését (asszem) | ||
return await this.prisma.user.create({ data }); | ||
} | ||
|
||
async findAll(): Promise<User[]> { | ||
return await this.prisma.user.findMany(); | ||
} | ||
|
||
findOne(id: number): Promise<User> { | ||
return this.prisma.user.findUnique({ where: { id } }); | ||
} | ||
|
||
findOneByEMail(email: string) { | ||
return this.prisma.user.findUnique({ where: { email } }); | ||
} | ||
|
||
async update(id: number, data: Prisma.UserUpdateInput) { | ||
return await this.prisma.user.update({ where: { id }, data }); | ||
} | ||
|
||
async remove(id: number) { | ||
return await this.prisma.user.delete({ where: { 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
Oops, something went wrong.