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 22:49:08 -05:00
|
|
|
import getParams from '../../get-params';
|
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
requireCredential: false,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
username: {
|
|
|
|
validator: $.str.pipe(validateUsername)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-12-28 16:49:51 -06:00
|
|
|
|
2018-07-05 12:58:29 -05:00
|
|
|
export default async (params: any) => new Promise(async (res, rej) => {
|
2018-11-01 22:49:08 -05:00
|
|
|
const [ps, psErr] = getParams(meta, params);
|
|
|
|
if (psErr) return rej(psErr);
|
2016-12-28 16:49:51 -06:00
|
|
|
|
|
|
|
// Get exist
|
|
|
|
const exist = await User
|
|
|
|
.count({
|
2018-03-27 02:51:12 -05:00
|
|
|
host: null,
|
2018-11-01 22:49:08 -05:00
|
|
|
usernameLower: ps.username.toLowerCase()
|
2016-12-28 16:49:51 -06:00
|
|
|
}, {
|
|
|
|
limit: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
// Reply
|
|
|
|
res({
|
|
|
|
available: exist === 0
|
|
|
|
});
|
|
|
|
});
|