'use strict';

const service = require('feathers-mongoose');
const user = require('./model');
const hooks = require('./hooks');
const registrationPinsHooks = require('./hooks/registrationPins');

module.exports = function () {
	const app = this;

	const options = {
		Model: user.userModel,
		paginate: {
			default: 25,
			max: 1000
		},
		lean: true
	};

	// Initialize our service with any options it requires
	app.use('/users', service(options));

	// Get our initialize service to that we can bind hooks
	const userService = app.service('/users');

	// Set up our before hooks
	userService.before(hooks.before(app));	// TODO: refactor

	// Set up our after hooks
	userService.after(hooks.after);

	/* registrationPin Service */
	app.use('/registrationPins', service({
		Model: user.registrationPinModel,
		paginate: {
			default: 500,
			max: 5000
		}
	}));
	const registrationPinService = app.service('/registrationPins');
	registrationPinService.before(registrationPinsHooks.before);
	registrationPinService.after(registrationPinsHooks.after);
};

@@ -187,16 +187,833 @@
 nPins');
+%0Aconst errors = require('feathers-errors');%0A%0Aconst userDataFilter=(user)=%3E%7B%0A%09return %7B%0A%09%09%22_id%22:user._id,%0A%09%09%22email%22:user.email,%0A%09%09%22firstName%22:user.firstName,%0A%09%09%22lastName%22:user.lastName,%0A%09%09%22importHash%22:user.importHash,%0A%09%09%22schoolId%22:user.schoolId,%0A%09%09%22birthday%22:user.birthday%0A%09%7D%0A%7D%0A%0Aclass UserHashService %7B%0A%09%09constructor(userService) %7B%0A%09%09%09this.userService = userService;%0A%09%09%09this.docs = %7B%7D%0A        %7D%0A%09%09%0A%09%09get(hash,params)%7B%09//can not use get becouse the hash can have / that mapped to non existing routes%0A%09%09%09console.log('hash',hash);%0A%09%09%09return this.userService.find(%7B query: %7B importHash: hash %7D%7D)%0A%09%09%09.then(users=%3E%7B%0A%09%09%09%09if(users.data.length%3C=0 %7C%7C users.data.length%3E1)%7B%0A%09%09%09%09%09throw new errors.BadRequest('Can not match the hash.');%0A%09%09%09%09%7D%0A%09%09%09%09return userDataFilter(users.data%5B0%5D);%0A%09%09%09%7D).catch(err=%3E%7B%0A%09%09%09%09return err;%0A%09%09%09%7D);%0A%09%09%7D%0A%7D
 %0A%0Amodule
@@ -1172,158 +1172,45 @@
 ;%0A%0A%09
-// Initialize our service with any options it requires%0A%09app.use('/users', service(options));%0A%0A%09// Get our initialize service to that we can bind hooks
+app.use('/users', service(options));%0A
 %0A%09co
@@ -1253,37 +1253,88 @@
 s');
-%0A%0A%09// Set up our befor
+%09%0A%09app.use('users/hash',new UserHashService(userService));%09//do not us
 e hooks
+%0A%0A%09
 %0A%09us
@@ -1391,36 +1391,8 @@
 ctor
-%0A%0A%09// Set up our after hooks
 %0A%09us

Add methode to user services for request users that are import via link.