diff --git a/app/backend/src/auth/auth.controller.ts b/app/backend/src/auth/auth.controller.ts index 3b333d56..e98c1c6a 100644 --- a/app/backend/src/auth/auth.controller.ts +++ b/app/backend/src/auth/auth.controller.ts @@ -39,9 +39,15 @@ export class AuthController { return this.authService.resetPassword(resetPasswordDto); } - @UseGuards(AuthGuard, VerificationGuard) + @UseGuards(AuthGuard) @Get('me') getMe(@Req() request: any) { return this.authService.getMe(request.user.id); } + + @UseGuards(AuthGuard, VerificationGuard) + @Get('verified-me') + getVerifiedMe(@Req() request: any) { + return this.authService.getMe(request.user.id); + } } diff --git a/app/backend/src/poll/dto/create-poll.dto.ts b/app/backend/src/poll/dto/create-poll.dto.ts index b0477b87..2cce5cc6 100644 --- a/app/backend/src/poll/dto/create-poll.dto.ts +++ b/app/backend/src/poll/dto/create-poll.dto.ts @@ -1,17 +1,7 @@ import { ApiProperty } from '@nestjs/swagger'; import { IsArray, IsNotEmpty, IsString, IsUUID } from 'class-validator'; -import { Option } from '../../option/entities/option.entity'; -import { Tag } from '../../tag/entities/tag.entity'; -import { User } from '../../user/entities/user.entity'; export class CreatePollDto { - @ApiProperty({ - example: '3dac5059-03bf-45a2-b0ed-273c75aafedc', - }) - @IsNotEmpty() - @IsUUID() - creator: User; - @ApiProperty({ example: 'Who will be the champion of the Turkish Football Super League in the 2023-2024 Season?', diff --git a/app/backend/src/poll/entities/poll.entity.ts b/app/backend/src/poll/entities/poll.entity.ts index 03c8c22b..5c235452 100644 --- a/app/backend/src/poll/entities/poll.entity.ts +++ b/app/backend/src/poll/entities/poll.entity.ts @@ -27,11 +27,6 @@ export class Poll { @JoinColumn() // Specifying the foreign key column creator: Relation; - //@ManyToOne(() => User) // Establishing the many-to-one relationship - //@JoinColumn({ name: 'id' }) - @Column({ nullable: true }) - moderator: string; - @ManyToMany(() => Tag) @JoinTable() tags: Relation; diff --git a/app/backend/src/poll/poll.controller.ts b/app/backend/src/poll/poll.controller.ts index 6fc7876f..b91af3f1 100644 --- a/app/backend/src/poll/poll.controller.ts +++ b/app/backend/src/poll/poll.controller.ts @@ -6,17 +6,27 @@ import { Param, Delete, ParseUUIDPipe, + UseGuards, + Req, } from '@nestjs/common'; import { PollService } from './poll.service'; import { CreatePollDto } from './dto/create-poll.dto'; +import { ApiBearerAuth } from '@nestjs/swagger'; +import { AuthGuard } from '../auth/guards/auth.guard'; +import { VerificationGuard } from '../auth/guards/verification.guard'; +@ApiBearerAuth() @Controller('poll') export class PollController { constructor(private readonly pollService: PollService) {} + @UseGuards(AuthGuard, VerificationGuard) @Post() - create(@Body() createPollDto: CreatePollDto) { - return this.pollService.createPoll(createPollDto); + create(@Body() createPollDto: CreatePollDto, @Req() request: any) { + return this.pollService.createPoll({ + ...createPollDto, + creator: request.user.id, + }); } @Get() diff --git a/app/backend/src/poll/poll.module.ts b/app/backend/src/poll/poll.module.ts index f6c9095f..4e310842 100644 --- a/app/backend/src/poll/poll.module.ts +++ b/app/backend/src/poll/poll.module.ts @@ -5,12 +5,14 @@ import { Poll } from './entities/poll.entity'; import { Option } from '../option/entities/option.entity'; // Import Option entity import { Tag } from '../tag/entities/tag.entity'; // Import Tag entity import { TypeOrmModule } from '@nestjs/typeorm'; +import { UserService } from '../user/user.service'; +import { User } from '../user/entities/user.entity'; @Module({ - imports: [TypeOrmModule.forFeature([Poll, Option, Tag])], + imports: [TypeOrmModule.forFeature([Poll, Option, Tag, User])], controllers: [PollController], - providers: [PollService], + providers: [PollService, UserService], exports: [PollService], }) export class PollModule {} diff --git a/app/backend/src/poll/poll.service.ts b/app/backend/src/poll/poll.service.ts index 798e5f21..2210405e 100644 --- a/app/backend/src/poll/poll.service.ts +++ b/app/backend/src/poll/poll.service.ts @@ -15,16 +15,13 @@ export class PollService { @InjectRepository(Tag) private readonly tagRepository: Repository, ) {} - public async createPoll(createPollDto: CreatePollDto): Promise { + public async createPoll(createPollDto: any): Promise { const poll = new Poll(); poll.question = createPollDto.question; poll.creator = createPollDto.creator; - poll.moderator = 'moderator'; - - // Save the poll first to generate the ID + poll.due_date = createPollDto.due_date; const savedPoll = await this.pollRepository.save(poll); - // Create and associate options with the saved poll const options = createPollDto.options.map((option) => { const newOption = new Option(); newOption.answer = option; @@ -32,11 +29,8 @@ export class PollService { return newOption; }); - // Save the options await this.optionRepository.save(options); - // If you want to associate tags with the poll, you can do it here - // Assuming createPollDto.tags is an array of tag names const tags = await Promise.all( createPollDto.tags.map(async (tagName) => { let tag = await this.tagRepository.findOneBy({ name: tagName }); @@ -51,10 +45,8 @@ export class PollService { }), ); - // Associate tags with the poll savedPoll.tags = tags; - // Save the poll again to update the associations return await this.pollRepository.save(savedPoll); }