salix/back/methods/mobile-app-version-control/getVersion.js

46 lines
1.1 KiB
JavaScript

module.exports = Self => {
Self.remoteMethodCtx('getVersion', {
description: 'gets app version data',
accessType: 'READ',
accepts: [{
arg: 'app',
type: 'string',
required: true
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/getVersion`,
verb: 'GET'
}
});
Self.getVersion = async(ctx, app) => {
const {models} = Self.app;
const userId = ctx.req.accessToken.userId;
const workerFk = await models.WorkerAppTester.findOne({
where: {
workerFk: userId
}
});
let fields = ['id', 'appName'];
if (workerFk)
fields = [...fields, ...['isVersionBetaCritical', 'versionBeta', 'urlBeta']];
else
fields = [...fields, ...['isVersionCritical', 'version', 'urlProduction']];
const filter = {
where: {
appName: app
},
fields,
};
return await Self.findOne(filter);
};
};