This commit is contained in:
syuilo
2018-11-02 12:49:08 +09:00
parent befc35a3ac
commit a7e6b766be
26 changed files with 434 additions and 354 deletions

View File

@ -1,20 +1,27 @@
import $ from 'cafy';
import User from '../../../../models/user';
import { validateUsername } from '../../../../models/user';
import getParams from '../../get-params';
export const meta = {
requireCredential: false,
params: {
username: {
validator: $.str.pipe(validateUsername)
}
}
};
/**
* Check available username
*/
export default async (params: any) => new Promise(async (res, rej) => {
// Get 'username' parameter
const [username, usernameError] = $.str.pipe(validateUsername).get(params.username);
if (usernameError) return rej('invalid username param');
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Get exist
const exist = await User
.count({
host: null,
usernameLower: username.toLowerCase()
usernameLower: ps.username.toLowerCase()
}, {
limit: 1
});