old_contents: 'use strict';
  
  /**
   * Module dependencies
   */
  import User from '../../models/user';
  
  /**
   * Check available username
   *
   * @param {Object} params
   * @param {Object} res
   * @return {Promise<object>}
   */
  module.exports = async (params, res) =>
  	new Promise(async (res, rej) =>
  {
  	// Init 'username' parameter
  	const username = params.username;
  	if (username === undefined || username === null || username === '') {
  		return res(400, 'username-is-required');
  	}
  
  	if (!/^[a-zA-Z0-9\-]{3,20}$/.test(username)) {
  		return res(400, 'invalid-username');
  	}
  
  	const exist = await User
  		.count({
  			username_lower: username.toLowerCase()
  		}, {
  			limit: 1
  		});
  
  	res({
  		available: exist === 0
  	});
  });
  
new_contents: 'use strict';
  
  /**
   * Module dependencies
   */
  import User from '../../models/user';
  
  /**
   * Check available username
   *
   * @param {Object} params
   * @return {Promise<object>}
   */
  module.exports = async (params) =>
  	new Promise(async (res, rej) =>
  {
  	// Get 'username' parameter
  	const username = params.username;
  	if (username == null || username == '') {
  		return rej('username-is-required');
  	}
  
  	// Validate username
  	if (!/^[a-zA-Z0-9\-]{3,20}$/.test(username)) {
  		return rej('invalid-username');
  	}
  
  	// Get exist
  	const exist = await User
  		.count({
  			username_lower: username.toLowerCase()
  		}, {
  			limit: 1
  		});
  
  	// Reply
  	res({
  		available: exist === 0
  	});
  });
  
subject: Fix bug