HOTFIX: Disable address without a province
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-07-12 08:29:21 +02:00
parent 35e3c8ce65
commit 878e989c02
1 changed files with 14 additions and 12 deletions

View File

@ -91,20 +91,22 @@ module.exports = function(Self) {
} }
}); });
const provinceId = args.provinceFk || address.provinceFk; const provinceId = args.provinceFk || address.provinceFk;
const province = await models.Province.findById(provinceId, { if (provinceId) {
include: { const province = await models.Province.findById(provinceId, {
relation: 'country' include: {
} relation: 'country'
}, options); }
}, options);
const isUeeMember = province.country().isUeeMember; const isUeeMember = province.country().isUeeMember;
const incotermsId = args.incotermsFk || address.incotermsFk; const incotermsId = args.incotermsFk || address.incotermsFk;
if (!isUeeMember && !incotermsId) if (!isUeeMember && !incotermsId)
throw new UserError(`Incoterms is required for a non UEE member`); throw new UserError(`Incoterms is required for a non UEE member`);
const customsAgentId = args.customsAgentFk || address.customsAgentFk; const customsAgentId = args.customsAgentFk || address.customsAgentFk;
if (!isUeeMember && !customsAgentId) if (!isUeeMember && !customsAgentId)
throw new UserError(`Customs agent is required for a non UEE member`); throw new UserError(`Customs agent is required for a non UEE member`);
}
delete args.ctx; // Remove unwanted properties delete args.ctx; // Remove unwanted properties
const updatedAddress = await address.updateAttributes(ctx.args, options); const updatedAddress = await address.updateAttributes(ctx.args, options);