How to use the ts-express-decorators/lib/swagger.Returns function in ts-express-decorators

To help you get started, we’ve selected a few ts-express-decorators 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 scopsy / node-typescript-starter / src / controllers / auth / auth.controller.ts View on Github external
@Validate()
    async signup(
        @Validator() @BodyParams() data: SignupDto
    ) {
        const user = await this.authService.createUser(data);
        const authData = await this.authService.authenticateLocal(user.email, data.password);

        return authData;
    }

    /**
     * This end point used for authentication with fb access_token provided
     * Useful when the access_token is obtained via client-side sdk
     */
    @Post('/facebook/token')
    @Returns(AuthDto)
    async facebookTokenAuth(
        @Required() @QueryParams('access_token') token: string,
        @Request() req: IAppRequest,
        @Response() res: IAppResponse,
        @Next() next: NextFunction
    ) {
        const auth = await this.authService.authenticateStrategy(AUTH_STRATEGY.FACEBOOK_TOKEN_STRATEGY, req, res, next);

        res.json(auth);
    }
}
github scopsy / node-typescript-starter / src / controllers / auth / auth.controller.ts View on Github external
import { Validate, Validator } from 'typescript-param-validator';
import { AuthDto } from '../../services/auth/auth.dto';
import { AuthService } from '../../services/auth/auth.service';
import { AUTH_STRATEGY } from '../../services/auth/passport/passport.service';
import { IAppRequest, IAppResponse } from '../../types/app.types';
import { HTTPStatusCodes } from '../../types/http';
import { FacebookTokenAuthQueryDto, LocalLoginDto, SignupDto } from './auth.dto';

@Controller('/auth')
export class AuthController {
    constructor(private authService: AuthService) {

    }

    @Post('/login')
    @Returns(AuthDto)
    @Validate()
    async login(
        @Validator() @BodyParams() body: LocalLoginDto,
        @Request() req: any,
        @Response() res,
        @Next() next: NextFunction
    ) {
        const auth = await this.authService.authenticateStrategy(AUTH_STRATEGY.LOCAL_STRATEGY, req, res, next);

        res.json(auth);
    }

    @Post('/signup')
    @Returns(AuthDto)
    @Status(HTTPStatusCodes.CREATED)
    @Validate()
github scopsy / node-typescript-starter / src / controllers / auth / auth.controller.ts View on Github external
@Post('/login')
    @Returns(AuthDto)
    @Validate()
    async login(
        @Validator() @BodyParams() body: LocalLoginDto,
        @Request() req: any,
        @Response() res,
        @Next() next: NextFunction
    ) {
        const auth = await this.authService.authenticateStrategy(AUTH_STRATEGY.LOCAL_STRATEGY, req, res, next);

        res.json(auth);
    }

    @Post('/signup')
    @Returns(AuthDto)
    @Status(HTTPStatusCodes.CREATED)
    @Validate()
    async signup(
        @Validator() @BodyParams() data: SignupDto
    ) {
        const user = await this.authService.createUser(data);
        const authData = await this.authService.authenticateLocal(user.email, data.password);

        return authData;
    }

    /**
     * This end point used for authentication with fb access_token provided
     * Useful when the access_token is obtained via client-side sdk
     */
    @Post('/facebook/token')
github scopsy / node-typescript-starter / src / controllers / user / user.controller.ts View on Github external
import { Returns } from 'ts-express-decorators/lib/swagger';
import { User } from '../../dal/User';
import { UserService } from '../../services/user/user.service';
import { IAppRequest } from '../../types/app.types';

@Controller('/users')
@Authenticated()
export class UserController {
    constructor(
        private userService: UserService
    ) {

    }

    @Get('/:id([0-9a-f]{24})')
    @Returns(User)
    async getUser(@Required() @PathParams('id') id: string): Promise {
        return await this.userService.getUserById(id);
    }

    @Get('/auth-test')
    async authTest(@Req() req: IAppRequest): Promise {

        return `hello ${req.user._id}`;
    }
}