How to use the routing-controllers.NotFoundError 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 geli-lms / geli / api / src / controllers / ProgressController.ts View on Github external
async updateProgress(@Param('id') id: string, @Body() data: any, @CurrentUser() currentUser: IUser) {
    const progress = await Progress.findById(id);

    if (!progress) {
      throw new NotFoundError();
    }

    const unit: IUnitModel = await Unit.findById(progress.unit);
    ProgressController.checkDeadline(unit);

    // set user
    data.user = currentUser._id;

    progress.set(data);
    await progress.save();

    return progress.toObject();
  }
}
github geli-lms / geli / api / src / controllers / StudentConfigController.ts View on Github external
async deleteConfig(@Param('id') id: string) {
    const config = await StudentConfig.findById(id);
    if (!config) {
      throw new NotFoundError();
    }
    await config.remove();
    return {result: true};
  }
}
github ktanakaj / typeorm-example / typeorm-example / src / services / blog-service.ts View on Github external
async findOne(id): Promise {
		const blog = await this.blogRepository.findOne(id);
		if (!blog) {
			throw new NotFoundError('blog is not found');
		}
		return blog;
	}
github bradymholt / koa-vuejs-template / api / controllers / ContactController.ts View on Github external
async remove(@Param("id") id: number) {
    let existingContact = await this.getRepo().findOneById(id);
    if (!existingContact) {
      throw new NotFoundError("Not found");
    } else {
      let result = await this.getRepo().remove(existingContact);
    }
  }
github youzan / zan-proxy / src / core / services / rule.ts View on Github external
public async toggleRuleFile(name: string, checked: boolean) {
    if (!this.exist(name)) {
      throw new NotFoundError('找不到对应名称的转发规则集');
    }

    const ruleFile = this.rules[name];
    ruleFile.checked = checked;
    await this.saveRuleFile(name, ruleFile);
  }
github ChatPlug / ChatPlug / src / services / api / controllers / ServicesController.ts View on Github external
async getConfigurationWithSchema(@Param('id') id: number) {
    const service = await this.servicesRepository.findOneOrFail({ id })
    const config = this.context.config.getConfigurationWithSchema(service)
    if (!config) {
      throw new NotFoundError()
    }
    return config
  }
github geli-lms / geli / api / src / controllers / CourseController.ts View on Github external
async enrollStudent(@Param('id') id: string, @Body() data: any, @CurrentUser() currentUser: IUser) {
    let course = await Course.findById(id);
    if (!course) {
          throw new NotFoundError();
        }
        if (course.enrollType === 'whitelist') {
        const wUsers: IWhitelistUser[] = await  WhitelistUser.find().where({courseId: course._id});
            if (wUsers.filter(e =>
                e.firstName === currentUser.profile.firstName.toLowerCase()
                && e.lastName === currentUser.profile.lastName.toLowerCase()
                && e.uid === currentUser.uid).length <= 0) {
              throw new ForbiddenError(errorCodes.errorCodes.course.notOnWhitelist.code);
            }
        } else if (course.accessKey && course.accessKey !== data.accessKey) {
          throw new ForbiddenError(errorCodes.errorCodes.course.accessKey.code);
        }

        if (course.students.indexOf(currentUser._id) < 0) {
          course.students.push(currentUser);
          await new NotificationSettings({
github ktanakaj / typeorm-example / typeorm-example / src / services / article-service.ts View on Github external
async update(article: Article): Promise<article> {
		const old = await this.findOne(article.id);
		if (!old) {
			throw new NotFoundError('article is not found');
		}
		if (article.blog.id !== old.blog.id) {
			throw new BadRequestError("blog id can't be changed");
		}
		article.tags = await this.relateTags(article.tags);
		return this.articleRepository.save(Object.assign(old, article));
	}
</article>
github ChatPlug / ChatPlug / src / services / api / controllers / ServicesController.ts View on Github external
async createNewInstance(
    @BodyParam('moduleName', { required: true }) serviceModuleName: string,
    @BodyParam('instanceName', { required: true }) serviceInstanceName: string,
    @BodyParam('config', { required: true, parse: true }) configuration: any,
  ) {
    const serviceModule = (await this.context.serviceManager.getAvailableServices()).find(
      el => el.moduleName === serviceModuleName,
    )
    if (!serviceModule) {
      throw new NotFoundError()
    }

    const schema = nativeRequire(serviceModule.modulePath).Config
    const fieldList = Reflect.getMetadata(
      fieldListMetadataKey,
      new schema(),
    ) as string[]
    if (!fieldList.every(el => configuration[el] !== undefined)) {
      throw new BadRequestError('Config does not match schema')
    }

    if (!serviceModule) {
      throw new NotFoundError('Service with given name does not exist')
    }

    const service = new Service()
github youzan / zan-proxy / src / core / services / plugin.ts View on Github external
public uninstall(pluginName: string) {
    if (!this.has(pluginName)) {
      throw new NotFoundError('该插件不存在');
    }
    return new Promise((resolve, reject) => {
      const uninstall = () => {
        npm.commands.uninstall([pluginName, this.pluginInstallDir], err => {
          if (err) {
            return reject(err);
          }
          const restPlugins = this.getPlugins().filter(p => p.name !== pluginName);
          this.setPlugins(restPlugins);
          return resolve(restPlugins);
        });
      };
      const npmConfig = { loglevel: 'silent', prefix: this.pluginInstallDir };
      this.loadNpmConfig(npmConfig, uninstall);
    });
  }