2016-12-28 22:49:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
|
|
|
import Appdata from '../../../models/appdata';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get app data
|
|
|
|
*
|
2017-03-01 08:37:01 +00:00
|
|
|
* @param {any} params
|
|
|
|
* @param {any} user
|
|
|
|
* @param {any} app
|
2016-12-28 22:49:51 +00:00
|
|
|
* @param {Boolean} isSecure
|
2017-03-01 08:37:01 +00:00
|
|
|
* @return {Promise<any>}
|
2016-12-28 22:49:51 +00:00
|
|
|
*/
|
|
|
|
module.exports = (params, user, app, isSecure) =>
|
|
|
|
new Promise(async (res, rej) =>
|
|
|
|
{
|
|
|
|
// Get 'key' parameter
|
|
|
|
let key = params.key;
|
|
|
|
if (key === undefined) {
|
|
|
|
key = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSecure) {
|
|
|
|
if (!user.data) {
|
|
|
|
return res();
|
|
|
|
}
|
|
|
|
if (key !== null) {
|
|
|
|
const data = {};
|
|
|
|
data[key] = user.data[key];
|
|
|
|
res(data);
|
|
|
|
} else {
|
|
|
|
res(user.data);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const select = {};
|
|
|
|
if (key !== null) {
|
|
|
|
select['data.' + key] = true;
|
|
|
|
}
|
|
|
|
const appdata = await Appdata.findOne({
|
|
|
|
app_id: app._id,
|
|
|
|
user_id: user._id
|
|
|
|
}, select);
|
|
|
|
|
|
|
|
if (appdata) {
|
|
|
|
res(appdata.data);
|
|
|
|
} else {
|
|
|
|
res();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|