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

42 lines
1.0 KiB
JavaScript
Raw Normal View History

const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('last', {
description: 'Upload and attach 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;
}
return maxNumber;
};
};