How to use the routing-controllers.Get function in routing-controllers

To help you get started, we’ve selected a few routing-controllers 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 RiseVision / rise-node / src / apis / delegatesAPI.ts View on Github external
}
        });
      } else if (['username', 'address', 'publicKey'].indexOf(d.sortField) > -1) {
        delegates.sort((a, b) => {
          if (d.sortMethod === 'ASC') {
            return a[d.sortField].localeCompare(b[d.sortField]);
          } else {
            return b[d.sortField].localeCompare(a[d.sortField]);
          }
        });
      }
    }
    return { delegates: delegates.slice(d.offset, d.limit), totalCount: d.count };
  }

  @Get('/fee')
  @ValidateSchema()
  public async getFee(@SchemaValid(schema.getFee, { castNumbers: true })
                      @QueryParams() params: { height?: number }) {
    const f            = this.system.getFees(params.height);
    const { delegate } = f.fees;
    delete f.fees;
    return { ...f, ... { fee: delegate } };

  }

  @Get('/forging/getForgedByAccount')
  @ValidateSchema()
  public async getForgedByAccount(@SchemaValid(schema.getForgedByAccount, { castNumbers: true })
                                  // tslint:disable-next-line max-line-length
                                  @QueryParams() params: { generatorPublicKey: publicKey, start?: number, end?: number }) {
    if (typeof(params.start) !== 'undefined' || typeof(params.end) !== 'undefined') {
github TEsTsLA / apijson / src / controller / Usercontroller.ts View on Github external
const msg = this.userSrv.createMsg();
        user.firstName = MockJs.Random.first();
        user.lastName = MockJs.Random.last();
        user.cName = MockJs.Random.cname() + MockJs.Random.cfirst();
        user.age = getRandom(60);
        user.sex = getRandom(100) > 50 ? 0 : 1
        // save
        await msg.save();
        let _msg = this.userSrv.createMsg()
        await _msg.save()
        user.message = [msg, _msg]
        await user.save()
        return "Success";
    }

    @Get("/users/:id")
    async getOne(@Param("id") id: number) {
        return await User.find({ relations: ["message"], where: { id: id } });
    }

    @Post("/users")
    post(@Body() user: any) {
        return "Saving user...";
    }

    @Put("/users/:id")
    put(@Param("id") id: number, @Body() user: any) {
        return "Updating a user...";
    }

    @Delete("/users/:id")
    remove(@Param("id") id: number) {
github geli-lms / geli / api / src / controllers / CourseController.ts View on Github external
*             "id": "5a037e6a60f72236d8e7c815"
   *         },
   *         "active": true,
   *         "__v": 1,
   *         "whitelist": [],
   *         "enrollType": "free",
   *         "lectures": [],
   *         "students": [],
   *         "teachers": [],
   *         "id": "5a037e6b60f72236d8e7c83d",
   *         "hasAccessKey": false
   *     }
   *
   * @apiError NotFoundError
   */
  @Get('/:id')
  async getCourse(@Param('id') id: string, @CurrentUser() currentUser: IUser) {
    const course = await Course.findOne({
      ...this.userReadConditions(currentUser),
      _id: id
    })
    // TODO: Do not send lectures when student has no access
      .populate({
        path: 'lectures',
        populate: {
          path: 'units',
          virtuals: true,
          populate: {
            path: 'progressData',
            match: {user: {$eq: currentUser._id}}
          }
        }
github geli-lms / geli / api / src / controllers / ReportController.ts View on Github external
import passportJwtMiddleware from '../security/passportJwtMiddleware';
import {Progress} from '../models/Progress';
import {IProgress} from '../../../shared/models/IProgress';
import {IUser} from '../../../shared/models/IUser';
import * as mongoose from 'mongoose';
import ObjectId = mongoose.Types.ObjectId;
import {Course} from '../models/Course';
import {ILecture} from '../../../shared/models/ILecture';
import {IUnit} from '../../../shared/models/units/IUnit';

@JsonController('/report')
@UseBefore(passportJwtMiddleware)
@Authorized(['teacher', 'admin'])
export class ReportController {

  @Get('/units/:id')
  getUnitProgress(@Param('id') id: string) {
    return Progress.find({'unit': id})
    .then((progresses) => progresses.map((progress) => progress.toObject({virtuals: true})));
  }

  @Get('/overview/courses/:id')
  getCourseOverview(@Param('id') id: string) {
    const coursePromise = Course.findOne({_id: id})
    .select({
      name: 1,
      lectures: 1,
      students: 1
    })
    .populate({
      path: 'lectures',
      populate: {
github SammyLiang97 / Mikey / src / controllers / todo.controller.ts View on Github external
@Get('/todo/:date')
    async getTodos(@Param('date') date: string,
                   @State('user') user: Payload
    ): Promise {
        return await this.todoService.todoModel.find({
            createdAt: {
                $gte: new Date(date).getTime(),
                $lt: new Date(date).getTime() + ms('1d')

            },
            user: user.id
        })
    }

    @Get('/todo/date/:year_month')
    async getTodosDateSet(@Param('year_month') year_month: string, @State('user') user: Payload) {
        let res = []
        await this.todoService.todoModel.find({user: user.id, createdAt: {$gte: new Date(year_month).getTime(), $lte: new Date(year_month).getTime() + ms('31d')}})
            .then(data => {
                data.forEach(t => {
                    res.push(`${t.createdAt.getFullYear()}/${t.createdAt.getMonth() + 1}/${t.createdAt.getDate()}`)
                })
            })


        return Array.from(new Set(res))
    }

    @Put('/todo/:id')
    async UpdateTodo(@Param('id') id: string,
                     @Body() todo: ITodo,
github shanmugharajk / react-point-of-sale / api / src / controllers / receiving / ReceivingController.ts View on Github external
import { IFetchPageQuery } from "../../services/CrudServices";
import { ReceivingServices } from "../../services/ReceivingServices";
import { CurrentUser } from "../../decorators/CurrentUser";

@JsonController("/receivings")
@Authorized()
export class ReceivingsController {
  constructor(private receivingServices: ReceivingServices) {}

  @Get("/:id")
  public async getReceivingById(@Param("id") id: string): Promise {
    const res = await this.receivingServices.fetchById(id);
    return res || {};
  }

  @Get()
  public async getReceivings(
    @PaginationInfo() paginationInfo: IPaginationQueryParam,
    @QueryParam("q") search?: string
  ): Promise {
    const query: IFetchPageQuery = {
      search,
      perPage: paginationInfo.perPage,
      page: paginationInfo.pageNo
    };
    return await this.receivingServices.fetchPages(query);
  }

  @Post()
  public async createNewReceiving(
    @Body() Receiving: Receiving,
    @CurrentUser() userid: string
github art-software / art-core / packages / art-demo-miniprogram / mock / home / HomeController.ts View on Github external
import { Controller, Get } from 'routing-controllers';

@Controller()
export default class TabHomeController {

  @Get('/demo/get')
  public portalGet() {

    return {
      success: true,
      code: '0000',
      message: 'success',
      data: {
        name: 'Tom'
      }
    };
  }
}
github nicolaspearson / node.api.boilerplate / src / controllers / UserController.ts View on Github external
*       403:
	 *         $ref: '#/responses/Forbidden'
	 *       404:
	 *         $ref: '#/responses/NotFound'
	 *       405:
	 *         $ref: '#/responses/MethodNotAllowed'
	 *       406:
	 *         $ref: '#/responses/NotAcceptable'
	 *       500:
	 *         $ref: '#/responses/InternalServerError'
	 *       504:
	 *         $ref: '#/responses/GatewayTimeout'
	 *       default:
	 *         $ref: '#/responses/DefaultError'
	 */
	@Get('/users/health')
	@Authorized()
	public async userHealth(
		@CurrentUser({ required: true })
		user: User
	): Promise {
		if (user) {
			return user.sanitize();
		}
		throw new UnauthorizedError('Invalid Token');
	}

	/**
	 * @swagger
	 * /users/forgotPassword:
	 *   post:
	 *     summary: Allow a user to reset their password
github geli-lms / geli / api / src / controllers / ProgressController.ts View on Github external
*                 "5ab2b8dd6fab4a3ae0cd6736": false,
   *                 "5ab2b8dd6fab4a3ae0cd6735": true
   *             },
   *             "5ab2b8dd6fab4a3ae0cd6731": {
   *                 "5ab2b8dd6fab4a3ae0cd6733": false,
   *                 "5ab2b8dd6fab4a3ae0cd6732": true
   *             }
   *         },
   *         "type": "task-unit-progress",
   *         "user": "5a037e6a60f72236d8e7c813",
   *         "__v": 0,
   *         "__t": "task-unit-progress",
   *         "id": "5ab2b9516fab4a3ae0cd6737"
   *     }]
   */
  @Get('/units/:id')
  getUnitProgress(@Param('id') id: string) {
    return Progress.find({'unit': id})
      .then((progresses) => progresses.map((progress) => progress.toObject({virtuals: true})));
  }

  /**
   * @api {get} /api/progress/courses/:id Get course progress
   * @apiName GetCourseProgress
   * @apiGroup Progress
   *
   * @apiParam {String} id Course ID.
   *
   * @apiSuccess {Progress[]} progresses List of progress.
   *
   * @apiSuccessExample {json} Success-Response:
   *     [{
github ChatPlug / ChatPlug / src / services / api / controllers / ConnectionsController.ts View on Github external
import ThreadConnection from '../../../entity/ThreadConnection'
import { Repository } from 'typeorm'
import Thread from '../../../entity/Thread'
import Service from '../../../entity/Service'
import Message from '../../../entity/Message'

@JsonController('/connections')
export default class ConnectionsController {
  connectionsRepository: Repository
  context: ChatPlugContext
  constructor(context: ChatPlugContext) {
    this.context = context
    this.connectionsRepository = context.connection.getRepository(ThreadConnection)
  }

  @Get('/')
  async getConnections() {
    return this.connectionsRepository.find({ deleted: false })
  }

  @Get('/:id')
  async getConnectionById(@Param('id') id : number) {
    return this.connectionsRepository.findOne({ id })
  }

  @Delete('/:id')
  async deleteConnectionById(@Param('id') id : number) {
    await this.context.connection.createQueryBuilder()
      .update(Thread)
      .set({ deleted: true })
      .where('threadConnection.id = :threadConnection', { threadConnection: id })
      .execute()