@nestjs/common#NotAcceptableException TypeScript Examples

The following examples show how to use @nestjs/common#NotAcceptableException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: pins.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Post('/me/pins')
  async createPin(@Request() req, @Body() createPinDto: CreatePinDto) {
    let userId = req.user._id;
    let createdPin = await this.PinsService.createPin(userId, createPinDto);
    if (createdPin) {
      return createdPin;
    } else {
      await this.ImagesService.deleteFile(createPinDto.imageId.toString());
      throw new NotAcceptableException({ message: 'pin is not created' });
    }
  }
Example #2
Source File: role.controller.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
@Delete('/:id')
	@Permissions('roles/delete')
	@AuditLog('roles/delete')
	public async delete(@Param('id') id: string): Promise<void> {
		const role = await this.roleService.findOne({ uuid: id }, true);

		if (!role) {
			throw new UnauthorizedException()
		}

		if (role.users.length !== 0) {
			throw new NotAcceptableException('Please make sure no users are assigned to this role')
		}

		return this.roleService.delete(id);
	}
Example #3
Source File: request.controller.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
@Post()
	@Permissions('requests/create')
	public async create(
		@Headers('authorization') authorization: string,
		@Body() request: RequestEntity,
		@Req() req: Request
	): Promise<any> {
		const remoteAddress = req.headers['x-real-ip'] as string || "internal";

		// first of all check for ban
		if (await this.banService.findOne({
			where: [
				{ identifier: remoteAddress, expiresAt: MoreThan(new Date()) },
				{ identifier: remoteAddress, expiresAt: IsNull()  }
			]
		})) {
			throw new NotAcceptableException('You have been banned from this radio');
		}

		if (await this.permissionService.hasPermission((req.user as any)?.uuid || req.headers.authorization, ['requests/ignore-timeout'])) {
			return this.requestService.create({
				requestOrigin: 'website',
				...request,
				requestContext: remoteAddress
			});
		}

		if (await this.requestService.findRecent(remoteAddress)) {
			throw new NotAcceptableException('Please wait before making another request');
		}

		return this.requestService.create({
			requestOrigin: 'website',
			...request,
			requestContext: remoteAddress
		});
	}
Example #4
Source File: form-entry.controller.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
@Post()
	@Webhook('form-entries/create')
	@Permissions('form-entries/create')
	public async create(
		@Param('formUuid') formUuid: string,
		@Body() formEntry: any,
		@Req() req: Request
	): Promise<any> {
		const form = await this.formService.findOne(formUuid);
		const remoteAddress = req.headers['x-forwarded-for'] as string || "internal";

		const existingRequest = await this.formEntryService.findRecent(remoteAddress, form.timeout || 0);

		if (existingRequest) {
			throw new NotAcceptableException("Please wait before sending a new message");
		}

		return this.formEntryService.create(formUuid, {
			...formEntry,
			requestContext: remoteAddress
		});
	}
Example #5
Source File: user.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Get('/me/boards/view')
  async getViewState(@Request() req) {
    const view = await this.userService.getViewState(req.user._id);
    if (view) {
      return view;
    } else {
      throw new NotAcceptableException('cant get view state');
    }
  }
Example #6
Source File: user.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Put('/me/boards/view')
  async setViewState(@Request() req, @Query('viewState') viewState: string) {
    const view = await this.userService.setViewState(req.user._id, viewState);
    if (view) {
      return { success: 'view is updated' };
    } else {
      throw new NotAcceptableException('view is not updated');
    }
  }
Example #7
Source File: pins.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Post('/pins/:pinId/report')
  async reportPin(
    @Request() req,
    @Param('pinId') pinId: string,
    @Body('reason') reason: string,
  ) {
    let userId = req.user._id;
    let report = await this.PinsService.reportPin(userId, pinId, reason);
    if (report) {
      return 1;
    } else {
      throw new NotAcceptableException({ message: 'pin is not reported' });
    }
  }
Example #8
Source File: pins.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Put('/me/savedPins/:pinId')
  async editSavedPin(
    @Request() req,
    @Param('pinId') pinId: string,
    @Body('note') note: string,
    @Body('boardId') boardId: string,
    @Body('sectionId') sectionId: string,
  ) {
    let userId = req.user._id;
    let editedPin = await this.PinsService.editSavedPin(
      pinId,
      userId,
      boardId,
      sectionId,
      note,
    );
    if (editedPin) {
      return { success: 'pin has been edited' };
    } else {
      throw new NotAcceptableException({ message: 'pin is not edited' });
    }
  }
Example #9
Source File: pins.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Put('/me/pins/:pinId')
  async editCreatedPin(
    @Request() req,
    @Param('pinId') pinId: string,
    @Body('description') description: string,
    @Body('boardId') boardId: string,
    @Body('sectionId') sectionId: string,
    @Body('title') title: string,
    @Body('destLink') destLink: string,
  ) {
    let userId = req.user._id;
    let editedPin = await this.PinsService.editCreatedPin(
      pinId,
      userId,
      boardId,
      sectionId,
      description,
      title,
      destLink,
    );
    if (editedPin) {
      return editedPin;
    } else {
      throw new NotAcceptableException({ message: 'pin is not edited' });
    }
  }
Example #10
Source File: pins.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Delete('/me/pins/:pinId')
  async deletePin(@Request() req, @Param('pinId') pinId: string) {
    let userId = req.user._id;
    let deletedPin = await this.BoardService.deletePin(pinId, userId);
    if (deletedPin) {
      return { success: 'pin is deleted succissfully' };
    } else {
      throw new NotAcceptableException({ message: 'pin is not deleated' });
    }
  }
Example #11
Source File: pins.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Post('/pins/:pinId/comments/:commentId/replies/:replyId/likes')
  async likeReply(
    @Request() req,
    @Param('pinId') pinId: string,
    @Param('commentId') commentId: string,
    @Param('replyId') replyId: string,
  ) {
    let userId = req.user._id;
    let like = await this.PinsService.likeReply(
      pinId,
      commentId,
      userId,
      replyId,
    );
    if (like) {
      return { success: true };
    } else {
      throw new NotAcceptableException({ message: 'like is not created' });
    }
  }
Example #12
Source File: pins.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Post('/pins/:pinId/comments/:commentId/likes')
  async likeComment(
    @Request() req,
    @Param('pinId') pinId: string,
    @Param('commentId') commentId: string,
  ) {
    let userId = req.user._id;
    let like = await this.PinsService.likeComment(pinId, commentId, userId);
    if (like) {
      return { success: true };
    } else {
      throw new NotAcceptableException({ message: 'like is not created' });
    }
  }
Example #13
Source File: pins.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Post('/pins/:pinId/reacts')
  async createReact(
    @Request() req,
    @Param('pinId') pinId: string,
    @Query('reactType') reactType: string,
  ) {
    let userId = req.user._id;
    let react = await this.PinsService.createReact(pinId, reactType, userId);
    if (react) {
      return { success: true };
    } else {
      throw new NotAcceptableException({ message: 'react is not created' });
    }
  }
Example #14
Source File: pins.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Post('/pins/:pinId/comments/:commentId/replies')
  async createReply(
    @Request() req,
    @Body('replyText') replyText: string,
    @Param('pinId') pinId: string,
    @Param('commentId') commentId: string,
  ) {
    let userId = req.user._id;
    let reply = await this.PinsService.createReply(
      pinId,
      replyText,
      userId,
      commentId,
    );
    if (reply) {
      return reply;
    } else {
      throw new NotAcceptableException({ message: 'reply is not created' });
    }
  }
Example #15
Source File: pins.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Post('/pins/:pinId/comments')
  async createComment(
    @Request() req,
    @Body('commentText') commentText: string,
    @Param('pinId') pinId: string,
  ) {
    let userId = req.user._id;
    let comment = await this.PinsService.createComment(
      pinId,
      commentText,
      userId,
    );
    if (comment) {
      return comment;
    } else {
      throw new NotAcceptableException({ message: 'comment is not created' });
    }
  }
Example #16
Source File: pins.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Post('/me/savedPins/:id')
  async savePin(
    @Request() req,
    @Param('id') pinId: string,
    @Query('boardId') boardId: string,
    @Query('sectionId') sectionId: string,
  ) {
    let userId = req.user._id;
    let savedPin = await this.PinsService.savePin(
      userId,
      pinId,
      boardId,
      sectionId,
    );
    if (savedPin) {
      return { success: true };
    } else {
      throw new NotAcceptableException({ message: 'pin is not saved' });
    }
  }
Example #17
Source File: ft.strategy.ts    From 42_checkIn with GNU General Public License v3.0 6 votes vote down vote up
async validate(token: string, rt: string, profile: any) {
    try {
      this.logger.debug('oauth validation start');
      const user = new User(
        profile.id,
        profile.username,
        profile.emails[0].value,
      );
      this.logger.debug('authroized info : ', profile.id, profile.username);
      if (profile._json.cursus_users.length < 2)
        throw new NotAcceptableException();
      return user;
    } catch (e) {
      this.logger.info(e);
      throw e;
    }
  }
Example #18
Source File: board.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Delete('/me/savedPins/:pinId')
  async unsavePinFromBoard(
    @Request() req,
    @Param('pinId') pinId: string,
    @Query('boardId') boardId: string,
    @Query('sectionId') sectionId: string,
  ) {
    let userId = req.user._id;
    let unsavedPin = await this.BoardService.unsavePin(
      pinId,
      boardId,
      sectionId,
      userId,
      false,
    );
    if (unsavedPin) {
      return { success: 'pin is unsaved suucissfully' };
    } else {
      throw new NotAcceptableException({ message: 'pin hasnt been unsaved' });
    }
  }
Example #19
Source File: board.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Get('/boards/:boardId/sections/:sectionId')
  async getFullSection(
    @Request() req,
    @Param('boardId') boardId: string,
    @Param('sectionId') sectionId: string,
  ) {
    let userId = req.user._id;
    let section = await this.BoardService.getSectionFull(
      boardId,
      sectionId,
      userId,
    );
    if (section) {
      return section;
    } else {
      throw new NotAcceptableException({ message: 'section is not found' });
    }
  }
Example #20
Source File: board.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Get('/boards/:boardId')
  async getFullBoard(@Request() req, @Param('boardId') boardId: string) {
    let userId = req.user._id;
    let board = await this.BoardService.getBoardFull(boardId, userId);
    if (board) {
      return board;
    } else {
      throw new NotAcceptableException({ message: 'Board is not found' });
    }
  }
Example #21
Source File: board.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Put('/me/boards/merge')
  async mergeBoards(
    @Request() req,
    @Body('originalBoardId') originalBoardId: string,
    @Body('mergedBoardId') mergedBoardId: string,
  ) {
    let userId = req.user._id;
    let board = await this.BoardService.merge(
      originalBoardId,
      mergedBoardId,
      userId,
    );
    if (board) {
      return board;
    } else {
      throw new NotAcceptableException({ message: 'Boards are not merged' });
    }
  }
Example #22
Source File: board.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Delete('/me/boards/:boardId/section/:sectionId')
  async deleteSection(
    @Request() req,
    @Param('boardId') boardId: string,
    @Param('sectionId') sectionId: string,
  ) {
    let userId = req.user._id;
    let deleteSection = await this.BoardService.deleteSection(
      boardId,
      sectionId,
      userId,
    );
    if (deleteSection) {
      return { success: 'section deleted succissfully' };
    } else {
      throw new NotAcceptableException({ message: 'Section is not deleated' });
    }
  }
Example #23
Source File: board.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Post('/me/boards/:boardId/section')
  async createSection(
    @Request() req,
    @Param('boardId') boardId: string,
    @Body('sectionName') sectionName: string,
  ) {
    let userId = req.user._id;
    let createSection = await this.BoardService.createSection(
      boardId,
      sectionName,
      userId,
    );
    if (createSection) {
      return createSection;
    } else {
      throw new NotAcceptableException({ message: 'Section is not created' });
    }
  }
Example #24
Source File: board.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Delete('/me/boards/:boardId')
  async deleteBoard(@Request() req, @Param('boardId') boardId: string) {
    let userId = req.user._id;
    let deletedBoard = await this.BoardService.deleteBoard(userId, boardId);
    if (deletedBoard) {
      return { success: 'Board is deleted succissfully' };
    } else {
      throw new NotAcceptableException({ message: 'Board is not deleated' });
    }
  }
Example #25
Source File: board.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Delete('/me/boards/:boardId/collaboratores')
  async deleteCollaborator(
    @Request() req,
    @Param('boardId') boardId: string,
    @Body('collaboratorId') collaboratorId: string,
  ) {
    let userId = req.user._id;
    let isdeleted = await this.BoardService.deleteCollaborator(
      userId,
      boardId,
      collaboratorId,
    );
    if (isdeleted) {
      return { success: 'collaborator has been deleted' };
    } else {
      throw new NotAcceptableException('collaborator couldnt be deleted');
    }
  }
Example #26
Source File: board.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Put('/me/boards/:boardId/collaboratores')
  async editCollaboratoresPermissions(
    @Request() req,
    @Param('boardId') boardId: string,
    @Body() editCollaboratoresPermissionsDto: EditCollaboratoresPermissionsDto,
  ) {
    let userId = req.user._id;
    let collaborator = await this.BoardService.editCollaboratoresPermissions(
      userId,
      boardId,
      editCollaboratoresPermissionsDto,
    );
    if (collaborator) {
      return collaborator;
    } else {
      throw new NotAcceptableException('collaborator couldnt be edited');
    }
  }
Example #27
Source File: board.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Get('/me/boards/:boardId/collaboratores')
  async getCollaboratoresPermissions(
    @Request() req,
    @Param('boardId') boardId: string,
  ) {
    let userId = req.user._id;
    let collaboratores = await this.BoardService.getCollaboratoresPermissions(
      userId,
      boardId,
    );
    if (collaboratores) {
      return collaboratores;
    } else {
      throw new NotAcceptableException('collaboratores not found');
    }
  }
Example #28
Source File: board.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Put('/me/boards/edit/:boardId')
  async editBoard(
    @Request() req,
    @Param('boardId') boardId: string,
    @Body() editBoardDto: EditBoardDto,
  ) {
    let userId = req.user._id;
    let board = await this.BoardService.editBoard(
      boardId,
      userId,
      editBoardDto,
    );
    if (board) {
      return board;
    } else {
      throw new NotAcceptableException("board couldn't be updated");
    }
  }
Example #29
Source File: board.controller.ts    From Phantom with MIT License 6 votes vote down vote up
@UseGuards(AuthGuard('jwt'))
  @Post('/me/boards')
  async createBoard(
    @Request() req,
    @Body('name') name: string,
    @Body('startDate') startDate: string,
    @Body('endDate') endDate: string,
    @Body('status') status: string,
  ) {
    let userId = req.user._id;
    let createdBoard = await this.BoardService.createBoard(
      name,
      startDate,
      endDate,
      userId,
    );
    if (createdBoard) {
      return createdBoard;
    } else {
      throw new NotAcceptableException({ message: 'board not created' });
    }
  }