2017-03-08 12:50:09 -06:00
|
|
|
import $ from 'cafy';
|
2018-03-29 06:32:18 -05:00
|
|
|
import User from '../../../../models/user';
|
|
|
|
import { validateUsername } from '../../../../models/user';
|
2018-11-01 23:47:44 -05:00
|
|
|
import define from '../../define';
|
2018-11-01 22:49:08 -05:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-22 20:20:58 -06:00
|
|
|
tags: ['users'],
|
|
|
|
|
2018-11-01 22:49:08 -05:00
|
|
|
requireCredential: false,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
username: {
|
|
|
|
validator: $.str.pipe(validateUsername)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-12-28 16:49:51 -06:00
|
|
|
|
2019-02-21 20:46:58 -06:00
|
|
|
export default define(meta, async (ps) => {
|
2016-12-28 16:49:51 -06:00
|
|
|
// Get exist
|
2019-02-21 20:46:58 -06:00
|
|
|
const exist = await User.count({
|
|
|
|
host: null,
|
|
|
|
usernameLower: ps.username.toLowerCase()
|
|
|
|
}, {
|
|
|
|
limit: 1
|
|
|
|
});
|
2016-12-28 16:49:51 -06:00
|
|
|
|
2019-02-21 20:46:58 -06:00
|
|
|
return {
|
2016-12-28 16:49:51 -06:00
|
|
|
available: exist === 0
|
2019-02-21 20:46:58 -06:00
|
|
|
};
|
|
|
|
});
|