How to use the @nestjs/swagger.ApiImplicitBody function in @nestjs/swagger

To help you get started, we’ve selected a few @nestjs/swagger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neoteric-eu / nestjs-auth / src / app / auth / auth.controller.ts View on Github external
const user = await this.userService.findByEmail(body.email);
			if (user.is_verified) {
				throw new Error(`User ${user.email} already verified`);
			}
			this.client.send({cmd: USER_CMD_REGISTER}, user).subscribe(() => {}, error => {
				this.logger.error(error, '');
			});
			this.logger.debug(`[registerVerify] Sent command registry verify for email ${body.email}`);
		} catch (err) {
			this.logger.error(`[registerVerifyResend] ${err.message}`, err.stack);
		}
	}

	@Post('password/reset')
	@HttpCode(204)
	@ApiImplicitBody({ required: true, type: PasswordResetDto, name: 'PasswordResetDto' })
	@ApiResponse({ status: 204, description: 'NO CONTENT' })
	public passwordReset(@Body() data: DeepPartial): void {
		this.logger.debug(`[passwordReset] User ${data.email} starts password reset`);
		this.client.send({cmd: USER_CMD_PASSWORD_RESET}, {email: data.email}).subscribe(() => {}, error => {
			this.logger.error(error, '');
		});
	}

	@Post('password/new')
	@HttpCode(204)
	@ApiImplicitBody({ required: true, type: PasswordTokenDto, name: 'PasswordTokenDto' })
	@ApiResponse({ status: 204, description: 'NO CONTENT' })
	public async passwordNew(@Body() body: PasswordTokenDto): Promise {
		this.logger.debug(`[passwordNew] Token ${body.resetToken}`);
		const token = await verifyToken(body.resetToken, config.session.password_reset.secret);
		const user = await this.userService.updatePassword({id: token.id, password: body.password});
github jmcdo29 / zeldaPlay / src / server / app / zeldaplay / weapon / weapon.controller.ts View on Github external
@Body('weapon', WeaponPipe) inWeapon: DbWeapon,
    @Param() params: CharacterIdParam
  ): Observable {
    return this.weaponService.newWeapon(inWeapon, params.charId);
  }

  @Patch('update/:weaponId')
  @ApiOperation({
    title: 'Update Weapon',
    description: 'Update the weapon saved in the database with the specified id'
  })
  @UseGuards(AuthGuard)
  @ApiBearerAuth()
  @ApiOkResponse({ type: DbWeapon })
  @ApiImplicitParam({ name: 'weaponId', type: 'string', required: true })
  @ApiImplicitBody({ name: 'weapon', type: WeaponDTO })
  updateWeapon(
    @Body('weapon', WeaponPipe) inWeapon: DbWeapon,
    @Param() params: WeaponIdParam
  ): Observable {
    return this.weaponService.updateWeapon(inWeapon);
  }
}
github jmcdo29 / zeldaPlay / src / server / app / zeldaplay / character / character.controller.ts View on Github external
description:
      'Get all of the characters who do not belong to a user. ' +
      'These are returned and shown as an example for the user to get an idea of how the app works.'
  })
  @ApiOkResponse({ type: DbCharacterShort, isArray: true })
  getAll(): Observable {
    return this.characterService.getAll();
  }

  @Post('new/:userId')
  @ApiOperation({
    title: 'New Character',
    description:
      'Using the User id, create and assign a new character based on the incoming body'
  })
  @ApiImplicitBody({ name: 'character', type: CharacterDTO })
  @ApiImplicitParam({ name: 'userId', type: 'string', required: true })
  @UseGuards(AuthGuard)
  @ApiBearerAuth()
  @ApiOkResponse({ type: DbCharacter })
  newChar(
    @Param() params: UserIdParam,
    @Body('character', CharacterPipe) character: DbCharacter
  ): Observable {
    return this.characterService.newChar(character, params.userId);
  }

  @Get('user/:userId')
  @ApiOperation({
    title: 'User Characters',
    description: 'Get all the characters belonging to the specified user.'
  })
github magishift / magishift.core / packages / crud / src / crud.controller.ts View on Github external
return ExceptionHandler(e);
      }
    }

    @Get('deleted/:id')
    @ApiOperation({ title: `Get single deleted ${name} by id` })
    async fetchDeletedById(@Param('id') id: string): Promise {
      try {
        return this.service.findOne({ id, isDeleted: true } as any);
      } catch (e) {
        return ExceptionHandler(e);
      }
    }

    @Post()
    @ApiImplicitBody({
      name: 'Create ' + name,
      type: dtoClass,
    })
    @ApiOperation({ title: `Create new ${name}` })
    @UsePipes(new DtoValidationPipe(dtoClass))
    async create(@Body() data: TDto): Promise {
      try {
        const param = await this.mapper.dtoFromObject(data);
        return await this.service.create(param);
      } catch (e) {
        return ExceptionHandler(e);
      }
    }

    @Patch(':id')
    @ApiImplicitBody({
github jmcdo29 / zeldaPlay / src / server / app / auth / auth.controller.ts View on Github external
ApiUseTags
} from '@nestjs/swagger';

import { AuthService } from '@Auth/auth.service';
import { JwtReturnDTO, NewUserDTO, UserDTO } from '@Body/index';
import { DbQuestion } from '@Db/models';
import { Observable, of } from 'rxjs';

@ApiUseTags('Sign In/ Sign Up/ Sign Out')
@Controller()
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @Post('login')
  @ApiOperation({ title: 'Login', description: 'Log the user in' })
  @ApiImplicitBody({ name: 'user', type: UserDTO })
  @ApiOkResponse({ type: JwtReturnDTO })
  login(@Body('user') user: UserDTO): Observable {
    return this.authService.login(user);
  }

  @Post('signup')
  @ApiOperation({ title: 'Signup', description: 'Sign the new user up' })
  @ApiImplicitBody({ name: 'user', type: NewUserDTO })
  @ApiOkResponse({ type: JwtReturnDTO })
  signup(@Body('user') user: NewUserDTO): Observable {
    return this.authService.signup(user);
  }

  @Post('logout')
  @ApiOperation({ title: 'Logout', description: 'Allow the user to log out.' })
  logout(): void {
github neoteric-eu / nestjs-auth / src / app / auth / auth.controller.ts View on Github external
@Post('register')
	@HttpCode(204)
	@ApiImplicitBody({ required: true, type: UserEntityDto, name: 'UserEntityDto' })
	@ApiResponse({ status: 204, description: 'NO_CONTENT' })
	public async register(@Body() data: DeepPartial): Promise {
		const user = await this.userService.create(data);
		this.logger.debug(`[register] User ${data.email} register`);
		this.client.send({cmd: USER_CMD_REGISTER}, user).subscribe(() => {}, error => {
			this.logger.error(error, '');
		});
		this.logger.debug(`[register] Send registration email for email ${data.email}`);
	}

	@Post('register/verify')
	@HttpCode(200)
	@ApiImplicitBody({ required: true, type: VerifyTokenDto, name: 'VerifyTokenDto' })
	@ApiResponse({ status: 200, description: 'OK', type: JwtDto })
	public async registerVerify(@Body() body: VerifyTokenDto): Promise {
		this.logger.debug(`[registerVerify] Token ${body.verifyToken}`);
		const user = await this.userService.findByEmail(body.email);
		if (user.activationCode !== body.verifyToken) {
			throw new RestException({
				error: 'Auth',
				message: `Wrong verification token`,
				condition: UserErrorEnum.NOT_VERIFIED
			}, HttpStatus.UNPROCESSABLE_ENTITY);
		}
		user.is_verified = true;
		await this.userService.update(user);
		this.client.send({cmd: USER_CMD_REGISTER_VERIFY}, user).subscribe(() => {}, error => {
			this.logger.error(error, '');
		});
github FunnyLiu / nestDemo / serve-data / src / user / user.controller.ts View on Github external
async create(@Body('user') userData: CreateUserDto) {
        return this.userService.create(userData);
    }

    @ApiOperation({ title: 'Delete user' })
    @ApiImplicitParam({ name: 'id', type: 'number' })
    @Delete('users/:id')
    @UseGuards(RolesGuard)
    @Roles(ROLE_SUPER)
    async delete(@Param() params: any) {
        return await this.userService.deleteUserById(params.id);
    }


    @ApiOperation({ title: 'Login' })
    @ApiImplicitBody({ name: 'user', type: LoginUserBody })
    @UsePipes(new ValidationPipe())
    @Post('users/login')
    async login(@Body('user') loginUserDto: LoginUserDto): Promise {
        const _user = await this.userService.findOne(loginUserDto);

        if (!_user) throw new UnhandleException(`not found`)

        const token = await this.userService.generateJWT(_user);
        const { email, username, roles } = _user;
        let rolesList = [];
        roles.forEach(v => {
            rolesList.push(v.name)
        })
        const user = {
            email,
            token,
github FunnyLiu / nestDemo / serve-data / src / user / role.controller.ts View on Github external
import { RoleService } from "./role.service";
import { CreateRoleDto } from "./dto";
import { CreateRoleBody } from "./dto/create-role.dto";
import { UpdateRoleBody, UpdateRoleDto } from "./dto/update-role.dto";
import { RoleRO, RolesRO } from "./role.interface";

@ApiBearerAuth()
@ApiUseTags('role')
@Controller()
export class RoleController {
    constructor(private readonly roleService: RoleService){

    }

    @ApiOperation({ title: 'Create Role'})
    @ApiImplicitBody({name:'role',type:CreateRoleBody})
    @UsePipes(new ValidationPipe({whitelist: true,forbidNonWhitelisted: true }))
    @Post('role')
    async create(@Body('role') roleData: CreateRoleDto){
        return this.roleService.createRole(roleData)
    }

    @ApiOperation({ title: 'Update Role Info by id'})
    @ApiImplicitQuery({name:'id',type:'number'})
    @ApiImplicitBody({name:'role',type:UpdateRoleBody})
    @UsePipes(new ValidationPipe({whitelist: true,forbidNonWhitelisted: true }))
    @Put('role')
    async update(@Query('id') roleId: number, @Body('role') roleData: UpdateRoleDto) {
        return await this.roleService.updateRole(roleId, roleData);
    }

    @ApiOperation({ title: 'Get all Roles' })
github jmcdo29 / zeldaPlay / src / server / app / auth / auth.controller.ts View on Github external
@ApiUseTags('Sign In/ Sign Up/ Sign Out')
@Controller()
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @Post('login')
  @ApiOperation({ title: 'Login', description: 'Log the user in' })
  @ApiImplicitBody({ name: 'user', type: UserDTO })
  @ApiOkResponse({ type: JwtReturnDTO })
  login(@Body('user') user: UserDTO): Observable {
    return this.authService.login(user);
  }

  @Post('signup')
  @ApiOperation({ title: 'Signup', description: 'Sign the new user up' })
  @ApiImplicitBody({ name: 'user', type: NewUserDTO })
  @ApiOkResponse({ type: JwtReturnDTO })
  signup(@Body('user') user: NewUserDTO): Observable {
    return this.authService.signup(user);
  }

  @Post('logout')
  @ApiOperation({ title: 'Logout', description: 'Allow the user to log out.' })
  logout(): void {
    return;
  }
}