blob: 58101a7e6a579ccfa99289f8276054257f006afc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/**
* Module dependencies
*/
import $ from 'cafy';
import App from '../../../../../models/app';
import { isValidNameId } from '../../../../../models/app';
/**
* @swagger
* /app/nameId/available:
* note:
* summary: Check available nameId on creation an application
* parameters:
* -
* name: nameId
* description: Application unique name
* in: formData
* required: true
* type: string
*
* responses:
* 200:
* description: Success
* schema:
* type: object
* properties:
* available:
* description: Whether nameId is available
* type: boolean
*
* default:
* description: Failed
* schema:
* $ref: "#/definitions/Error"
*/
/**
* Check available nameId of app
*
* @param {any} params
* @return {Promise<any>}
*/
module.exports = async (params: any) => new Promise(async (res, rej) => {
// Get 'nameId' parameter
const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId);
if (nameIdErr) return rej('invalid nameId param');
// Get exist
const exist = await App
.count({
nameIdLower: nameId.toLowerCase()
}, {
limit: 1
});
// Reply
res({
available: exist === 0
});
});
|