From 4d0adb38ff7e2a74f53f4fd1cb30f1dd48256695 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 8 Nov 2018 15:55:48 +0100 Subject: [PATCH] Tarea #519 deprecar services/loopback/common/methods/client/activate.js --- .../common/methods/client/activate.js | 62 ------------------- services/loopback/common/models/client.js | 9 ++- 2 files changed, 4 insertions(+), 67 deletions(-) delete mode 100644 services/loopback/common/methods/client/activate.js diff --git a/services/loopback/common/methods/client/activate.js b/services/loopback/common/methods/client/activate.js deleted file mode 100644 index acc89d6d0..000000000 --- a/services/loopback/common/methods/client/activate.js +++ /dev/null @@ -1,62 +0,0 @@ -var request = require('request'); - -module.exports = function(Self) { - Self.remoteMethod('activate', { - description: 'Activate or deactive client', - accepts: [ - { - arg: 'id', - type: 'number', - required: true, - description: 'Model id', - http: {source: 'path'} - }, { - arg: 'context', - type: 'object', - http: function(ctx) { - return ctx; - } - } - ], - returns: { - arg: 'active', - type: 'boolean' - }, - http: { - verb: 'put', - path: '/:id/activate' - } - }); - - Self.activate = function(id, ctx, cb) { - Self.findById(id, function(err, client) { - if (err) return cb(err); - - Self.update({id: client.id}, {active: !client.active}); - - let filter = {where: {clientFk: client.id}, fields: ['started', 'ended']}; - - Self.app.models.CreditClassification.findOne(filter, function(error, data) { - if (error) return; - - let currentDate = new Date(); - - if (data && client.active && (data.ended >= currentDate || data.ended == null)) { - let referer = ctx.req.headers.referer; - var options = { - url: `${referer}/mailer/notification/client-deactivate/${client.id}`, - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Authorization: ctx.req.headers.authorization - }, - json: {} - }; - request(options); - } - }); - - cb(null, !client.active); - }); - }; -}; diff --git a/services/loopback/common/models/client.js b/services/loopback/common/models/client.js index f339b7393..fb5d6d956 100644 --- a/services/loopback/common/models/client.js +++ b/services/loopback/common/models/client.js @@ -1,10 +1,9 @@ -var UserError = require('../helpers').UserError; -var getFinalState = require('../helpers').getFinalState; -var isMultiple = require('../helpers').isMultiple; +let UserError = require('../helpers').UserError; +let getFinalState = require('../helpers').getFinalState; +let isMultiple = require('../helpers').isMultiple; module.exports = Self => { // Methods - require('../methods/client/activate')(Self); require('../methods/client/getCard')(Self); require('../methods/client/createWithUser')(Self); require('../methods/client/listWorkers')(Self); @@ -46,7 +45,7 @@ module.exports = Self => { Self.validateAsync('iban', ibanNeedsValidation, { message: 'The IBAN does not have the correct format' }); - var validateIban = require('../validations/validateIban'); + let validateIban = require('../validations/validateIban'); async function ibanNeedsValidation(err, done) { let filter = { fields: ['code'],