Skip to content

Commit

Permalink
added login mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Berat Genç authored and Berat Genç committed Jan 18, 2024
1 parent 18602d8 commit 685ef5c
Show file tree
Hide file tree
Showing 18 changed files with 307 additions and 79 deletions.
102 changes: 101 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
"@nestjs/platform-express": "^10.0.0",
"@prisma/client": "^5.8.0",
"axios": "^1.6.5",
"connect-redis": "^7.1.0",
"dotenv": "^16.3.1",
"express-session": "^1.17.3",
"prisma": "^5.8.0",
"redis": "^4.6.12",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"zustand": "^4.4.7"
Expand All @@ -37,7 +39,7 @@
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/express": "^4.17.21",
"@types/express-session": "^1.17.10",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
Expand Down
23 changes: 0 additions & 23 deletions prisma/migrations/20240114145643_init/migration.sql

This file was deleted.

8 changes: 0 additions & 8 deletions prisma/migrations/20240115211555_priority/migration.sql

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
/*
Warnings:
- You are about to drop the `Post` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `User` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE `Post` DROP FOREIGN KEY `Post_authorId_fkey`;

-- DropTable
DROP TABLE `Post`;

-- DropTable
DROP TABLE `User`;

-- CreateTable
CREATE TABLE `Employee` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`username` VARCHAR(191) NOT NULL,
`email` VARCHAR(191) NOT NULL,
`password` VARCHAR(191) NOT NULL,

UNIQUE INDEX `Employee_email_key`(`email`),
PRIMARY KEY (`id`)
Expand Down Expand Up @@ -46,7 +31,7 @@ CREATE TABLE `Project` (
`name` VARCHAR(191) NOT NULL,
`description` VARCHAR(191) NULL,
`teamId` INTEGER NOT NULL,
`employeeId` INTEGER NOT NULL,
`employeeId` INTEGER NULL,

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Expand All @@ -56,6 +41,7 @@ CREATE TABLE `Task` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`title` VARCHAR(191) NOT NULL,
`description` VARCHAR(191) NULL,
`priority` VARCHAR(191) NOT NULL,
`completed` BOOLEAN NOT NULL DEFAULT false,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updatedAt` DATETIME(3) NOT NULL,
Expand All @@ -75,7 +61,7 @@ ALTER TABLE `EmployeeOnTeams` ADD CONSTRAINT `EmployeeOnTeams_employeeId_fkey` F
ALTER TABLE `Project` ADD CONSTRAINT `Project_teamId_fkey` FOREIGN KEY (`teamId`) REFERENCES `Team`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Project` ADD CONSTRAINT `Project_employeeId_fkey` FOREIGN KEY (`employeeId`) REFERENCES `Employee`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `Project` ADD CONSTRAINT `Project_employeeId_fkey` FOREIGN KEY (`employeeId`) REFERENCES `Employee`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Task` ADD CONSTRAINT `Task_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `Employee`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
Expand Down
3 changes: 2 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ generator client {

datasource db {
provider = "mysql"
url = "mysql://root:ysxgdil0@35.195.248.72:3306/manager"
url = "mysql://root:ysxgdil0@35.195.248.72:3306/taskManagerp"
}

model Employee {
id Int @id @default(autoincrement())
username String
email String @unique
password String
teams EmployeeOnTeams[]
tasks Task[]
projects Project[]
Expand Down
27 changes: 16 additions & 11 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { DatabaseModule } from './database/database.module';
import { EmployeeModule } from './employee/employee.module';
import { TasksModule } from './tasks/tasks.module';
import { TeamModule } from './team/team.module';
import { ProjectModule } from './project/project.module';

import { Module } from '@nestjs/common'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import { DatabaseModule } from './database/database.module'
import { EmployeeModule } from './employee/employee.module'
import { TasksModule } from './tasks/tasks.module'
import { TeamModule } from './team/team.module'
import { ProjectModule } from './project/project.module'

@Module({
imports: [DatabaseModule, EmployeeModule, TasksModule, TeamModule, ProjectModule],
imports: [
DatabaseModule,
EmployeeModule,
TasksModule,
TeamModule,
ProjectModule
],
controllers: [AppController],
providers: [AppService],
providers: [AppService]
})
export class AppModule {}
37 changes: 33 additions & 4 deletions src/employee/employee.controller.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
// @ts-nocheck
import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Delete
Delete,
Res,
Req
} from '@nestjs/common'
import { EmployeeService } from './employee.service'
import { Prisma } from '@prisma/client'
import { Request } from 'express'

@Controller('employee')
export class EmployeeController {
constructor(private readonly employeeService: EmployeeService) {}

@Post()
create(@Body() createEmployeeDto: Prisma.EmployeeCreateInput) {
create(
@Body() createEmployeeDto: Prisma.EmployeeCreateInput,
@Req() request: Request
) {
request.session.userMail = createEmployeeDto.email
return this.employeeService.create(createEmployeeDto)
}

@Get('/getUserId')
findUserId(@Req() request: Request) {
if (request.session.userMail) {
const mailAdress = request.session.userMail
return this.employeeService.findUserId(mailAdress)
} else {
return 'No access'
}
}

// login(
// @Body() createEmployeeDto: Prisma.EmployeeCreateInput,
// @Req() request: Request
// ) {
// return this.employeeService.login()
// }

@Get()
findAll() {
return this.employeeService.findAll()
Expand All @@ -30,7 +55,7 @@ export class EmployeeController {
}

@Get(':id')
findOne(@Param('id') id: string) {
findOne(@Param('id') id: string, @Req() request: Request) {
return this.employeeService.findOne(+id)
}

Expand All @@ -49,6 +74,10 @@ export class EmployeeController {

@Delete(':id')
remove(@Param('id') id: string) {
return this.employeeService.remove(+id)
return this.employeeService.remove()
}
@Delete('/remove-all')
remove() {
return this.employeeService.removeAll()
}
}
Loading

0 comments on commit 685ef5c

Please sign in to comment.