1.0.0 • Published 4 years ago

@lemonpeach/sequelize-to-json-schema v1.0.0

Weekly downloads
7
License
MPL-2.0
Repository
github
Last release
4 years ago

sequelize-to-json-schema

Example

import Errors from '@feathersjs/errors';
import Ajv from 'ajv';
import { validateSchema } from 'feathers-hooks-common';
import jsonSchema from '@lemonpeach/sequelize-to-json-schema';

const getSchema = context => jsonSchema(
  context.service.Model,
  ['createdAt', 'updatedAt', 'id']
);

export const validateSchemaHook = async (
  context,
  schema = getSchema(context)
) => {
  try {
    switch (context.method) {
      case 'patch':
      case 'update':
        schema.required = [];
      /* eslint no-fallthrough: "error" */
      case 'create':
        await validateSchema(schema, new Ajv())(context);
        break;
      default:
        break;
    }
  } catch (error) {
   // handle error
  }
  return context;
};
1.0.0

4 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.0

5 years ago