#199 - Bug solved: Client service crash when calling Client.card() method with invalid id
This commit is contained in:
parent
fd324df1c9
commit
c8aa7dc43c
|
@ -26,7 +26,7 @@
|
|||
initial-data="$ctrl.client.salesPerson"
|
||||
field="$ctrl.client.salesPersonFk"
|
||||
url="/client/api/Clients/activeSalesPerson"
|
||||
show-field="name"
|
||||
show-field="firstName"
|
||||
value-field="id"
|
||||
select-fields="name"
|
||||
label="Salesperson"
|
||||
|
|
|
@ -9,7 +9,6 @@ module.exports = function(Self) {
|
|||
http: {source: 'path'}
|
||||
},
|
||||
returns: {
|
||||
arg: 'data',
|
||||
type: 'Object',
|
||||
root: true
|
||||
},
|
||||
|
@ -19,8 +18,8 @@ module.exports = function(Self) {
|
|||
}
|
||||
});
|
||||
|
||||
Self.card = function(id, cb) {
|
||||
let filter = {
|
||||
Self.card = async function(id) {
|
||||
return await Self.findOne({
|
||||
where: {
|
||||
id: id
|
||||
},
|
||||
|
@ -57,20 +56,6 @@ module.exports = function(Self) {
|
|||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
Self.findOne(filter, function(err, card) {
|
||||
if (err) return cb(err);
|
||||
|
||||
let formatedCard = JSON.parse(JSON.stringify(card));
|
||||
|
||||
if (formatedCard.salesPersonFk)
|
||||
formatedCard.salesPerson = {
|
||||
id: card.salesPerson().id,
|
||||
name: `${card.salesPerson().firstName} ${card.salesPerson().name}`
|
||||
};
|
||||
|
||||
cb(null, formatedCard);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,20 +1,13 @@
|
|||
const app = require('../../../../../client/server/server');
|
||||
const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors;
|
||||
|
||||
describe('Client card', () => {
|
||||
it('should call the card() method to receive a formated card of Bruce Wayne', done => {
|
||||
it('should call the card() method to receive a formated card of Bruce Wayne', async() => {
|
||||
let id = 101;
|
||||
let result = await app.models.Client.card(id, callback);
|
||||
|
||||
let callback = (error, result) => {
|
||||
if (error) return catchErrors(done)(error);
|
||||
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
id: 101,
|
||||
name: 'Bruce Wayne'
|
||||
}));
|
||||
done();
|
||||
};
|
||||
|
||||
app.models.Client.card(id, callback);
|
||||
expect(result).toEqual(jasmine.objectContaining({
|
||||
id: 101,
|
||||
name: 'Bruce Wayne'
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue