Resolve conflicts
This commit is contained in:
@ -13,7 +13,7 @@ import App, { isValidNameId, pack } from '../../models/app';
|
||||
* parameters:
|
||||
* - $ref: "#/parameters/AccessToken"
|
||||
* -
|
||||
* name: name_id
|
||||
* name: nameId
|
||||
* description: Application unique name
|
||||
* in: formData
|
||||
* required: true
|
||||
@ -40,7 +40,7 @@ import App, { isValidNameId, pack } from '../../models/app';
|
||||
* type: string
|
||||
* collectionFormat: csv
|
||||
* -
|
||||
* name: callback_url
|
||||
* name: callbackUrl
|
||||
* description: URL called back after authentication
|
||||
* in: formData
|
||||
* required: false
|
||||
@ -66,9 +66,9 @@ import App, { isValidNameId, pack } from '../../models/app';
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name_id' parameter
|
||||
const [nameId, nameIdErr] = $(params.name_id).string().pipe(isValidNameId).$;
|
||||
if (nameIdErr) return rej('invalid name_id param');
|
||||
// Get 'nameId' parameter
|
||||
const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).$;
|
||||
if (nameIdErr) return rej('invalid nameId param');
|
||||
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = $(params.name).string().$;
|
||||
@ -82,24 +82,24 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
const [permission, permissionErr] = $(params.permission).array('string').unique().$;
|
||||
if (permissionErr) return rej('invalid permission param');
|
||||
|
||||
// Get 'callback_url' parameter
|
||||
// Get 'callbackUrl' parameter
|
||||
// TODO: Check it is valid url
|
||||
const [callbackUrl = null, callbackUrlErr] = $(params.callback_url).optional.nullable.string().$;
|
||||
if (callbackUrlErr) return rej('invalid callback_url param');
|
||||
const [callbackUrl = null, callbackUrlErr] = $(params.callbackUrl).optional.nullable.string().$;
|
||||
if (callbackUrlErr) return rej('invalid callbackUrl param');
|
||||
|
||||
// Generate secret
|
||||
const secret = rndstr('a-zA-Z0-9', 32);
|
||||
|
||||
// Create account
|
||||
const app = await App.insert({
|
||||
created_at: new Date(),
|
||||
user_id: user._id,
|
||||
createdAt: new Date(),
|
||||
userId: user._id,
|
||||
name: name,
|
||||
name_id: nameId,
|
||||
name_id_lower: nameId.toLowerCase(),
|
||||
nameId: nameId,
|
||||
nameIdLower: nameId.toLowerCase(),
|
||||
description: description,
|
||||
permission: permission,
|
||||
callback_url: callbackUrl,
|
||||
callbackUrl: callbackUrl,
|
||||
secret: secret
|
||||
});
|
||||
|
||||
|
@ -7,12 +7,12 @@ import { isValidNameId } from '../../../models/app';
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /app/name_id/available:
|
||||
* /app/nameId/available:
|
||||
* post:
|
||||
* summary: Check available name_id on creation an application
|
||||
* summary: Check available nameId on creation an application
|
||||
* parameters:
|
||||
* -
|
||||
* name: name_id
|
||||
* name: nameId
|
||||
* description: Application unique name
|
||||
* in: formData
|
||||
* required: true
|
||||
@ -25,7 +25,7 @@ import { isValidNameId } from '../../../models/app';
|
||||
* type: object
|
||||
* properties:
|
||||
* available:
|
||||
* description: Whether name_id is available
|
||||
* description: Whether nameId is available
|
||||
* type: boolean
|
||||
*
|
||||
* default:
|
||||
@ -35,20 +35,20 @@ import { isValidNameId } from '../../../models/app';
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check available name_id of app
|
||||
* Check available nameId of app
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params) => new Promise(async (res, rej) => {
|
||||
// Get 'name_id' parameter
|
||||
const [nameId, nameIdErr] = $(params.name_id).string().pipe(isValidNameId).$;
|
||||
if (nameIdErr) return rej('invalid name_id param');
|
||||
// Get 'nameId' parameter
|
||||
const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).$;
|
||||
if (nameIdErr) return rej('invalid nameId param');
|
||||
|
||||
// Get exist
|
||||
const exist = await App
|
||||
.count({
|
||||
name_id_lower: nameId.toLowerCase()
|
||||
nameIdLower: nameId.toLowerCase()
|
||||
}, {
|
||||
limit: 1
|
||||
});
|
||||
|
@ -9,15 +9,15 @@ import App, { pack } from '../../models/app';
|
||||
* /app/show:
|
||||
* post:
|
||||
* summary: Show an application's information
|
||||
* description: Require app_id or name_id
|
||||
* description: Require appId or nameId
|
||||
* parameters:
|
||||
* -
|
||||
* name: app_id
|
||||
* name: appId
|
||||
* description: Application ID
|
||||
* in: formData
|
||||
* type: string
|
||||
* -
|
||||
* name: name_id
|
||||
* name: nameId
|
||||
* description: Application unique name
|
||||
* in: formData
|
||||
* type: string
|
||||
@ -44,22 +44,22 @@ import App, { pack } from '../../models/app';
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => {
|
||||
// Get 'app_id' parameter
|
||||
const [appId, appIdErr] = $(params.app_id).optional.id().$;
|
||||
if (appIdErr) return rej('invalid app_id param');
|
||||
// Get 'appId' parameter
|
||||
const [appId, appIdErr] = $(params.appId).optional.id().$;
|
||||
if (appIdErr) return rej('invalid appId param');
|
||||
|
||||
// Get 'name_id' parameter
|
||||
const [nameId, nameIdErr] = $(params.name_id).optional.string().$;
|
||||
if (nameIdErr) return rej('invalid name_id param');
|
||||
// Get 'nameId' parameter
|
||||
const [nameId, nameIdErr] = $(params.nameId).optional.string().$;
|
||||
if (nameIdErr) return rej('invalid nameId param');
|
||||
|
||||
if (appId === undefined && nameId === undefined) {
|
||||
return rej('app_id or name_id is required');
|
||||
return rej('appId or nameId is required');
|
||||
}
|
||||
|
||||
// Lookup app
|
||||
const app = appId !== undefined
|
||||
? await App.findOne({ _id: appId })
|
||||
: await App.findOne({ name_id_lower: nameId.toLowerCase() });
|
||||
: await App.findOne({ nameIdLower: nameId.toLowerCase() });
|
||||
|
||||
if (app === null) {
|
||||
return rej('app not found');
|
||||
@ -67,6 +67,6 @@ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) =>
|
||||
|
||||
// Send response
|
||||
res(await pack(app, user, {
|
||||
includeSecret: isSecure && app.user_id.equals(user._id)
|
||||
includeSecret: isSecure && app.userId.equals(user._id)
|
||||
}));
|
||||
});
|
||||
|
Reference in New Issue
Block a user