salix/modules/mdb/back/methods/mdbVersion/last.js

47 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('last', {
description: 'Gets the latest version of a access file',
accepts: [
{
arg: 'appName',
type: 'string',
required: true,
description: 'The app name'
}
],
returns: {
2022-12-19 10:24:18 +00:00
type: 'number',
root: true
},
http: {
path: `/:appName/last`,
verb: 'GET'
}
});
Self.last = async(ctx, appName) => {
const models = Self.app.models;
const versions = await models.MdbVersion.find({
2022-12-19 10:24:18 +00:00
where: {app: appName},
fields: ['version']
});
if (!versions.length)
2022-12-19 10:24:18 +00:00
throw new UserError('App name does not exist');
let maxNumber = 0;
for (let mdb of versions) {
if (mdb.version > maxNumber)
maxNumber = mdb.version;
}
2023-01-05 13:20:47 +00:00
let response = {
version: maxNumber
};
return response;
};
};