From dbe22844a6087dc926fa3007cf4ed0a07f4681d3 Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 30 Apr 2021 09:53:20 +0200 Subject: [PATCH] Removed unused method --- .../back/methods/supplier/createAddress.js | 90 ------------------- 1 file changed, 90 deletions(-) delete mode 100644 modules/supplier/back/methods/supplier/createAddress.js diff --git a/modules/supplier/back/methods/supplier/createAddress.js b/modules/supplier/back/methods/supplier/createAddress.js deleted file mode 100644 index 63995ba8f..000000000 --- a/modules/supplier/back/methods/supplier/createAddress.js +++ /dev/null @@ -1,90 +0,0 @@ -const UserError = require('vn-loopback/util/user-error'); - -module.exports = function(Self) { - Self.remoteMethodCtx('createAddress', { - description: 'Creates a supplier address', - accepts: [{ - arg: 'id', - type: 'number', - description: 'The supplier id', - http: {source: 'path'} - }, - { - arg: 'nickname', - type: 'string', - required: true - }, - { - arg: 'city', - type: 'string', - required: true - }, - { - arg: 'street', - type: 'string', - required: true - }, - { - arg: 'phone', - type: 'string' - }, - { - arg: 'mobile', - type: 'string' - }, - { - arg: 'postalCode', - type: 'string' - }, - { - arg: 'provinceFk', - type: 'number' - }], - returns: { - root: true, - type: 'Object' - }, - http: { - verb: 'post', - path: '/:id/createAddress' - } - }); - - Self.createAddress = async(ctx, clientFk) => { - const models = Self.app.models; - const args = ctx.args; - const tx = await models.Address.beginTransaction({}); - - try { - const options = {transaction: tx}; - const province = await models.Province.findById(args.provinceFk, { - include: { - relation: 'country' - } - }, options); - - const isUeeMember = province.country().isUeeMember; - if (!isUeeMember && !args.incotermsFk) - throw new UserError(`Incoterms is required for a non UEE member`); - - if (!isUeeMember && !args.customsAgentFk) - throw new UserError(`Customs agent is required for a non UEE member`); - - delete args.ctx; // Remove unwanted properties - const newAddress = await models.Address.create(args, options); - const client = await Self.findById(clientFk, null, options); - - if (args.isDefaultAddress) { - await client.updateAttributes({ - defaultAddressFk: newAddress.id - }, options); - } - - await tx.commit(); - return newAddress; - } catch (e) { - await tx.rollback(); - throw e; - } - }; -};