2016-12-29 07:49:51 +09:00
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
2017-03-09 03:50:09 +09:00
|
|
|
import $ from 'cafy';
|
2018-03-29 20:32:18 +09:00
|
|
|
import App from '../../../../../models/app';
|
|
|
|
import { isValidNameId } from '../../../../../models/app';
|
2016-12-29 07:49:51 +09:00
|
|
|
|
|
|
|
/**
|
2018-03-29 14:48:47 +09:00
|
|
|
* Check available nameId of app
|
2016-12-29 07:49:51 +09:00
|
|
|
*
|
2017-03-01 17:37:01 +09:00
|
|
|
* @param {any} params
|
|
|
|
* @return {Promise<any>}
|
2016-12-29 07:49:51 +09:00
|
|
|
*/
|
2018-07-06 02:58:29 +09:00
|
|
|
export default async (params: any) => new Promise(async (res, rej) => {
|
2018-03-29 14:48:47 +09:00
|
|
|
// Get 'nameId' parameter
|
2018-05-02 18:06:16 +09:00
|
|
|
const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId);
|
2018-03-29 14:48:47 +09:00
|
|
|
if (nameIdErr) return rej('invalid nameId param');
|
2016-12-29 07:49:51 +09:00
|
|
|
|
|
|
|
// Get exist
|
|
|
|
const exist = await App
|
|
|
|
.count({
|
2018-03-29 14:48:47 +09:00
|
|
|
nameIdLower: nameId.toLowerCase()
|
2016-12-29 07:49:51 +09:00
|
|
|
}, {
|
|
|
|
limit: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
// Reply
|
|
|
|
res({
|
|
|
|
available: exist === 0
|
|
|
|
});
|
|
|
|
});
|