From a46c2ced7c3ddfc015719f3966849e7bc57274b2 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 19 Dec 2022 07:26:07 +0100 Subject: [PATCH] refs #4975: Added last mdbVersion/last method --- loopback/locale/es.json | 9 +++-- modules/mdb/back/methods/mdbVersion/last.js | 40 +++++++++++++++++++ modules/mdb/back/methods/mdbVersion/upload.js | 6 +-- modules/mdb/back/models/mdbVersion.js | 1 + 4 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 modules/mdb/back/methods/mdbVersion/last.js diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 932dfe98f..478b0da15 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -247,7 +247,8 @@ "Empty data source": "Origen de datos vacio", "Email verify": "Correo de verificación", "Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment", - "Receipt's bank was not found": "No se encontró el banco del recibo", - "This receipt was not compensated": "Este recibo no ha sido compensado", - "Client's email was not found": "No se encontró el email del cliente" -} + "Receipt's bank was not found": "No se encontró el banco del recibo", + "This receipt was not compensated": "Este recibo no ha sido compensado", + "Client's email was not found": "No se encontró el email del cliente", + "Not exist this app name": "No existe este nombre de aplicación" +} \ No newline at end of file diff --git a/modules/mdb/back/methods/mdbVersion/last.js b/modules/mdb/back/methods/mdbVersion/last.js new file mode 100644 index 000000000..91329be4e --- /dev/null +++ b/modules/mdb/back/methods/mdbVersion/last.js @@ -0,0 +1,40 @@ +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: { + type: ['object'], + root: true + }, + http: { + path: `/:appName/last`, + verb: 'GET' + } + }); + + Self.last = async(ctx, appName) => { + const models = Self.app.models; + const versions = await models.MdbVersion.find({ + where: {app: appName} + }); + + if (!versions.length) + throw new UserError('Not exist this app name'); + + let maxNumber = 0; + for (let mdb of versions) { + if (mdb.version > maxNumber) + maxNumber = mdb.version; + } + return maxNumber; + }; +}; diff --git a/modules/mdb/back/methods/mdbVersion/upload.js b/modules/mdb/back/methods/mdbVersion/upload.js index 57df35ce7..d165a7bb5 100644 --- a/modules/mdb/back/methods/mdbVersion/upload.js +++ b/modules/mdb/back/methods/mdbVersion/upload.js @@ -11,14 +11,12 @@ module.exports = Self => { type: 'string', required: true, description: 'The app name' - }, - { + }, { arg: 'newVersion', type: 'number', required: true, description: `The new version number` - }, - { + }, { arg: 'branch', type: 'string', required: true, diff --git a/modules/mdb/back/models/mdbVersion.js b/modules/mdb/back/models/mdbVersion.js index b36ee2a60..3a7a0c6f3 100644 --- a/modules/mdb/back/models/mdbVersion.js +++ b/modules/mdb/back/models/mdbVersion.js @@ -1,3 +1,4 @@ module.exports = Self => { require('../methods/mdbVersion/upload')(Self); + require('../methods/mdbVersion/last')(Self); };