From 931bdc6aace5e7aa71ffdfb470e208ead78a2a53 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 2 Nov 2018 03:32:24 +0900 Subject: Refactoring, Clean up and bug fixes --- src/server/api/endpoints/app/show.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/server/api/endpoints/app/show.ts') diff --git a/src/server/api/endpoints/app/show.ts b/src/server/api/endpoints/app/show.ts index 8cc2abdc28..0d73985b48 100644 --- a/src/server/api/endpoints/app/show.ts +++ b/src/server/api/endpoints/app/show.ts @@ -1,19 +1,25 @@ -import $ from 'cafy'; import ID from '../../../../misc/cafy-id'; +import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import App, { pack, IApp } from '../../../../models/app'; import { ILocalUser } from '../../../../models/user'; +import getParams from '../../get-params'; + +export const meta = { + params: { + appId: { + validator: $.type(ID), + transform: transform + }, + } +}; -/** - * Show an app - */ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { - const isSecure = user != null && app == null; + const [ps, psErr] = getParams(meta, params); + if (psErr) return rej(psErr); - // Get 'appId' parameter - const [appId, appIdErr] = $.type(ID).get(params.appId); - if (appIdErr) return rej('invalid appId param'); + const isSecure = user != null && app == null; // Lookup app - const ap = await App.findOne({ _id: appId }); + const ap = await App.findOne({ _id: ps.appId }); if (ap === null) { return rej('app not found'); -- cgit v1.2.3-freya