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

Balint #4

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
7 changes: 7 additions & 0 deletions .env
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"
18 changes: 18 additions & 0 deletions apps/backend/prisma/migrations/20240706165250_init/migration.sql
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");
8 changes: 5 additions & 3 deletions apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ datasource db {
}

model User {
id String @id @default(cuid())
// authSchId String @unique
email String @unique
id Int @id @default(autoincrement())
sureName String
foreName String
password String @unique
email String @unique
}
3 changes: 2 additions & 1 deletion apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { PrismaModule } from 'nestjs-prisma';

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

@Module({
imports: [ConfigModule.forRoot(), PrismaModule.forRoot({ isGlobal: true })],
imports: [ConfigModule.forRoot(), PrismaModule.forRoot({ isGlobal: true }), UserModule],
controllers: [AppController],
providers: [AppService],
})
Expand Down
40 changes: 40 additions & 0 deletions apps/backend/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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(user);
}
}
1 change: 1 addition & 0 deletions apps/backend/src/sprint/dto/create-sprint.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class CreateSprintDto {}
4 changes: 4 additions & 0 deletions apps/backend/src/sprint/dto/update-sprint.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';

Check failure on line 1 in apps/backend/src/sprint/dto/update-sprint.dto.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

Run autofix to sort these imports!
import { CreateSprintDto } from './create-sprint.dto';

export class UpdateSprintDto extends PartialType(CreateSprintDto) {}
1 change: 1 addition & 0 deletions apps/backend/src/sprint/entities/sprint.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class Sprint {}
34 changes: 34 additions & 0 deletions apps/backend/src/sprint/sprint.controller.ts
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';

Check failure on line 1 in apps/backend/src/sprint/sprint.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

Run autofix to sort these imports!
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);

Check failure on line 22 in apps/backend/src/sprint/sprint.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

use `Number(id)` instead
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateSprintDto: UpdateSprintDto) {
return this.sprintService.update(+id, updateSprintDto);

Check failure on line 27 in apps/backend/src/sprint/sprint.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

use `Number(id)` instead
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.sprintService.remove(+id);

Check failure on line 32 in apps/backend/src/sprint/sprint.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

use `Number(id)` instead
}
}
9 changes: 9 additions & 0 deletions apps/backend/src/sprint/sprint.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';

Check failure on line 1 in apps/backend/src/sprint/sprint.module.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

Run autofix to sort these imports!
import { SprintService } from './sprint.service';
import { SprintController } from './sprint.controller';

@Module({
controllers: [SprintController],
providers: [SprintService],
})
export class SprintModule {}
27 changes: 27 additions & 0 deletions apps/backend/src/sprint/sprint.service.ts
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) {

Check failure on line 8 in apps/backend/src/sprint/sprint.service.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

'createSprintDto' is defined but never used
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) {

Check failure on line 20 in apps/backend/src/sprint/sprint.service.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

'updateSprintDto' is defined but never used
return `This action updates a #${id} sprint`;
}

remove(id: number) {
return `This action removes a #${id} sprint`;
}
}
7 changes: 7 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,7 @@
export class CreateUserDto {
surName: string;
foreName: string;
password: string;
email: string;
//TODO: user adatelemei
}
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/mapped-types';

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

export class UpdateUserDto extends PartialType(CreateUserDto) {}
1 change: 1 addition & 0 deletions apps/backend/src/user/entities/user.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class User {}
21 changes: 21 additions & 0 deletions apps/backend/src/user/user.controller.spec.ts
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();
});
});
45 changes: 45 additions & 0 deletions apps/backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
import { User } from '@prisma/client';
import { AuthService } from 'src/auth/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.userService.create(createUserDto);
}

@Post('login')
async logIn(@Body() loginDto: { email: string; passWord: string }): Promise<User> {
return await this.authService.signIn(loginDto.email, loginDto.passWord);
}

@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));
}
}
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 {}
19 changes: 19 additions & 0 deletions apps/backend/src/user/user.service.spec.ts
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();
});
});
33 changes: 33 additions & 0 deletions apps/backend/src/user/user.service.ts
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 } });
}
}
Loading
Loading