Tarea #519 deprecar services/loopback/common/methods/client/activate.js

This commit is contained in:
Javi Gallego 2018-11-08 15:55:48 +01:00
parent b72cdde12f
commit 4d0adb38ff
2 changed files with 4 additions and 67 deletions

View File

@ -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);
});
};
};

View File

@ -1,10 +1,9 @@
var UserError = require('../helpers').UserError; let UserError = require('../helpers').UserError;
var getFinalState = require('../helpers').getFinalState; let getFinalState = require('../helpers').getFinalState;
var isMultiple = require('../helpers').isMultiple; let isMultiple = require('../helpers').isMultiple;
module.exports = Self => { module.exports = Self => {
// Methods // Methods
require('../methods/client/activate')(Self);
require('../methods/client/getCard')(Self); require('../methods/client/getCard')(Self);
require('../methods/client/createWithUser')(Self); require('../methods/client/createWithUser')(Self);
require('../methods/client/listWorkers')(Self); require('../methods/client/listWorkers')(Self);
@ -46,7 +45,7 @@ module.exports = Self => {
Self.validateAsync('iban', ibanNeedsValidation, { Self.validateAsync('iban', ibanNeedsValidation, {
message: 'The IBAN does not have the correct format' message: 'The IBAN does not have the correct format'
}); });
var validateIban = require('../validations/validateIban'); let validateIban = require('../validations/validateIban');
async function ibanNeedsValidation(err, done) { async function ibanNeedsValidation(err, done) {
let filter = { let filter = {
fields: ['code'], fields: ['code'],