rudeshark.net/src/server/api/endpoints/username/available.ts

31 lines
525 B
TypeScript
Raw Normal View History

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