File

src/vote/repo-vote.controller.ts

Prefix

repos

Index

Methods

Methods

Async downVoteOneById
downVoteOneById(id: number, userId: number)
Decorators :
@Delete('/:id/vote')
@ApiBearerAuth()
@UseGuards(SupabaseGuard)
@ApiOperation({operationId: 'downVoteOneById', summary: 'Finds a repo by :id and removes existing vote'})
@ApiOkResponse({description: 'Returns the repo vote', type: DbRepoToUserVotes})
@ApiNotFoundResponse({description: 'Repo or vote not found'})
@ApiConflictResponse({description: 'You have already removed your vote'})
@ApiParam({name: 'id', type: 'integer'})
Parameters :
Name Type Optional
id number No
userId number No
Async downVoteOneByOwnerAndRepo
downVoteOneByOwnerAndRepo(owner: string, repo: string, userId: number)
Decorators :
@Delete('/:owner/:repo/vote')
@ApiBearerAuth()
@UseGuards(SupabaseGuard)
@ApiOperation({operationId: 'downVoteOneByOwnerAndRepo', summary: 'Finds a repo by :owner and :repo and removes existing vote'})
@ApiOkResponse({description: 'Returns the repo vote', type: DbRepoToUserVotes})
@ApiNotFoundResponse({description: 'Repo or vote not found'})
@ApiConflictResponse({description: 'You have already removed your vote'})
Parameters :
Name Type Optional
owner string No
repo string No
userId number No
Async findAllUserVoted
findAllUserVoted(pageOptionsDto: RepoPageOptionsDto, userId: number)
Decorators :
@Get('/listUserVoted')
@ApiBearerAuth()
@UseGuards(SupabaseGuard)
@ApiOperation({operationId: 'findAllUserVoted', summary: 'Finds all repos voted by authenticated user and paginates them'})
@ApiPaginatedResponse(DbRepo)
@ApiOkResponse({type: DbRepo})
Parameters :
Name Type Optional
pageOptionsDto RepoPageOptionsDto No
userId number No
Async findOneByRepoId
findOneByRepoId(repoId: number, userId: number)
Decorators :
@Get('/:repoId/vote')
@ApiBearerAuth()
@UseGuards(SupabaseGuard)
@ApiOperation({operationId: 'findOneByRepoId', summary: 'Finds a repo by :repoId and returns if authenticated user has voted for it'})
@ApiOkResponse({type: VotedRepoDto, description: 'Returns if authenticated user has voted for it'})
@ApiParam({name: 'repoId', type: 'integer'})
Parameters :
Name Type Optional
repoId number No
userId number No
Returns : unknown
Async voteOneById
voteOneById(id: number, userId: number)
Decorators :
@Put('/:id/vote')
@ApiBearerAuth()
@UseGuards(SupabaseGuard)
@ApiOperation({operationId: 'voteOneById', summary: 'Finds a repo by :id and adds a vote'})
@ApiOkResponse({description: 'Returns the repo vote', type: DbRepoToUserVotes})
@ApiNotFoundResponse({description: 'Repo or vote not found'})
@ApiConflictResponse({description: 'You have already voted for this repo'})
@ApiParam({name: 'id', type: 'integer'})
Parameters :
Name Type Optional
id number No
userId number No
Async voteOneByOwnerAndRepo
voteOneByOwnerAndRepo(owner: string, repo: string, userId: number)
Decorators :
@Put('/:owner/:repo/vote')
@ApiBearerAuth()
@UseGuards(SupabaseGuard)
@ApiOperation({operationId: 'voteOneByOwnerAndRepo', summary: 'Finds a repo by :owner and :repo and adds a vote'})
@ApiOkResponse({description: 'Returns the repo vote', type: DbRepoToUserVotes})
@ApiNotFoundResponse({description: 'Repo or vote not found'})
@ApiConflictResponse({description: 'You have already voted for this repo'})
Parameters :
Name Type Optional
owner string No
repo string No
userId number No
import { Controller, Delete, Get, Param, ParseIntPipe, Put, Query, UseGuards } from "@nestjs/common";
import {
  ApiBearerAuth,
  ApiConflictResponse,
  ApiNotFoundResponse,
  ApiOkResponse,
  ApiOperation,
  ApiParam,
  ApiTags,
} from "@nestjs/swagger";

import { RepoService } from "../repo/repo.service";
import { SupabaseGuard } from "../auth/supabase.guard";
import { UserId } from "../auth/supabase.user.decorator";
import { DbRepoToUserVotes } from "../repo/entities/repo.to.user.votes.entity";
import { ApiPaginatedResponse } from "../common/decorators/api-paginated-response.decorator";
import { DbRepo } from "../repo/entities/repo.entity";
import { RepoPageOptionsDto } from "../repo/dtos/repo-page-options.dto";
import { PageDto } from "../common/dtos/page.dto";
import { VotedRepoDto } from "./../user-repo/dtos/user-repos.dto";
import { VoteService } from "./vote.service";

@Controller("repos")
@ApiTags("Repository service guarded", "Vote service")
export class RepoVoteController {
  constructor(private readonly repoService: RepoService, private readonly voteService: VoteService) {}

  @Get("/listUserVoted")
  @ApiBearerAuth()
  @UseGuards(SupabaseGuard)
  @ApiOperation({
    operationId: "findAllUserVoted",
    summary: "Finds all repos voted by authenticated user and paginates them",
  })
  @ApiPaginatedResponse(DbRepo)
  @ApiOkResponse({ type: DbRepo })
  async findAllUserVoted(
    @Query() pageOptionsDto: RepoPageOptionsDto,
    @UserId() userId: number
  ): Promise<PageDto<DbRepo>> {
    return this.repoService.findAll(pageOptionsDto, userId, ["Votes"]);
  }

  @Get("/:repoId/vote")
  @ApiBearerAuth()
  @UseGuards(SupabaseGuard)
  @ApiOperation({
    operationId: "findOneByRepoId",
    summary: "Finds a repo by :repoId and returns if authenticated user has voted for it",
  })
  @ApiOkResponse({
    type: VotedRepoDto,
    description: "Returns if authenticated user has voted for it",
  })
  @ApiParam({ name: "repoId", type: "integer" })
  async findOneByRepoId(@Param("repoId", ParseIntPipe) repoId: number, @UserId() userId: number) {
    return this.voteService.findOneByRepoId(repoId, userId);
  }

  @Put("/:id/vote")
  @ApiBearerAuth()
  @UseGuards(SupabaseGuard)
  @ApiOperation({
    operationId: "voteOneById",
    summary: "Finds a repo by :id and adds a vote",
  })
  @ApiOkResponse({
    description: "Returns the repo vote",
    type: DbRepoToUserVotes,
  })
  @ApiNotFoundResponse({ description: "Repo or vote not found" })
  @ApiConflictResponse({ description: "You have already voted for this repo" })
  @ApiParam({ name: "id", type: "integer" })
  async voteOneById(@Param("id", ParseIntPipe) id: number, @UserId() userId: number): Promise<DbRepoToUserVotes> {
    const item = await this.repoService.findOneById(id);

    return this.voteService.voteByRepoId(item.id, userId);
  }

  @Put("/:owner/:repo/vote")
  @ApiBearerAuth()
  @UseGuards(SupabaseGuard)
  @ApiOperation({
    operationId: "voteOneByOwnerAndRepo",
    summary: "Finds a repo by :owner and :repo and adds a vote",
  })
  @ApiOkResponse({
    description: "Returns the repo vote",
    type: DbRepoToUserVotes,
  })
  @ApiNotFoundResponse({ description: "Repo or vote not found" })
  @ApiConflictResponse({ description: "You have already voted for this repo" })
  async voteOneByOwnerAndRepo(
    @Param("owner") owner: string,
    @Param("repo") repo: string,
    @UserId() userId: number
  ): Promise<DbRepoToUserVotes> {
    const item = await this.repoService.findOneByOwnerAndRepo(owner, repo);

    return this.voteService.voteByRepoId(item.id, userId);
  }

  @Delete("/:id/vote")
  @ApiBearerAuth()
  @UseGuards(SupabaseGuard)
  @ApiOperation({
    operationId: "downVoteOneById",
    summary: "Finds a repo by :id and removes existing vote",
  })
  @ApiOkResponse({
    description: "Returns the repo vote",
    type: DbRepoToUserVotes,
  })
  @ApiNotFoundResponse({ description: "Repo or vote not found" })
  @ApiConflictResponse({ description: "You have already removed your vote" })
  @ApiParam({ name: "id", type: "integer" })
  async downVoteOneById(@Param("id", ParseIntPipe) id: number, @UserId() userId: number): Promise<DbRepoToUserVotes> {
    const item = await this.repoService.findOneById(id);

    return this.voteService.downVoteByRepoId(item.id, userId);
  }

  @Delete("/:owner/:repo/vote")
  @ApiBearerAuth()
  @UseGuards(SupabaseGuard)
  @ApiOperation({
    operationId: "downVoteOneByOwnerAndRepo",
    summary: "Finds a repo by :owner and :repo and removes existing vote",
  })
  @ApiOkResponse({
    description: "Returns the repo vote",
    type: DbRepoToUserVotes,
  })
  @ApiNotFoundResponse({ description: "Repo or vote not found" })
  @ApiConflictResponse({ description: "You have already removed your vote" })
  async downVoteOneByOwnerAndRepo(
    @Param("owner") owner: string,
    @Param("repo") repo: string,
    @UserId() userId: number
  ): Promise<DbRepoToUserVotes> {
    const item = await this.repoService.findOneByOwnerAndRepo(owner, repo);

    return this.voteService.downVoteByRepoId(item.id, userId);
  }
}

results matching ""

    No results matching ""