WIP: a falta de e2e
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
c14e13a2e6
commit
4aea284703
|
@ -0,0 +1,9 @@
|
||||||
|
ALTER TABLE `vn`.`observationType`
|
||||||
|
ADD COLUMN `code` VARCHAR(45) NOT NULL AFTER `description`;
|
||||||
|
|
||||||
|
UPDATE `vn`.`observationType` SET `code` = 'itemPicker' WHERE (`id` = '1');
|
||||||
|
UPDATE `vn`.`observationType` SET `code` = 'packager' WHERE (`id` = '2');
|
||||||
|
UPDATE `vn`.`observationType` SET `code` = 'salesPerson' WHERE (`id` = '4');
|
||||||
|
UPDATE `vn`.`observationType` SET `code` = 'administrative' WHERE (`id` = '5');
|
||||||
|
UPDATE `vn`.`observationType` SET `code` = 'weight' WHERE (`id` = '6');
|
||||||
|
UPDATE `vn`.`observationType` SET `code` = 'delivery' WHERE (`id` = '3');
|
|
@ -154,7 +154,8 @@ module.exports = function(Self) {
|
||||||
const showFieldNames = [
|
const showFieldNames = [
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'code'
|
'code',
|
||||||
|
'nickname'
|
||||||
];
|
];
|
||||||
for (field of showFieldNames) {
|
for (field of showFieldNames) {
|
||||||
const propField = properties && properties[field];
|
const propField = properties && properties[field];
|
||||||
|
|
|
@ -4,7 +4,7 @@ module.exports = function(Self) {
|
||||||
Self.remoteMethodCtx('createAddress', {
|
Self.remoteMethodCtx('createAddress', {
|
||||||
description: 'Creates client address updating default address',
|
description: 'Creates client address updating default address',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'id',
|
arg: 'clientFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: 'The client id',
|
description: 'The client id',
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
|
@ -37,19 +37,19 @@ module.exports = function(Self) {
|
||||||
type: 'string'
|
type: 'string'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'provinceId',
|
arg: 'provinceFk',
|
||||||
type: 'number'
|
type: 'number'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'agencyModeId',
|
arg: 'agencyModeFk',
|
||||||
type: 'number'
|
type: 'number'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'incotermsId',
|
arg: 'incotermsFk',
|
||||||
type: 'string'
|
type: 'string'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'customsAgentId',
|
arg: 'customsAgentFk',
|
||||||
type: 'number'
|
type: 'number'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -66,44 +66,33 @@ module.exports = function(Self) {
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
verb: 'post',
|
verb: 'post',
|
||||||
path: '/:id/createAddress'
|
path: '/:clientFk/createAddress'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.createAddress = async(ctx, clientId) => {
|
Self.createAddress = async(ctx, clientFk) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
const tx = await models.Address.beginTransaction({});
|
const tx = await models.Address.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const province = await models.Province.findById(args.provinceId, {
|
const province = await models.Province.findById(args.provinceFk, {
|
||||||
include: {
|
include: {
|
||||||
relation: 'country'
|
relation: 'country'
|
||||||
}
|
}
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
const isUeeMember = province.country().isUeeMember;
|
const isUeeMember = province.country().isUeeMember;
|
||||||
if (!isUeeMember && !args.incotermsId)
|
if (!isUeeMember && !args.incotermsFk)
|
||||||
throw new UserError(`Incoterms is required for a non UEE member`);
|
throw new UserError(`Incoterms is required for a non UEE member`);
|
||||||
|
|
||||||
if (!isUeeMember && !args.customsAgentId)
|
if (!isUeeMember && !args.customsAgentFk)
|
||||||
throw new UserError(`Customs agent is required for a non UEE member`);
|
throw new UserError(`Customs agent is required for a non UEE member`);
|
||||||
|
|
||||||
const newAddress = await models.Address.create({
|
delete args.ctx; // Remove unwanted properties
|
||||||
clientFk: clientId,
|
const newAddress = await models.Address.create(args, options);
|
||||||
nickname: args.nickname,
|
const client = await Self.findById(clientFk, null, options);
|
||||||
incotermsFk: args.incotermsId,
|
|
||||||
customsAgentFk: args.customsAgentId,
|
|
||||||
city: args.city,
|
|
||||||
street: args.street,
|
|
||||||
phone: args.phone,
|
|
||||||
postalCode: args.postalCode,
|
|
||||||
provinceFk: args.provinceId,
|
|
||||||
agencyModeFk: args.agencyModeId,
|
|
||||||
isActive: args.isActive
|
|
||||||
}, options);
|
|
||||||
const client = await Self.findById(clientId, null, options);
|
|
||||||
|
|
||||||
if (args.isDefaultAddress) {
|
if (args.isDefaultAddress) {
|
||||||
await client.updateAttributes({
|
await client.updateAttributes({
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('Address createAddress', () => {
|
describe('Address createAddress', () => {
|
||||||
const clientId = 101;
|
const clientFk = 101;
|
||||||
const provinceId = 5;
|
const provinceFk = 5;
|
||||||
const incotermsId = 'FAS';
|
const incotermsFk = 'FAS';
|
||||||
const customAgentOneId = 1;
|
const customAgentOneId = 1;
|
||||||
|
|
||||||
it('should throw a non uee member error if no incoterms is defined', async() => {
|
it('should throw a non uee member error if no incoterms is defined', async() => {
|
||||||
const expectedResult = 'My edited address';
|
const expectedResult = 'My edited address';
|
||||||
const ctx = {
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
provinceId: provinceId,
|
provinceFk: provinceFk,
|
||||||
nickname: expectedResult,
|
nickname: expectedResult,
|
||||||
street: 'Wall Street',
|
street: 'Wall Street',
|
||||||
city: 'New York',
|
city: 'New York',
|
||||||
customsAgentId: customAgentOneId
|
customsAgentFk: customAgentOneId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await app.models.Client.createAddress(ctx, clientId);
|
await app.models.Client.createAddress(ctx, clientFk);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
|
@ -32,16 +32,16 @@ describe('Address createAddress', () => {
|
||||||
const expectedResult = 'My edited address';
|
const expectedResult = 'My edited address';
|
||||||
const ctx = {
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
provinceId: provinceId,
|
provinceFk: provinceFk,
|
||||||
nickname: expectedResult,
|
nickname: expectedResult,
|
||||||
street: 'Wall Street',
|
street: 'Wall Street',
|
||||||
city: 'New York',
|
city: 'New York',
|
||||||
incotermsId: incotermsId
|
incotermsFk: incotermsFk
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await app.models.Client.createAddress(ctx, clientId);
|
await app.models.Client.createAddress(ctx, clientFk);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ describe('Address createAddress', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should verify that client defaultAddressFk is untainted', async() => {
|
it('should verify that client defaultAddressFk is untainted', async() => {
|
||||||
const client = await app.models.Client.findById(clientId);
|
const client = await app.models.Client.findById(clientFk);
|
||||||
|
|
||||||
expect(client.defaultAddressFk).toEqual(1);
|
expect(client.defaultAddressFk).toEqual(1);
|
||||||
});
|
});
|
||||||
|
@ -59,18 +59,23 @@ describe('Address createAddress', () => {
|
||||||
it('should create a new address and set as a client default address', async() => {
|
it('should create a new address and set as a client default address', async() => {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
provinceId: 1,
|
clientFk: 101,
|
||||||
|
provinceFk: 1,
|
||||||
nickname: 'My address',
|
nickname: 'My address',
|
||||||
street: 'Wall Street',
|
street: 'Wall Street',
|
||||||
city: 'New York',
|
city: 'New York',
|
||||||
incotermsId: incotermsId,
|
phone: 678678678,
|
||||||
customsAgentId: customAgentOneId,
|
mobile: 678678678,
|
||||||
|
postalCode: 46680,
|
||||||
|
agencyModeFk: 1,
|
||||||
|
incotermsFk: incotermsFk,
|
||||||
|
customsAgentFk: customAgentOneId,
|
||||||
isDefaultAddress: true
|
isDefaultAddress: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const address = await app.models.Client.createAddress(ctx, clientId);
|
const address = await app.models.Client.createAddress(ctx, clientFk);
|
||||||
const client = await app.models.Client.findById(clientId);
|
const client = await app.models.Client.findById(clientFk);
|
||||||
|
|
||||||
expect(client.defaultAddressFk).toEqual(address.id);
|
expect(client.defaultAddressFk).toEqual(address.id);
|
||||||
|
|
||||||
|
@ -78,4 +83,31 @@ describe('Address createAddress', () => {
|
||||||
await client.updateAttributes({defaultAddressFk: 1});
|
await client.updateAttributes({defaultAddressFk: 1});
|
||||||
await address.destroy();
|
await address.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should create a new address and set all properties', async() => {
|
||||||
|
const ctx = {
|
||||||
|
args: {
|
||||||
|
clientFk: 101,
|
||||||
|
provinceFk: 1,
|
||||||
|
nickname: 'My address',
|
||||||
|
street: 'Wall Street',
|
||||||
|
city: 'New York',
|
||||||
|
phone: '678678678',
|
||||||
|
mobile: '678678678',
|
||||||
|
postalCode: '46680',
|
||||||
|
agencyModeFk: 1,
|
||||||
|
incotermsFk: incotermsFk,
|
||||||
|
customsAgentFk: customAgentOneId,
|
||||||
|
isDefaultAddress: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
address = await app.models.Client.createAddress(ctx, clientFk);
|
||||||
|
|
||||||
|
expect(address.__data).toEqual(jasmine.objectContaining(ctx.args));
|
||||||
|
// restores
|
||||||
|
const client = await app.models.Client.findById(clientFk);
|
||||||
|
await client.updateAttributes({defaultAddressFk: 1});
|
||||||
|
await address.destroy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -88,7 +88,7 @@
|
||||||
</vn-datalist>
|
</vn-datalist>
|
||||||
<vn-autocomplete vn-id="province" vn-one
|
<vn-autocomplete vn-id="province" vn-one
|
||||||
label="Province"
|
label="Province"
|
||||||
ng-model="$ctrl.address.provinceId"
|
ng-model="$ctrl.address.provinceFk"
|
||||||
data="provincesLocation"
|
data="provincesLocation"
|
||||||
fields="['id', 'name', 'countryFk']"
|
fields="['id', 'name', 'countryFk']"
|
||||||
show-field="name"
|
show-field="name"
|
||||||
|
@ -100,7 +100,7 @@
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
vn-one
|
vn-one
|
||||||
ng-model="$ctrl.address.agencyModeId"
|
ng-model="$ctrl.address.agencyModeFk"
|
||||||
url="AgencyModes/isActive"
|
url="AgencyModes/isActive"
|
||||||
show-field="name"
|
show-field="name"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
|
@ -121,14 +121,14 @@
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-autocomplete vn-one
|
<vn-autocomplete vn-one
|
||||||
ng-model="$ctrl.address.incotermsId"
|
ng-model="$ctrl.address.incotermsFk"
|
||||||
data="incoterms"
|
data="incoterms"
|
||||||
show-field="name"
|
show-field="name"
|
||||||
value-field="code"
|
value-field="code"
|
||||||
label="Incoterms">
|
label="Incoterms">
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
<vn-autocomplete vn-one
|
<vn-autocomplete vn-one
|
||||||
ng-model="$ctrl.address.customsAgentId"
|
ng-model="$ctrl.address.customsAgentFk"
|
||||||
data="customsAgents"
|
data="customsAgents"
|
||||||
show-field="fiscalName"
|
show-field="fiscalName"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
|
|
|
@ -29,7 +29,7 @@ export default class Controller extends Section {
|
||||||
|
|
||||||
onCustomAgentAccept() {
|
onCustomAgentAccept() {
|
||||||
return this.$http.post(`CustomsAgents`, this.newCustomsAgent)
|
return this.$http.post(`CustomsAgents`, this.newCustomsAgent)
|
||||||
.then(res => this.address.customsAgentId = res.data.id);
|
.then(res => this.address.customsAgentFk = res.data.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
get town() {
|
get town() {
|
||||||
|
@ -45,8 +45,8 @@ export default class Controller extends Section {
|
||||||
const province = selection.province;
|
const province = selection.province;
|
||||||
const postcodes = selection.postcodes;
|
const postcodes = selection.postcodes;
|
||||||
|
|
||||||
if (!this.address.provinceI)
|
if (!this.address.provinceFk)
|
||||||
this.address.provinceId = province.id;
|
this.address.provinceFk = province.id;
|
||||||
|
|
||||||
if (postcodes.length === 1)
|
if (postcodes.length === 1)
|
||||||
this.address.postalCode = postcodes[0].code;
|
this.address.postalCode = postcodes[0].code;
|
||||||
|
@ -68,8 +68,8 @@ export default class Controller extends Section {
|
||||||
if (!this.address.city)
|
if (!this.address.city)
|
||||||
this.address.city = town.name;
|
this.address.city = town.name;
|
||||||
|
|
||||||
if (!this.address.provinceId)
|
if (!this.address.provinceFk)
|
||||||
this.address.provinceId = province.id;
|
this.address.provinceFk = province.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
onResponse(response) {
|
onResponse(response) {
|
||||||
|
|
|
@ -54,7 +54,7 @@ describe('Client', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('town() setter', () => {
|
describe('town() setter', () => {
|
||||||
it(`should set provinceId property`, () => {
|
it(`should set provinceFk property`, () => {
|
||||||
controller.town = {
|
controller.town = {
|
||||||
provinceFk: 1,
|
provinceFk: 1,
|
||||||
code: 46001,
|
code: 46001,
|
||||||
|
@ -69,10 +69,10 @@ describe('Client', () => {
|
||||||
postcodes: []
|
postcodes: []
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(controller.address.provinceId).toEqual(1);
|
expect(controller.address.provinceFk).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should set provinceId property and fill the postalCode if there's just one`, () => {
|
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
|
||||||
controller.town = {
|
controller.town = {
|
||||||
provinceFk: 1,
|
provinceFk: 1,
|
||||||
code: 46001,
|
code: 46001,
|
||||||
|
@ -87,7 +87,7 @@ describe('Client', () => {
|
||||||
postcodes: [{code: '46001'}]
|
postcodes: [{code: '46001'}]
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(controller.address.provinceId).toEqual(1);
|
expect(controller.address.provinceFk).toEqual(1);
|
||||||
expect(controller.address.postalCode).toEqual('46001');
|
expect(controller.address.postalCode).toEqual('46001');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -112,7 +112,7 @@ describe('Client', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(controller.address.city).toEqual('New York');
|
expect(controller.address.city).toEqual('New York');
|
||||||
expect(controller.address.provinceId).toEqual(1);
|
expect(controller.address.provinceFk).toEqual(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ describe('Client', () => {
|
||||||
controller.onCustomAgentAccept();
|
controller.onCustomAgentAccept();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.address.customsAgentId).toEqual(1);
|
expect(controller.address.customsAgentFk).toEqual(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -190,8 +190,6 @@ module.exports = Self => {
|
||||||
item.prices.push(price);
|
item.prices.push(price);
|
||||||
else
|
else
|
||||||
item.prices = [price];
|
item.prices = [price];
|
||||||
|
|
||||||
item.available = price.grouping;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -88,9 +88,29 @@ module.exports = Self => {
|
||||||
if (!zoneShipped || zoneShipped.zoneFk != zoneFk)
|
if (!zoneShipped || zoneShipped.zoneFk != zoneFk)
|
||||||
throw new UserError(`You don't have privileges to change the zone`);
|
throw new UserError(`You don't have privileges to change the zone`);
|
||||||
}
|
}
|
||||||
const originalTicket = await models.Ticket.findById(id, {fields:
|
const observationTypeDelivery = await models.ObservationType.findOne({
|
||||||
['id', 'clientFk', 'agencyModeFk', 'addressFk', 'zoneFk',
|
where: {code: 'delivery'}
|
||||||
'warehouseFk', 'companyFk', 'shipped', 'landed', 'isDeleted']
|
});
|
||||||
|
const originalTicket = await models.Ticket.findOne({
|
||||||
|
where: {id: id},
|
||||||
|
fields: ['id', 'clientFk', 'agencyModeFk', 'addressFk', 'zoneFk',
|
||||||
|
'warehouseFk', 'companyFk', 'shipped', 'landed', 'isDeleted'],
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
relation: 'address',
|
||||||
|
scope: {
|
||||||
|
include: {
|
||||||
|
relation: 'observations',
|
||||||
|
scope: {
|
||||||
|
where: {observationTypeFk: observationTypeDelivery.id},
|
||||||
|
include: {
|
||||||
|
relation: 'observationType'
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
});
|
});
|
||||||
const updatedTicket = Object.assign({}, ctx.args);
|
const updatedTicket = Object.assign({}, ctx.args);
|
||||||
delete updatedTicket.ctx;
|
delete updatedTicket.ctx;
|
||||||
|
@ -125,6 +145,25 @@ module.exports = Self => {
|
||||||
option
|
option
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (originalTicket.addressFk != updatedTicket.addressFk) {
|
||||||
|
const ticketObservation = await models.TicketObservation.findOne({
|
||||||
|
where: {
|
||||||
|
ticketFk: id,
|
||||||
|
observationTypeFk: observationTypeDelivery.id}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ticketObservation)
|
||||||
|
await ticketObservation.destroy();
|
||||||
|
|
||||||
|
const [observation] = originalTicket.address().observations();
|
||||||
|
if (observation) {
|
||||||
|
await models.TicketObservation.upsert({
|
||||||
|
ticketFk: id,
|
||||||
|
observationTypeFk: observation.observationTypeFk,
|
||||||
|
description: observation.description
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
await models.TicketLog.create(logRecord);
|
await models.TicketLog.create(logRecord);
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue