Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Sequelize = require('sequelize');
- module.exports = function(app) {
- const sequelizeClient = app.get('sequelizeClient');
- const user = sequelizeClient.define('users', {
- first_name: {
- type: Sequelize.STRING
- },
- last_name: {
- type: Sequelize.STRING
- },
- gender: {
- type: Sequelize.STRING
- },
- date_of_birth: {
- type: Sequelize.STRING
- },
- mobilePhone: {
- type: Sequelize.STRING,
- unique: true
- },
- email: {
- type: Sequelize.STRING,
- unique: true
- },
- password: {
- type: Sequelize.STRING,
- allowNull: true
- },
- facebookId: {
- type: Sequelize.STRING,
- unique: true,
- allowNull: true
- },
- facebook: {
- type: Sequelize.ARRAY(Sequelize.STRING),
- allowNull: true
- },
- avatar: {
- type: Sequelize.STRING,
- allowNull: true
- },
- ownerId: {
- type: Sequelize.STRING,
- allowNull: true
- },
- }, {
- freezeTableName: true
- });
- user.sync();
- return user;
- };
- const { authenticate } = require('feathers-authentication').hooks;
- const commonHooks = require('feathers-hooks-common');
- const { restrictToOwner } = require('feathers-authentication-hooks');
- const { lowerCase } = require('feathers-hooks-common');
- const { validateSchema } = require('feathers-hooks-common');
- const { hashPassword } = require('feathers-authentication-local').hooks;
- const { facebookRegister } = require('../../hooks/facebook-data');
- const { getEmailFromFacebook } = require('../../hooks/get-email-from-facebook');
- //const addOwnerId = require('../../hooks/add-owner-id');
- const { iff, isNot, discard, setCreatedAt, setUpdatedAt } = require('feathers-hooks-common');
- const restrict = [
- authenticate('jwt')
- ];
- const Ajv = require('ajv');
- const ajv = new Ajv({ allErrors: true, $data: true });
- ajv.addFormat('allNumbers', '^d+$');
- const createSchema = {
- title: 'User Schema',
- // $schema: '../schemas/schema-01#',
- type: 'object',
- required: [ 'first_name', 'last_name', 'gender', 'date_of_birth', 'email', 'password', 'mobilePhone' ],
- additionalProperties: false,
- properties: {
- first_name : { type: 'string', maxLength: 100, minLength: 3 },
- last_name: { type: 'string', maxLength: 100, minLength: 3 },
- gender: { type: 'string', maxLength: 100, minLength: 4 },
- date_of_birth: { type: 'string', maxLength: 100, minLength: 6 },
- email: { type: 'string', maxLength: 100, minLength: 6 },
- password: { type: 'string', maxLength: 30, minLength: 4 },
- mobilePhone: { type: 'string' },
- facebookId: { type: 'string', maxLength: 500, minLength: 6 },
- facebook: { type: 'string', maxLength: 900, minLength: 6 }
- }
- };
- module.exports = {
- before: {
- all: [],
- find: [...restrict ],
- get: [ ...restrict ],
- create: [ facebookRegister(), hashPassword() ],
- update: [ restrictToOwner() ],
- patch: [ ...restrict, hashPassword() ],
- remove: [ ...restrict ]
- },
- after: {
- all: [
- commonHooks.when(
- hook => hook.params.provider,
- commonHooks.discard('password')
- )
- ],
- find: [],
- get: [],
- create: [],
- update: [setUpdatedAt()],
- patch: [],
- remove: []
- },
- error: {
- all: [],
- find: [],
- get: [],
- create: [],
- update: [],
- patch: [],
- remove: []
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement