nameId廃止 & アプリ作成時にシークレットを返すように

This commit is contained in:
syuilo
2018-08-19 18:38:02 +09:00
parent d60c3c4ee3
commit bb7b335491
6 changed files with 7 additions and 103 deletions

View File

@ -1,6 +1,6 @@
import rndstr from 'rndstr';
import $ from 'cafy';
import App, { isValidNameId, pack } from '../../../../models/app';
import App, { pack } from '../../../../models/app';
import { ILocalUser } from '../../../../models/user';
export const meta = {
@ -11,10 +11,6 @@ export const meta = {
* Create an app
*/
export default async (params: any, user: ILocalUser) => 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 'name' parameter
const [name, nameErr] = $.str.get(params.name);
if (nameErr) return rej('invalid name param');
@ -40,8 +36,6 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
createdAt: new Date(),
userId: user && user._id,
name: name,
nameId: nameId,
nameIdLower: nameId.toLowerCase(),
description: description,
permission: permission,
callbackUrl: callbackUrl,
@ -49,5 +43,7 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
});
// Response
res(await pack(app));
res(await pack(app, null, {
includeSecret: true
}));
});

View File

@ -1,31 +0,0 @@
/**
* Module dependencies
*/
import $ from 'cafy';
import App from '../../../../../models/app';
import { isValidNameId } from '../../../../../models/app';
/**
* Check available nameId of app
*
* @param {any} params
* @return {Promise<any>}
*/
export default 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
});
});

View File

@ -9,21 +9,11 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (
const isSecure = user != null && app == null;
// Get 'appId' parameter
const [appId, appIdErr] = $.type(ID).optional.get(params.appId);
const [appId, appIdErr] = $.type(ID).get(params.appId);
if (appIdErr) return rej('invalid appId param');
// Get 'nameId' parameter
const [nameId, nameIdErr] = $.str.optional.get(params.nameId);
if (nameIdErr) return rej('invalid nameId param');
if (appId === undefined && nameId === undefined) {
return rej('appId or nameId is required');
}
// Lookup app
const ap = appId !== undefined
? await App.findOne({ _id: appId })
: await App.findOne({ nameIdLower: nameId.toLowerCase() });
const ap = await App.findOne({ _id: appId });
if (ap === null) {
return rej('app not found');