41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
|
module.exports = function(Self) {
|
||
|
Self.remoteMethod('getByUser', {
|
||
|
description: 'returns the starred modules for the current user',
|
||
|
accessType: 'READ',
|
||
|
accepts: [{
|
||
|
arg: 'userId',
|
||
|
type: 'number',
|
||
|
description: 'The user id',
|
||
|
required: true,
|
||
|
http: {source: 'path'}
|
||
|
}],
|
||
|
returns: {
|
||
|
type: 'object',
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/:userId/get-by-user`,
|
||
|
verb: 'GET'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.getByUser = async userId => {
|
||
|
const models = Self.app.models;
|
||
|
const appNames = ['hedera'];
|
||
|
const filter = {
|
||
|
fields: ['appName', 'url'],
|
||
|
where: {
|
||
|
appName: {inq: appNames},
|
||
|
environment: process.env.NODE_ENV ?? 'development',
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const isWorker = await models.Account.findById(userId, {fields: ['id']});
|
||
|
if (!isWorker)
|
||
|
return models.Url.find(filter);
|
||
|
|
||
|
appNames.push('salix');
|
||
|
return models.Url.find(filter);
|
||
|
};
|
||
|
};
|