address observations crud created
This commit is contained in:
parent
fd4b427518
commit
7eee1cad50
|
@ -41,7 +41,7 @@ export default class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
addObservation() {
|
addObservation() {
|
||||||
this.observations.push({observationTypeFk: null, description: null, showAddIcon: true});
|
this.observations.push({observationTypeFk: null, addressFk: this.address.id, description: null, showAddIcon: true});
|
||||||
this._setIconAdd();
|
this._setIconAdd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ export default class Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_submitObservations(objectObservations) {
|
_submitObservations(objectObservations) {
|
||||||
return this.$http.post('/client/api/crudAddressObservations', objectObservations);
|
return this.$http.post(`/client/api/AddressObservations/crudAddressObservations`, objectObservations);
|
||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
|
@ -66,9 +66,9 @@ export default class Controller {
|
||||||
let submitObservations;
|
let submitObservations;
|
||||||
let repeatedTypes = false;
|
let repeatedTypes = false;
|
||||||
let observationsObj = {
|
let observationsObj = {
|
||||||
remove: this.observationsRemoved,
|
delete: this.observationsRemoved,
|
||||||
news: [],
|
create: [],
|
||||||
modified: []
|
update: []
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let i = 0; i < this.observations.length; i++) {
|
for (let i = 0; i < this.observations.length; i++) {
|
||||||
|
@ -84,16 +84,16 @@ export default class Controller {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.observationsDictionary[observation.observationTypeFk] = observation;
|
|
||||||
|
|
||||||
if (!observation.id && observation.observationTypeFk && observation.description) {
|
if (!observation.id && observation.observationTypeFk && observation.description) {
|
||||||
observationsObj.news.push(observation);
|
observationsObj.create.push(observation);
|
||||||
} else if (observation.id && this.observationsDictionary[observation.observationTypeFk].description !== observation.description) {
|
} else if (observation.id && this.observationsDictionary[observation.observationTypeFk].description !== observation.description) {
|
||||||
observationsObj.modified.push(observation);
|
observationsObj.update.push(observation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.observationsDictionary[observation.observationTypeFk] = observation;
|
||||||
}
|
}
|
||||||
|
|
||||||
submitObservations = observationsObj.modified.length > 0 || observationsObj.news.length > 0 || observationsObj.remove.length > 0;
|
submitObservations = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
|
||||||
|
|
||||||
if (repeatedTypes) {
|
if (repeatedTypes) {
|
||||||
this.vnApp.showMessage(
|
this.vnApp.showMessage(
|
||||||
|
@ -125,8 +125,8 @@ export default class Controller {
|
||||||
};
|
};
|
||||||
this.$http.get(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).then(res => {
|
this.$http.get(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).then(res => {
|
||||||
this.observations = res.data;
|
this.observations = res.data;
|
||||||
this.observations.forEach(item => {
|
res.data.forEach(item => {
|
||||||
this.observationsDictionary[item.observationTypeFk] = {id: item.id, description: item.description};
|
this.observationsDictionary[item.observationTypeFk] = Object.assign({}, item);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,19 +15,19 @@ describe('Client', () => {
|
||||||
$componentController = _$componentController_;
|
$componentController = _$componentController_;
|
||||||
$state = _$state_;
|
$state = _$state_;
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
$state.params.addressId = '1234';
|
$state.params.addressId = '1';
|
||||||
controller = $componentController('vnAddressEdit', {$state: $state});
|
controller = $componentController('vnAddressEdit', {$state: $state});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should define and set address property', () => {
|
it('should define and set address property', () => {
|
||||||
expect(controller.address.id).toBe(1234);
|
expect(controller.address.id).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('$onInit()', () => {
|
describe('$onInit()', () => {
|
||||||
it('should perform a GET query to receive the address observations', () => {
|
it('should perform a GET query to receive the address observations', () => {
|
||||||
let filter = {where: {addressFk: 1234}, include: [{relation: 'observationType'}]};
|
let filter = {where: {addressFk: 1}, include: {relation: 'observationType'}};
|
||||||
let json = {data: 'some notes'};
|
let res = ['some notes'];
|
||||||
$httpBackend.when('GET', `/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).respond(json);
|
$httpBackend.when('GET', `/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).respond(res);
|
||||||
$httpBackend.expectGET(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`);
|
$httpBackend.expectGET(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`);
|
||||||
controller.$onInit();
|
controller.$onInit();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('crudAddressObservations', {
|
||||||
|
description: 'create, delete or update address observations',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'observations',
|
||||||
|
type: 'Object',
|
||||||
|
require: true,
|
||||||
|
description: 'object with observations to create, delete or update, Example: {delete: [], create: [], update: []}',
|
||||||
|
http: {source: 'body'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
arg: 'sumAmount'
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/crudAddressObservations`,
|
||||||
|
verb: 'post'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.crudAddressObservations = observations => {
|
||||||
|
let promises = [];
|
||||||
|
|
||||||
|
if (observations.delete.length) {
|
||||||
|
promises.push(Self.destroyAll({id: {inq: observations.delete}}));
|
||||||
|
}
|
||||||
|
if (observations.create.length) {
|
||||||
|
promises.push(Self.create(observations.create));
|
||||||
|
}
|
||||||
|
if (observations.update.length) {
|
||||||
|
observations.update.forEach(observation => {
|
||||||
|
promises.push(Self.upsert(observation));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.all(promises);
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = function(Self) {
|
||||||
|
require('../methods/address/crudAddressObservations.js')(Self);
|
||||||
|
};
|
Loading…
Reference in New Issue