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

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-11-29 12:22:44 +00:00
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)
2024-01-30 15:07:33 +00:00
fields = fields.concat(['isVersionBetaCritical', 'versionBeta', 'urlBeta']);
2023-11-29 12:22:44 +00:00
else
2024-01-30 15:07:33 +00:00
fields = fields.concat(['isVersionCritical', 'version', 'urlProduction']);
2023-11-29 12:22:44 +00:00
const filter = {
where: {
appName: app
},
fields,
};
2024-01-30 15:07:33 +00:00
return Self.findOne(filter);
2023-11-29 12:22:44 +00:00
};
};