const { Forbidden } = require('@feathersjs/errors');
const logger = require('../../logger');
const hooks = require('./hooks');

class Service {
	constructor(options) {
		this.options = options || {};
		this.docs = {};
	}

	/**
     * request headers
     * set Content-Type = application/json
     * set Authorization = Bearer [jwt]
     */
	find(params) {
		const { userId } = params.account;
		const userServiceParams = {
			query: {
				$populate: ['roles'],
			},
		};
		return this.app.service('/users').get(userId, userServiceParams).catch((err) => {
			logger.warning(err);
			throw new Forbidden('Your access token is not valid.');
		});
	}

	setup(app, path) {
		this.app = app;
	}
}

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

	app.use('/me', new Service());

	const me = app.service('/me');

	me.hooks(hooks);
};

@@ -10,16 +10,30 @@
 orbidden
+, GeneralError
  %7D = req
@@ -349,16 +349,22 @@
     */%0A%09
+async 
 find(par
@@ -492,14 +492,46 @@
 ;%0A%09%09
-return
+let user = %7B%7D;%0A%09%09try %7B%0A%09%09%09user = await
  thi
@@ -588,23 +588,25 @@
 ams)
-.
+;%0A%09%09%7D 
 catch
-(
+ 
 (err)
- =%3E
  %7B%0A%09
@@ -690,17 +690,227 @@
 .');%0A%09%09%7D
-)
+%0A%09%09try %7B%0A%09%09%09user.schoolName = (await this.app.service('/schools').get(user.schoolId)).name;%0A%09%09%7D catch (err) %7B%0A%09%09%09logger.warning(err);%0A%09%09%09throw new GeneralError('Can%5C't find connected school.');%0A%09%09%7D%0A%09%09return user
 ;%0A%09%7D%0A%0A%09s

add schoolName to /me route (#738)