2017-03-08 20:50:09 +02:00
|
|
|
import $ from 'cafy';
|
2018-11-02 06:47:44 +02:00
|
|
|
import define from '../../define';
|
2019-07-22 04:15:00 +03:00
|
|
|
import { Users, UsedUsernames } from '../../../../models';
|
2018-11-02 05:49:08 +02:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 04:20:58 +02:00
|
|
|
tags: ['users'],
|
|
|
|
|
2018-11-02 05:49:08 +02:00
|
|
|
requireCredential: false,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
username: {
|
2019-06-14 18:07:41 +03:00
|
|
|
validator: $.use(Users.validateLocalUsername)
|
2018-11-02 05:49:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-12-29 00:49:51 +02:00
|
|
|
|
2019-02-22 04:46:58 +02:00
|
|
|
export default define(meta, async (ps) => {
|
2016-12-29 00:49:51 +02:00
|
|
|
// Get exist
|
2019-04-07 15:50:36 +03:00
|
|
|
const exist = await Users.count({
|
2019-02-22 04:46:58 +02:00
|
|
|
host: null,
|
|
|
|
usernameLower: ps.username.toLowerCase()
|
|
|
|
});
|
2016-12-29 00:49:51 +02:00
|
|
|
|
2019-07-22 04:15:00 +03:00
|
|
|
const exist2 = await UsedUsernames.count({ username: ps.username.toLowerCase() });
|
|
|
|
|
2019-02-22 04:46:58 +02:00
|
|
|
return {
|
2019-07-22 04:15:00 +03:00
|
|
|
available: exist === 0 && exist2 === 0
|
2019-02-22 04:46:58 +02:00
|
|
|
};
|
|
|
|
});
|