Tarea #519 deprecar services/loopback/common/methods/client/activate.js
This commit is contained in:
parent
b72cdde12f
commit
4d0adb38ff
|
@ -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);
|
||||
});
|
||||
};
|
||||
};
|
|
@ -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'],
|
||||
|
|
Loading…
Reference in New Issue