Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {Body, Post, JsonController, UseBefore, BadRequestError, Param, Put, Authorized} from 'routing-controllers';
import passportJwtMiddleware from '../security/passportJwtMiddleware';
import {UnitBaseController} from './UnitBaseController';
import {FreeTextUnit} from '../models/units/FreeTextUnit';
import {IFreeTextUnit} from '../../../shared/models/units/IFreeTextUnit';
@JsonController('/units/free-texts')
@UseBefore(passportJwtMiddleware)
@Authorized(['teacher', 'admin'])
export class FreeTextUnitController extends UnitBaseController {
/*
@Post('/')
addUnit(@Body() data: any) {
// discard invalid requests
this.checkPostParam(data);
return new FreeTextUnit(data.model).save()
.then((savedFreeTextUnit) => {
return this.pushToLecture(data.lectureId, savedFreeTextUnit);
});
}
*/
Body,
JsonController,
Authorized,
QueryParam,
Param,
Put,
Delete
} from "routing-controllers";
import {
PaginationInfo,
IPaginationQueryParam
} from "../../decorators/PaginationInfo";
import { CrudServices, IFetchPageQuery } from "../../services/CrudServices";
import { CurrentUser } from "../../decorators/CurrentUser";
@JsonController("/customers")
@Authorized()
export class CustomersController {
private crudServices: CrudServices;
constructor() {
this.crudServices = new CrudServices();
this.crudServices.setEntity(Customer);
}
@Get("/:id")
public async getCustomerById(@Param("id") id: string): Promise {
const res = await this.crudServices.fetchById(id);
return res || {};
}
@Get()
import {Authorized, BadRequestError, Body, Get, JsonController, Param, Post, Put, UseBefore} from 'routing-controllers';
import passportJwtMiddleware from '../security/passportJwtMiddleware';
import {
API_NOTIFICATION_TYPE_ALL_CHANGES,
INotificationSettingsModel,
NotificationSettings
} from '../models/NotificationSettings';
import {INotificationSettings} from '../../../shared/models/INotificationSettings';
@JsonController('/notificationSettings')
@UseBefore(passportJwtMiddleware)
export class NotificationSettingsController {
/**
* @api {get} /api/notificationSettings/user/:id Get notification settings per user
* @apiName GetNotificationSettings
* @apiGroup NotificationSettings
* @apiPermission student
* @apiPermission teacher
* @apiPermission admin
*
* @apiParam {String} id User ID.
*
* @apiSuccess {INotificationSettingsModel[]} settings List of notification settings.
*
* @apiSuccessExample {json} Success-Response:
import {
IAccountsModule,
IBlocksModule,
IBlocksModuleUtils,
IDelegatesModule,
IForgeModule,
ISystemModule,
} from '../ioc/interfaces/modules';
import { Symbols } from '../ioc/symbols';
import { Accounts2DelegatesModel, AccountsModel, BlocksModel, TransactionsModel } from '../models';
import schema from '../schema/delegates';
import { publicKey } from '../types/sanityTypes';
import { APIError, DeprecatedAPIError } from './errors';
import { ForgingApisWatchGuard } from './utils/forgingApisWatchGuard';
@JsonController('/api/delegates')
@injectable()
@IoCSymbol(Symbols.api.delegates)
export class DelegatesAPI {
@inject(Symbols.generic.zschema)
public schema: z_schema;
@inject(Symbols.modules.accounts)
private accounts: IAccountsModule;
@inject(Symbols.modules.blocks)
private blocks: IBlocksModule;
@inject(Symbols.modules.blocksSubModules.utils)
private blocksUtils: IBlocksModuleUtils;
@inject(Symbols.modules.delegates)
private delegatesModule: IDelegatesModule;
@inject(Symbols.helpers.ed)
private ed: Ed;
@inject(Symbols.modules.forge)
import { Request, Response } from 'express';
import { ReflectiveInjector, Injector } from 'injection-js';
import { JsonController, Param, Body, Get, Post, Put, Delete, Req, Res } from 'routing-controllers';
import { Speakers, Speaker } from '../models/speaker';
import { SpeakerRepository } from '../data/speaker-repository';
const injector = ReflectiveInjector.resolveAndCreate([
SpeakerRepository
]);
@JsonController()
export class SpeakerController {
private repository: SpeakerRepository;
constructor() {
this.repository = injector.get(SpeakerRepository);
}
@Get('/speakers')
getAll() {
return this.repository.getAll();
}
@Get('/speakers/:id')
getOne(@Req() request: Request,
@Res() response: Response,
@Param("id") id: string) {
import {Get, Post, JsonController, Param, Body, Req, UseBefore} from 'routing-controllers';
import {JSONWebToken} from '../../utils/JSONWebToken';
import {Thing} from '../../entities/thing.model';
import {UserAuthenticatorMiddleware} from '../../middleware/UserAuthenticatorMiddleware';
import {BlockchainClient} from '../../blockchain/client/blockchainClient';
import {Service} from 'typedi';
@JsonController('/things')
@UseBefore(UserAuthenticatorMiddleware)
@Service()
export class ThingsController {
public constructor(private blockchainClient: BlockchainClient) { }
@Get('/:id')
public getThingsByUserID(@Param('id') userID: string, @Req() request: any): any {
let enrollmentID = new JSONWebToken(request).getUserID();
return this.blockchainClient.query('getThingsByUserID', [userID], enrollmentID);
}
@Post('/')
public post(@Body() thing: Thing, @Req() request: any): any {
let enrollmentID = new JSONWebToken(request).getUserID();
return this.blockchainClient.invoke('createThing', [JSON.stringify(thing)], enrollmentID);
}
JsonController,
Authorized,
QueryParam,
Param,
Put,
Delete
} from 'routing-controllers';
import { CrudServices, IFetchPageQuery } from '../../services/CrudServices';
import { CurrentUser } from '../../decorators/CurrentUser';
import {
PaginationInfo,
IPaginationQueryParam
} from '../../decorators/PaginationInfo';
@JsonController('/productTypes')
@Authorized()
export class ProductTypesController {
private crudServices: CrudServices;
constructor() {
this.crudServices = new CrudServices();
this.crudServices.setEntity(ProductType);
}
@Get('/all/items')
public async getAllProductTypes(): Promise {
return await this.crudServices.fetchAll();
}
@Get('/:id')
public async getProductTypeById(@Param('id') id: string): Promise {
* - tag
* - properties:
* id:
* type: integer
* format: int32
* description: タグID
* createdAt:
* type: string
* format: date-time
* description: 登録日時
*/
/**
* ブログ記事コントローラクラス。
*/
@JsonController('/articles')
export class BlogController {
/**
* ブログ記事サービス。
*/
@Inject()
articleService: ArticleService;
/**
* @swagger
* /articles:
* get:
* tags:
* - articles
* summary: ブログ記事一覧
* description: ブログ記事の一覧を取得する。
import { Authorized, Body, JsonController, Post, QueryParam, QueryParams } from 'routing-controllers';
import { OrmRepository } from 'typeorm-typedi-extensions';
import { User } from '../../../database/entities';
import { RoleRepository, UserRepository } from '../../../database/repositories';
import { BcryptService } from '../../../services';
@JsonController('/users')
export class GetUsersController {
constructor(
@OrmRepository() private userRepository: UserRepository,
@OrmRepository() private roleRepository: RoleRepository,
private bcryptService: BcryptService
) {}
@Post()
public async execute(
@Body() user: User
) {
const role = await this.roleRepository.getRoleByName(user.roles[0].name);
if (!role) {
throw new Error(`Cannot create user, cannot get role: ${user.roles[0].name}`);
}