How to use the rulr/validateData function in rulr

To help you get started, we’ve selected a few rulr 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 kube-js / kube-ts-server / src / presenter / express / api / v1 / routes / users / functions / beforeUpdateItem / index.ts View on Github external
beforeHandler: async ({ req }: HookOptions) => {
      const user = await getAuthenticatedUser({ req, config });

      // FYI: user should be able to update itself without permission
      if (req.params.id !== user.id) {
        await hasPermission({ req, user, config });
      }

      const payload: any = _pick(Object.keys(schema), req.body);

      validateData(rules)(payload);

      req.body.password = !_isNil(req.body.password)
        ? await hashPassword(req.body.password)
        : undefined;
        
      req.body.updatedAt = getUtcDate();
    },
    config,
github kube-js / kube-ts-server / src / presenter / express / api / v1 / routes / courses / functions / beforeCreateItem / index.ts View on Github external
beforeHandler: async ({ req }: HookOptions) => {
      const user = await getAuthenticatedUser({ req, config });

      await hasPermission({ req, user, config });

      const payload: any = _pick(Object.keys(beforeCreateSchema), req.body);

      validateData(rules)(payload);

      // user who has permission to create an article is an author
      req.body.user_id = user.id;
    },
    config,
github kube-js / kube-ts-server / src / presenter / express / api / v1 / routes / users / functions / beforeReplaceItem / index.ts View on Github external
beforeHandler: async ({ req }: HookOptions) => {
      const user = await getAuthenticatedUser({ req, config });

      // FYI: user should be able to update itself without permission
      if (req.params.id !== user.id) {
        await hasPermission({ req, user, config });
      }

      const payload: any = _pick(Object.keys(schema), req.body);

      validateData(rules)(payload);

      req.body.password = !_isNil(req.body.password)
        ? await hashPassword(req.body.password)
        : undefined;

      req.body.updatedAt = getUtcDate();
    },
    config,
github kube-js / kube-ts-server / src / presenter / express / api / v1 / routes / roles / functions / assignRolePermission / index.ts View on Github external
catchErrors(config, async (req, res) => {
    const user = await getAuthenticatedUser({ req, config });

    await hasPermission({ req, user, config });

    const { role_id } = req.params;
    const { permission_id } = req.body;

    validateData(rules)({ role_id, permission_id });

    await config.service.assignRolePermission({
      permissionId: permission_id,
      roleId: role_id,
    });

    const translations = config.translator({ req });

    res.status(CREATED).json({
      message: translations.created(),
    });
  });
github kube-js / kube-ts-server / src / presenter / express / api / v1 / routes / utils / beforeReplaceItem / index.ts View on Github external
beforeHandler: async ({ req }: HookOptions) => {
      const user = await getAuthenticatedUser({ req, config });

      if (req.params.id !== user.id) {
        await hasPermission({ req, user, config });
      }

      const payload: any = _pick(Object.keys(config.beforeReplaceSchema), req.body);

      validateData(config.beforeReplaceRules)(payload);

      req.body.updatedAt = getUtcDate();
    },
    config,
github kube-js / kube-ts-server / src / presenter / express / api / v1 / routes / auth / resendVerifyToken / index.ts View on Github external
catchErrors(config, async (req, res) => {
    const { email } = req.body;

    validateData(rules)({ email });

    const { appConfig, translator } = config;

    const translations = translator({ req });

    const { items } = await config.service.users.getItems({
      filter: {
        email,
      },
    });

    if (items.length === 0) {
      throw new ItemNotFoundError('User');
    }

    const link = getVerifyEmailUrl({
github kube-js / kube-ts-server / src / presenter / express / api / v1 / routes / utils / beforeCreateItem / index.ts View on Github external
beforeHandler: async ({ req }: HookOptions) => {
      const user = await getAuthenticatedUser({ req, config });

      await hasPermission({ req, user, config });

      const payload: any = _pick(Object.keys(config.beforeCreateSchema), req.body);

      validateData(config.beforeCreateRules)(payload);
    },
    config,
github kube-js / kube-ts-server / src / presenter / express / api / v1 / routes / users / functions / beforeCreateItem / index.ts View on Github external
beforeHandler: async ({ req }: HookOptions) => {
      const user = await getAuthenticatedUser({ req, config });

      await hasPermission({ req, user, config });

      const payload: any = _pick(Object.keys(schema), req.body);
      
      validateData(rules)(payload);
    },
    config,
github kube-js / kube-ts-server / src / presenter / express / api / v1 / routes / auth / register / index.ts View on Github external
catchErrors(config, async (req, res) => {
    const payload: any = _pick(Object.keys(schema), req.body);

    const { password_confirmation, ...data } = validateData(rules)(payload);
    const {
      bio,
      dateOfBirth,
      email,
      firstName,
      gender,
      lastName,
      password,
    } = toCamel(data);

    const { appConfig, translator } = config;

    const translations = translator({ req });

    const verifyToken = uuid();
github kube-js / kube-ts-server / src / presenter / express / api / v1 / routes / auth / resetPassword / index.ts View on Github external
catchErrors(config, async (req, res) => {
    const payload: any = _pick(Object.keys(schema), req.body);

    const { token, password } = validateData(rules)(payload);
    const { appConfig, translator } = config;

    const translations = translator({ req });

    const mailOptions: BaseOptions = {
      from: appConfig.repo.mail.from,
      html: translations.resetPasswordHtml(),
      subject: translations.resetPasswordSubject(),
      text: translations.resetPasswordText(),
    };

    await config.service.auth.resetPassword({
      mailOptions,
      password,
      token,
    });

rulr

Validation and unit conversion errors in TypeScript at compile-time. Started in 2016.

MIT
Latest version published 4 days ago

Package Health Score

72 / 100
Full package analysis