summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/app/show.ts
blob: 072fbaeb79760fdc4e6f76e06c0fca4efe482489 (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
import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
import App, { pack, IApp } from '../../../../models/app';
import { ILocalUser } from '../../../../models/user';

/**
 * Show an app
 */
export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
	const isSecure = user != null && app == null;

	// Get 'appId' parameter
	const [appId, appIdErr] = $.type(ID).get(params.appId);
	if (appIdErr) return rej('invalid appId param');

	// Lookup app
	const ap = await App.findOne({ _id: appId });

	if (ap === null) {
		return rej('app not found');
	}

	// Send response
	res(await pack(ap, user, {
		includeSecret: isSecure && ap.userId.equals(user._id)
	}));
});