How to use the typescript-rest.Errors.BadRequestError function in typescript-rest

To help you get started, we’ve selected a few typescript-rest 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 vellengs / typerx / packages / server / src / modules / core / setting.service.ts View on Github external
async update(entry: EditSettingDto): Promise {
    if (entry.id) {
      const result = await Db.Setting.findOneAndUpdate(
        { _id: entry.id },
        { $set: entry },
        { upsert: true, 'new': true }).exec();
      return this.pure(result);
    } else {
      throw new Errors.BadRequestError('settings not found');
    }
  }
github vellengs / typerx / packages / server / src / util / validator.ts View on Github external
export function validator(req: Request): Request {
    if (req.body.userId != undefined) {
        throw new Errors.BadRequestError("userId not present");
    } else {
        return req
    }
}
github vellengs / typerx / packages / server / src / modules / core / menu.service.ts View on Github external
async update(
    entry: EditMenuDto,
  ): Promise {


    if (entry.id === entry.parent) {
      throw new Errors.BadRequestError('can not be set parent by self.');
    }

    const doc: any = await Db.Menu.findOneAndUpdate(
      {
        _id: entry.id,
      },
      entry,
    ).exec();
    return doc;
  }
github vellengs / typerx / packages / server / src / modules / core / user.service.ts View on Github external
entry, { upsert: true, new: true },
    ).exec();

    entry.profile = profile._id;
    const account = await Db.Account.findOneAndUpdate(
      {
        _id: request.user.id,
      },
      entry, { new: true },
    ).populate('profile').exec();

    if (profile) {
      const instance = Repository.mergeProfile(account);
      return instance;
    } else {
      throw new Errors.BadRequestError('user not found');
    }
  }
github vellengs / typerx / packages / server / src / modules / core / group.service.ts View on Github external
async update(
    entry: EditGroupDto,
  ): Promise {

    if (entry.id === entry.parent) {
      throw new Errors.BadRequestError('can not be set parent by self.');
    }

    const doc: any = await Db.Group.findOneAndUpdate(
      {
        _id: entry.id,
      },
      entry,
    ).exec();
    return doc;
  }
github vellengs / typerx / packages / server / src / modules / cms / category.service.ts View on Github external
async update(
        entry: EditCategoryDto,
    ): Promise {
        
        if (entry.id === entry.parent) {
            throw new Errors.BadRequestError('can not be set parent by self.');
        }

        const doc: any = await Db.Category.findOneAndUpdate(
            {
                _id: entry.id,
            },
            entry,
        ).exec();
        return doc;
    }