From 7537d35446f4661894e3b2553676b936564ce2ad Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 29 Jan 2019 15:04:38 +0100 Subject: [PATCH 01/10] uncheck zones,removed treeview model #1066 --- .../{zone-treeview => zone-geo}/getLeaves.js | 8 ++--- .../methods/zone-included/toggleIsIncluded.js | 6 ++-- modules/agency/back/model-config.json | 3 -- modules/agency/back/models/zone-geo.js | 3 ++ modules/agency/back/models/zone-geo.json | 6 ++++ modules/agency/back/models/zone-treeview.js | 3 -- modules/agency/back/models/zone-treeview.json | 30 ------------------- modules/agency/front/location/index.html | 2 +- modules/client/front/billing-data/index.js | 2 +- modules/client/front/sample/index/index.js | 12 ++++---- print/report/email-footer/index.js | 4 +-- 11 files changed, 26 insertions(+), 53 deletions(-) rename modules/agency/back/methods/{zone-treeview => zone-geo}/getLeaves.js (93%) create mode 100644 modules/agency/back/models/zone-geo.js delete mode 100644 modules/agency/back/models/zone-treeview.js delete mode 100644 modules/agency/back/models/zone-treeview.json diff --git a/modules/agency/back/methods/zone-treeview/getLeaves.js b/modules/agency/back/methods/zone-geo/getLeaves.js similarity index 93% rename from modules/agency/back/methods/zone-treeview/getLeaves.js rename to modules/agency/back/methods/zone-geo/getLeaves.js index 08774aa6c..c0496f765 100644 --- a/modules/agency/back/methods/zone-treeview/getLeaves.js +++ b/modules/agency/back/methods/zone-geo/getLeaves.js @@ -38,7 +38,7 @@ module.exports = Self => { stmts.push(new ParameterizedSQL( `SELECT lft, rgt, depth + 1 INTO @lft, @rgt, @depth - FROM zoneTreeview WHERE id = ?`, [parentFk])); + FROM zoneGeo WHERE id = ?`, [parentFk])); stmts.push(`DROP TEMPORARY TABLE IF EXISTS tChilds`); @@ -46,7 +46,7 @@ module.exports = Self => { `CREATE TEMPORARY TABLE tChilds ENGINE = MEMORY SELECT id, lft, rgt - FROM zoneTreeview pt`); + FROM zoneGeo pt`); stmt.merge(conn.makeSuffix(filter)); if (!filter.where) { @@ -63,7 +63,7 @@ module.exports = Self => { ENGINE = MEMORY SELECT t.id FROM tChilds t - JOIN zoneTreeview zt + JOIN zoneGeo zt ON zt.lft > t.lft AND zt.rgt < t.rgt JOIN zoneIncluded zi ON zi.geoFk = zt.id AND zi.zoneFk = ? @@ -80,7 +80,7 @@ module.exports = Self => { ti.id IS NOT NULL hasCheckedChilds, zi.geoFk IS NOT NULL AS selected, zi.isIncluded AS excluded - FROM zoneTreeview pt + FROM zoneGeo pt LEFT JOIN vn.zoneIncluded zi ON zi.geoFk = pt.id AND zi.zoneFk = ? JOIN tChilds c ON c.id = pt.id diff --git a/modules/agency/back/methods/zone-included/toggleIsIncluded.js b/modules/agency/back/methods/zone-included/toggleIsIncluded.js index 766c51835..f93df8b35 100644 --- a/modules/agency/back/methods/zone-included/toggleIsIncluded.js +++ b/modules/agency/back/methods/zone-included/toggleIsIncluded.js @@ -24,20 +24,20 @@ module.exports = Self => { Self.toggleIsIncluded = async(zoneFk, geoFk) => { const models = Self.app.models; - const geo = await models.ZoneTreeview.findById(geoFk); + const geo = await models.ZoneGeo.findById(geoFk); const isIncluded = await Self.findOne({ where: {zoneFk, geoFk} }); const hasCheckedParents = await Self.rawSql( `SELECT id - FROM vn.zoneTreeview zt + FROM vn.zoneGeo zt JOIN vn.zoneIncluded zi ON zi.geoFk = zt.id WHERE zt.lft < ? AND zt.rgt > ?`, [geo.lft, geo.rgt] ); const hasCheckedChilds = await Self.rawSql( `SELECT id - FROM vn.zoneTreeview zt + FROM vn.zoneGeo zt JOIN vn.zoneIncluded zi ON zi.geoFk = zt.id WHERE zt.lft > ? AND zt.rgt < ?`, [geo.lft, geo.rgt] ); diff --git a/modules/agency/back/model-config.json b/modules/agency/back/model-config.json index d0959864d..d910a1602 100644 --- a/modules/agency/back/model-config.json +++ b/modules/agency/back/model-config.json @@ -20,9 +20,6 @@ "ZoneIncluded": { "dataSource": "vn" }, - "ZoneTreeview": { - "dataSource": "vn" - }, "LabourHoliday": { "dataSource": "vn" }, diff --git a/modules/agency/back/models/zone-geo.js b/modules/agency/back/models/zone-geo.js new file mode 100644 index 000000000..987e2de71 --- /dev/null +++ b/modules/agency/back/models/zone-geo.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/zone-geo/getLeaves')(Self); +}; diff --git a/modules/agency/back/models/zone-geo.json b/modules/agency/back/models/zone-geo.json index 14f436133..0a001235f 100644 --- a/modules/agency/back/models/zone-geo.json +++ b/modules/agency/back/models/zone-geo.json @@ -19,6 +19,12 @@ }, "rgt": { "type": "Number" + }, + "depth": { + "type": "Number" + }, + "sons": { + "type": "Number" } } } \ No newline at end of file diff --git a/modules/agency/back/models/zone-treeview.js b/modules/agency/back/models/zone-treeview.js deleted file mode 100644 index 36c76e12f..000000000 --- a/modules/agency/back/models/zone-treeview.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = Self => { - require('../methods/zone-treeview/getLeaves')(Self); -}; diff --git a/modules/agency/back/models/zone-treeview.json b/modules/agency/back/models/zone-treeview.json deleted file mode 100644 index 9ffd14d7e..000000000 --- a/modules/agency/back/models/zone-treeview.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "ZoneTreeview", - "base": "VnModel", - "options": { - "mysql": { - "table": "zoneTreeview" - } - }, - "properties": { - "id": { - "id": true, - "type": "Number" - }, - "name": { - "type": "String" - }, - "lft": { - "type": "Number" - }, - "rgt": { - "type": "Number" - }, - "depth": { - "type": "Number" - }, - "sons": { - "type": "Number" - } - } -} \ No newline at end of file diff --git a/modules/agency/front/location/index.html b/modules/agency/front/location/index.html index 86d5f9f34..70fed6ff6 100644 --- a/modules/agency/front/location/index.html +++ b/modules/agency/front/location/index.html @@ -1,6 +1,6 @@ diff --git a/modules/client/front/billing-data/index.js b/modules/client/front/billing-data/index.js index 40116b416..fd7a0e8b8 100644 --- a/modules/client/front/billing-data/index.js +++ b/modules/client/front/billing-data/index.js @@ -35,7 +35,7 @@ export default class Controller { } notifyChanges() { - this.$http.post(`/email/payment-update`, {clientFk: this.client.id}).then( + this.$http.post(`/api/email/payment-update`, {clientFk: this.client.id}).then( () => this.vnApp.showMessage(this.$translate.instant('Notification sent!')) ); } diff --git a/modules/client/front/sample/index/index.js b/modules/client/front/sample/index/index.js index 7fd84f54c..78fd7f37e 100644 --- a/modules/client/front/sample/index/index.js +++ b/modules/client/front/sample/index/index.js @@ -6,21 +6,21 @@ class Controller { this.filter = { include: [ { - relation: "type", + relation: 'type', scope: { - fields: ["code", "description"] + fields: ['code', 'description'] } }, { - relation: "worker", + relation: 'worker', scope: { - fields: ["firstName", "name"] + fields: ['firstName', 'name'] } }, { - relation: "company", + relation: 'company', scope: { - fields: ["code"] + fields: ['code'] } } ] diff --git a/print/report/email-footer/index.js b/print/report/email-footer/index.js index a2ed8473e..6cd80b610 100755 --- a/print/report/email-footer/index.js +++ b/print/report/email-footer/index.js @@ -16,8 +16,8 @@ module.exports = { data() { return { files: [ - '/assets/images/action.png', - '/assets/images/info.png', + /* '/assets/images/action.png', + '/assets/images/info.png', */ '/assets/images/facebook.png', '/assets/images/twitter.png', '/assets/images/youtube.png', From f47fe9c1cc49c3063b5bd05913929a754b6fcf43 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 29 Jan 2019 16:37:59 +0100 Subject: [PATCH 02/10] #998 worker.index, back tests fixed --- back/model-config.json | 18 ----------- back/models/account.js | 6 +--- back/models/person-department.json | 31 ------------------ back/models/person-media.json | 25 --------------- loopback/util/user-error.js | 3 +- .../claim/back/methods/claim/updateClaim.js | 2 +- .../methods/ticket-tracking/changeState.js | 32 ++++++++----------- .../ticket-tracking/specs/changeState.spec.js | 21 ++++++------ modules/ticket/back/methods/ticket/deleted.js | 2 +- modules/worker/back/model-config.json | 21 +++++++++++- .../worker/back/models/worker-department.json | 25 +++++++++++++++ modules/worker/back/models/worker-media.json | 25 +++++++++++++++ modules/worker/back/models/worker.json | 10 ++++++ modules/worker/front/index/index.html | 19 ++++++++--- modules/worker/front/index/index.js | 20 ++++++++++-- modules/worker/front/search-panel/index.html | 7 ++++ 16 files changed, 150 insertions(+), 117 deletions(-) delete mode 100644 back/models/person-department.json delete mode 100644 back/models/person-media.json create mode 100644 modules/worker/back/models/worker-department.json create mode 100644 modules/worker/back/models/worker-media.json diff --git a/back/model-config.json b/back/model-config.json index f69b9d7d0..c66cdb421 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -29,27 +29,9 @@ "Warehouse": { "dataSource": "vn" }, - "Worker": { - "dataSource": "vn" - }, - "WorkerMana": { - "dataSource": "vn" - }, - "WorkerTeam": { - "dataSource": "vn" - }, - "WorkerTeamCollegues": { - "dataSource": "vn" - }, "Sip": { "dataSource": "vn" }, - "PersonMedia": { - "dataSource": "vn" - }, - "PersonDepartment": { - "dataSource": "vn" - }, "Route": { "dataSource": "vn" }, diff --git a/back/models/account.js b/back/models/account.js index 4ccd0e99a..12d1aca65 100644 --- a/back/models/account.js +++ b/back/models/account.js @@ -57,10 +57,7 @@ module.exports = Self => { */ Self.hasRole = async function(userId, name) { let roles = await Self.getRoles(userId); - - return roles.find(role => { - return role.toLowerCase() == name.toLowerCase(); - }); + return roles.find(role => role == name); }; /** @@ -81,7 +78,6 @@ module.exports = Self => { for (role of result) roles.push(role.name); - return roles; }; }; diff --git a/back/models/person-department.json b/back/models/person-department.json deleted file mode 100644 index 246fa4f5d..000000000 --- a/back/models/person-department.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "PersonDepartment", - "base": "VnModel", - "options": { - "mysql": { - "table": "personDepartment" - } - }, - "properties": { - "name": { - "type": "String" - }, - "firstName": { - "type": "String" - }, - "workerFk": { - "id": true, - "type": "Number" - }, - "department": { - "type": "Number" - } - }, - "relations": { - "worker": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "workerFk" - } - } -} diff --git a/back/models/person-media.json b/back/models/person-media.json deleted file mode 100644 index 1fa316602..000000000 --- a/back/models/person-media.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "PersonMedia", - "base": "VnModel", - "options": { - "mysql": { - "table": "personMedia" - } - }, - "properties": { - "mediaValue": { - "type": "String" - }, - "workerFk": { - "id": true, - "type": "Number" - } - }, - "relations": { - "worker": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "workerFk" - } - } -} diff --git a/loopback/util/user-error.js b/loopback/util/user-error.js index 7ba4f10f2..c2d01e080 100644 --- a/loopback/util/user-error.js +++ b/loopback/util/user-error.js @@ -5,10 +5,11 @@ * be understandable by people who do not have a technical profile. */ module.exports = class UserError extends Error { - constructor(message, ...translateArgs) { + constructor(message, code, ...translateArgs) { super(message); this.name = 'UserError'; this.statusCode = 400; + this.code = code; this.translateArgs = translateArgs; } }; diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index 21dc23abb..8b88078a7 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -29,7 +29,7 @@ module.exports = Self => { let token = ctx.req.accessToken; let currentUserId = token && token.userId; - isSalesAssistant = await models.Account.hasRole(currentUserId, 'SalesAssistant'); + isSalesAssistant = await models.Account.hasRole(currentUserId, 'salesAssistant'); if (!isSalesAssistant) { let oldClaim = await models.Claim.findById(params.id); diff --git a/modules/ticket/back/methods/ticket-tracking/changeState.js b/modules/ticket/back/methods/ticket-tracking/changeState.js index a701a1fdb..5e99f830d 100644 --- a/modules/ticket/back/methods/ticket-tracking/changeState.js +++ b/modules/ticket/back/methods/ticket-tracking/changeState.js @@ -6,10 +6,9 @@ module.exports = Self => { accessType: 'WRITE', accepts: [{ arg: 'params', - type: 'object', - required: true, description: 'ticketFk, stateFk', - http: {source: 'body'} + type: 'object', + required: true }], returns: { type: 'string', @@ -17,33 +16,30 @@ module.exports = Self => { }, http: { path: `/changeState`, - verb: 'post' + verb: 'POST' } }); Self.changeState = async(ctx, params) => { + let userId = ctx.req.accessToken.userId; let models = Self.app.models; - let isProduction; - let isEditable = await Self.app.models.Ticket.isEditable(params.ticketFk); - let assignedState = await Self.app.models.State.findOne({where: {code: 'PICKER_DESIGNED'}}); + + let isEditable = await models.Ticket.isEditable(params.ticketFk); + let assignedState = await models.State.findOne({where: {code: 'PICKER_DESIGNED'}}); let isAssigned = assignedState.id === params.stateFk; - let currentUserId; - if (ctx.req.accessToken) { - let token = ctx.req.accessToken; - currentUserId = token && token.userId; - isProduction = await models.Account.hasRole(currentUserId, 'production'); - isSalesperson = await models.Account.hasRole(currentUserId, 'salesPerson'); - } + let isProduction = await models.Account.hasRole(userId, 'production'); + let isSalesPerson = await models.Account.hasRole(userId, 'salesPerson'); + let isAllowed = isProduction || isSalesPerson && isEditable && isAssigned; - if ((!isEditable && !isProduction) || (isEditable && !isAssigned && isSalesperson) || (!isSalesperson && !isProduction)) - throw new UserError(`You don't have enough privileges to change the state of this ticket`); + if (!isAllowed) + throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED'); if (!isAssigned) { - let worker = await models.Worker.findOne({where: {userFk: currentUserId}}); + let worker = await models.Worker.findOne({where: {userFk: userId}}); params.workerFk = worker.id; } - return await Self.app.models.TicketTracking.create(params); + return await models.TicketTracking.create(params); }; }; diff --git a/modules/ticket/back/methods/ticket-tracking/specs/changeState.spec.js b/modules/ticket/back/methods/ticket-tracking/specs/changeState.spec.js index 8e51a08ac..ad8f45a47 100644 --- a/modules/ticket/back/methods/ticket-tracking/specs/changeState.spec.js +++ b/modules/ticket/back/methods/ticket-tracking/specs/changeState.spec.js @@ -16,41 +16,44 @@ describe('ticket changeState()', () => { it('should throw an error if the ticket is not editable and the user isnt production', async() => { let ctx = {req: {accessToken: {userId: 18}}}; let params = {ticketFk: 2, stateFk: 3}; - let error; + + let errCode; try { await app.models.TicketTracking.changeState(ctx, params); } catch (e) { - error = e; + errCode = e.code; } - expect(error).toEqual(new Error(`You don't have enough privileges to change the state of this ticket`)); + expect(errCode).toBe('ACCESS_DENIED'); }); it('should throw an error if the state is assigned and theres not worker in params', async() => { let ctx = {req: {accessToken: {userId: 18}}}; let assignedState = await app.models.State.findOne({where: {code: 'PICKER_DESIGNED'}}); let params = {ticketFk: 11, stateFk: assignedState.id}; - let error; + + let errCode; try { await app.models.TicketTracking.changeState(ctx, params); } catch (e) { - error = e; + errCode = e.details.codes.workerFk[0]; } - expect(error.message).toEqual('La instancia `TicketTracking` no es válida. Detalles: `workerFk` Worker cannot be blank (value: undefined).'); + expect(errCode).toEqual('presence'); }); it('should throw an error if a worker thats not production tries to change the state to one thats not assigned', async() => { let ctx = {req: {accessToken: {userId: 110}}}; let params = {ticketFk: 11, stateFk: 3}; - let error; + + let errCode; try { await app.models.TicketTracking.changeState(ctx, params); } catch (e) { - error = e; + errCode = e.code; } - expect(error.message).toEqual(`You don't have enough privileges to change the state of this ticket`); + expect(errCode).toBe('ACCESS_DENIED'); }); it('should be able to create a ticket tracking line for a not editable ticket if the user has the production role', async() => { diff --git a/modules/ticket/back/methods/ticket/deleted.js b/modules/ticket/back/methods/ticket/deleted.js index 7ddb180f7..0736be90a 100644 --- a/modules/ticket/back/methods/ticket/deleted.js +++ b/modules/ticket/back/methods/ticket/deleted.js @@ -24,7 +24,7 @@ module.exports = Self => { Self.deleted = async(ctx, params) => { let claimOfATicket = await Self.app.models.Claim.findOne({where: {ticketFk: params.id}}); if (claimOfATicket) - throw new UserError('You must delete the claim id %d first', claimOfATicket.id); + throw new UserError('You must delete the claim id %d first', 'DELETE_CLAIM_FIRST', claimOfATicket.id); let currentTicket = await Self.app.models.Ticket.findById(params.id); await currentTicket.updateAttributes({isDeleted: '1'}); diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index 0967ef424..266e00233 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -1 +1,20 @@ -{} +{ + "Worker": { + "dataSource": "vn" + }, + "WorkerMana": { + "dataSource": "vn" + }, + "WorkerTeam": { + "dataSource": "vn" + }, + "WorkerTeamCollegues": { + "dataSource": "vn" + }, + "WorkerMedia": { + "dataSource": "vn" + }, + "WorkerDepartment": { + "dataSource": "vn" + } +} diff --git a/modules/worker/back/models/worker-department.json b/modules/worker/back/models/worker-department.json new file mode 100644 index 000000000..461009c96 --- /dev/null +++ b/modules/worker/back/models/worker-department.json @@ -0,0 +1,25 @@ +{ + "name": "WorkerDepartment", + "base": "VnModel", + "options": { + "mysql": { + "table": "personDepartment" + } + }, + "properties": { + "workerFk": { + "id": true, + "type": "Number" + }, + "department": { + "type": "String" + } + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + } + } +} diff --git a/modules/worker/back/models/worker-media.json b/modules/worker/back/models/worker-media.json new file mode 100644 index 000000000..e86f9e1ac --- /dev/null +++ b/modules/worker/back/models/worker-media.json @@ -0,0 +1,25 @@ +{ + "name": "WorkerMedia", + "base": "VnModel", + "options": { + "mysql": { + "table": "personMedia" + } + }, + "properties": { + "workerFk": { + "id": true, + "type": "Number" + }, + "mediaValue": { + "type": "String" + } + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + } + } +} diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 6b382a16c..31106a94b 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -32,6 +32,16 @@ "model": "Account", "foreignKey": "userFk" }, + "client": { + "type": "belongsTo", + "model": "Client", + "foreignKey": "userFk" + }, + "department": { + "type": "belongsTo", + "model": "WorkerDepartment", + "foreignKey": "id" + }, "collegues": { "type": "hasMany", "model": "WorkerTeamCollegues", diff --git a/modules/worker/front/index/index.html b/modules/worker/front/index/index.html index 137543771..e6acf3158 100644 --- a/modules/worker/front/index/index.html +++ b/modules/worker/front/index/index.html @@ -1,10 +1,10 @@ + auto-load="false">
@@ -23,12 +23,21 @@ class="vn-list-item"> -
{{::$ctrl.worker.name}}
+
{{::worker.firstName}} {{::worker.name}}
- + + + + + + +
diff --git a/modules/worker/front/index/index.js b/modules/worker/front/index/index.js index 6619250af..4f6ea1a7e 100644 --- a/modules/worker/front/index/index.js +++ b/modules/worker/front/index/index.js @@ -4,7 +4,19 @@ export default class Controller { constructor($) { Object.assign(this, { $, - selectedWorker: null + selectedWorker: null, + include: [ + { + relation: 'user', + scope: {fields: ['name', 'email']} + }, { + relation: 'client', + scope: {fields: ['fi']} + }, { + relation: 'department', + scope: {fields: ['department']} + } + ] }); } @@ -13,8 +25,12 @@ export default class Controller { case 'search': return /^\d+$/.test(value) ? {id: value} - : {name: {like: `%${value}%`}}; + : {or: [ + {firstName: {like: `%${value}%`}}, + {name: {like: `%${value}%`}} + ]}; case 'name': + case 'firstName': return {[param]: {like: `%${value}%`}}; case 'id': return {[param]: value}; diff --git a/modules/worker/front/search-panel/index.html b/modules/worker/front/search-panel/index.html index 02b8bcb36..2e9249541 100644 --- a/modules/worker/front/search-panel/index.html +++ b/modules/worker/front/search-panel/index.html @@ -17,6 +17,13 @@ + + + + From e553d6349283c4aadd003d64d72c18ca57917687 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 29 Jan 2019 21:00:27 +0100 Subject: [PATCH 03/10] #996 worker.descriptor --- back/models/sip.json | 19 ++++------ .../05_create_new_tracking_state.spec.js | 2 +- gulpfile.js | 5 +-- loopback/locale/en.json | 4 +-- loopback/locale/es.json | 1 - .../methods/ticket-tracking/changeState.js | 25 +++++++------ modules/worker/back/models/worker.json | 8 +++++ modules/worker/front/card/index.js | 20 ++++++++++- modules/worker/front/descriptor/index.html | 36 ++++++++++++++++--- modules/worker/front/index/index.html | 2 +- 10 files changed, 86 insertions(+), 36 deletions(-) diff --git a/back/models/sip.json b/back/models/sip.json index de6af8ad8..98bcfee96 100644 --- a/back/models/sip.json +++ b/back/models/sip.json @@ -7,24 +7,19 @@ } }, "properties": { - "code": { + "userFk": { "type": "Number", "id": true, + "description": "The user id", "mysql": { - "columnName": "extension" + "columnName": "user_id" } }, - "password": { - "type": "string", - "mysql": { - "columnName": "secret" - } + "extension": { + "type": "String" }, - "name": { - "type": "string", - "mysql": { - "columnName": "caller_id" - } + "secret": { + "type": "String" } }, "relations": { diff --git a/e2e/paths/ticket-module/05_create_new_tracking_state.spec.js b/e2e/paths/ticket-module/05_create_new_tracking_state.spec.js index 061d67c1c..ce7f63f71 100644 --- a/e2e/paths/ticket-module/05_create_new_tracking_state.spec.js +++ b/e2e/paths/ticket-module/05_create_new_tracking_state.spec.js @@ -73,7 +73,7 @@ describe('Ticket Create new tracking state path', () => { .waitToClick(selectors.createStateView.saveStateButton) .waitForLastSnackbar(); - expect(result).toEqual(`You don't have enough privileges to change the state of this ticket`); + expect(result).toEqual(`You don't have enough privileges`); }); it(`should attempt to create an state for the type salesPerson has rights but fail as worker is blank`, async() => { diff --git a/gulpfile.js b/gulpfile.js index b4a333dc7..fce5555ce 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -45,10 +45,11 @@ function backWatch(done) { // XXX: Workaround to avoid nodemon bug // https://github.com/remy/nodemon/issues/1346 - let sleepBin = isWindows ? '' : 'sleep 1 &&'; + let commands = ['node --inspect ./node_modules/gulp/bin/gulp.js']; + if (!isWindows) commands.unshift('sleep 1'); nodemon({ - exec: `${sleepBin}node --inspect ./node_modules/gulp/bin/gulp.js`, + exec: commands.join(' && '), args: ['backOnly'], watch: backSources, done: done diff --git a/loopback/locale/en.json b/loopback/locale/en.json index e9395682f..06060fe67 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -29,6 +29,6 @@ "You can't make changes on the basic data of an confirmed order or with rows": "You can't make changes on the basic data of an confirmed order or with rows", "You can't create a ticket for a inactive client": "You can't create a ticket for a inactive client", "Worker cannot be blank": "Worker cannot be blank", - "You don't have enough privileges to change the state of this ticket": "You don't have enough privileges to change the state of this ticket", - "You must delete the claim id %d first": "You must delete the claim id %d first" + "You must delete the claim id %d first": "You must delete the claim id %d first", + "You don't have enough privileges": "You don't have enough privileges" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index f7f128741..cc08b120e 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -37,7 +37,6 @@ "The grade must be an integer greater than or equal to zero": "El grade debe ser un entero mayor o igual a cero", "Sample type cannot be blank": "El tipo de plantilla no puede quedar en blanco", "Description cannot be blank": "Se debe rellenar el campo de texto", - "You don't have enough privileges to change the state of this ticket": "No tienes permisos para cambiar el estado de este ticket", "The new quantity should be smaller than the old one": "La nueva cantidad debe de ser menor que la anterior", "The value should not be greater than 100%": "El valor no debe de ser mayor de 100%", "The value should be a number": "El valor debe ser un numero", diff --git a/modules/ticket/back/methods/ticket-tracking/changeState.js b/modules/ticket/back/methods/ticket-tracking/changeState.js index 5e99f830d..2b6aab923 100644 --- a/modules/ticket/back/methods/ticket-tracking/changeState.js +++ b/modules/ticket/back/methods/ticket-tracking/changeState.js @@ -4,12 +4,15 @@ module.exports = Self => { Self.remoteMethodCtx('changeState', { description: 'Change the state of a ticket', accessType: 'WRITE', - accepts: [{ - arg: 'params', - description: 'ticketFk, stateFk', - type: 'object', - required: true - }], + accepts: [ + { + arg: 'data', + description: 'Model instance data', + type: 'Object', + required: true, + http: {source: 'body'} + } + ], returns: { type: 'string', root: true @@ -20,13 +23,13 @@ module.exports = Self => { } }); - Self.changeState = async(ctx, params) => { + Self.changeState = async(ctx, data) => { let userId = ctx.req.accessToken.userId; let models = Self.app.models; - let isEditable = await models.Ticket.isEditable(params.ticketFk); + let isEditable = await models.Ticket.isEditable(data.ticketFk); let assignedState = await models.State.findOne({where: {code: 'PICKER_DESIGNED'}}); - let isAssigned = assignedState.id === params.stateFk; + let isAssigned = assignedState.id === data.stateFk; let isProduction = await models.Account.hasRole(userId, 'production'); let isSalesPerson = await models.Account.hasRole(userId, 'salesPerson'); @@ -37,9 +40,9 @@ module.exports = Self => { if (!isAssigned) { let worker = await models.Worker.findOne({where: {userFk: userId}}); - params.workerFk = worker.id; + data.workerFk = worker.id; } - return await models.TicketTracking.create(params); + return await models.TicketTracking.create(data); }; }; diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 31106a94b..70f9bb693 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -21,6 +21,9 @@ "type": "string", "required": true }, + "phone": { + "type" : "String" + }, "userFk": { "type" : "Number", "required": true @@ -37,6 +40,11 @@ "model": "Client", "foreignKey": "userFk" }, + "sip": { + "type": "belongsTo", + "model": "Sip", + "foreignKey": "userFk" + }, "department": { "type": "belongsTo", "model": "WorkerDepartment", diff --git a/modules/worker/front/card/index.js b/modules/worker/front/card/index.js index 1e574aa1c..2095d1351 100644 --- a/modules/worker/front/card/index.js +++ b/modules/worker/front/card/index.js @@ -14,7 +14,25 @@ class Controller { reload() { let query = `api/Workers/${this.$stateParams.id}`; - this.$http.get(query).then(res => { + let filter = { + include: [ + { + relation: 'user', + scope: {fields: ['name', 'email']} + }, { + relation: 'client', + scope: {fields: ['fi']} + }, { + relation: 'department', + scope: {fields: ['department']} + }, { + relation: 'sip', + scope: {fields: ['extension']} + } + ] + }; + + this.$http.get(query, {params: {filter}}).then(res => { this.worker = res.data; }); } diff --git a/modules/worker/front/descriptor/index.html b/modules/worker/front/descriptor/index.html index 9fdb87c1d..4222ca490 100644 --- a/modules/worker/front/descriptor/index.html +++ b/modules/worker/front/descriptor/index.html @@ -9,13 +9,39 @@
- +
+
{{::$ctrl.worker.firstName}} {{::$ctrl.worker.name}}
+ value="{{::$ctrl.worker.id}}"> - + - + + + + + + + + + + +
+
\ No newline at end of file diff --git a/modules/worker/front/index/index.html b/modules/worker/front/index/index.html index e6acf3158..342fb1de3 100644 --- a/modules/worker/front/index/index.html +++ b/modules/worker/front/index/index.html @@ -18,7 +18,7 @@ From 7893c784aabdd231f28316982b3c97b9853a1f9b Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 29 Jan 2019 21:45:43 +0100 Subject: [PATCH 04/10] #997 worker summary --- back/models/account.json | 13 ++++++ front/salix/styles/descriptor.scss | 6 +++ modules/worker/back/models/worker-mana.json | 14 +++--- modules/worker/front/summary/index.html | 49 +++++++++++++++------ modules/worker/front/summary/index.js | 35 ++++++++++++--- 5 files changed, 92 insertions(+), 25 deletions(-) diff --git a/back/models/account.json b/back/models/account.json index 1ec9d789f..89b1f42c5 100644 --- a/back/models/account.json +++ b/back/models/account.json @@ -15,6 +15,12 @@ "type": "string", "required": true }, + "roleFk": { + "type": "number", + "mysql": { + "columnName": "role" + } + }, "nickname": { "type": "string" }, @@ -35,6 +41,13 @@ "type": "date" } }, + "relations": { + "role": { + "type": "belongsTo", + "model": "Role", + "foreignKey": "roleFk" + } + }, "acls": [ { "property": "login", diff --git a/front/salix/styles/descriptor.scss b/front/salix/styles/descriptor.scss index 18f08adf6..7837a8326 100644 --- a/front/salix/styles/descriptor.scss +++ b/front/salix/styles/descriptor.scss @@ -33,6 +33,12 @@ & > * { @extend .pad-small; } + & > .attributes > h5 { + @extend .pad-small-bottom; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + } & > .icons { display: flex; align-items: center; diff --git a/modules/worker/back/models/worker-mana.json b/modules/worker/back/models/worker-mana.json index 509067e35..8de7c1fe1 100644 --- a/modules/worker/back/models/worker-mana.json +++ b/modules/worker/back/models/worker-mana.json @@ -3,23 +3,23 @@ "base": "VnModel", "options": { "mysql": { - "table": "bs.workerMana" + "table": "bs.workerMana" } }, "properties": { "amount": { - "type": "Number" + "type": "Number" }, "workerFk": { - "id": true, - "type": "Number" + "id": true, + "type": "Number" } }, "relations": { "worker": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "workerFk" + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" } } } diff --git a/modules/worker/front/summary/index.html b/modules/worker/front/summary/index.html index 63dae45d4..44149ad0c 100644 --- a/modules/worker/front/summary/index.html +++ b/modules/worker/front/summary/index.html @@ -1,15 +1,38 @@ -
{{worker.name}}
- - - - - - - - - - +
{{worker.firstName}} {{worker.name}}
+ + +

Basic data

+ + + + + + + + + + +
+ +

User info

+ + + + + + + + +
+
\ No newline at end of file diff --git a/modules/worker/front/summary/index.js b/modules/worker/front/summary/index.js index 20b08c7ab..ec96e444b 100644 --- a/modules/worker/front/summary/index.js +++ b/modules/worker/front/summary/index.js @@ -15,11 +15,36 @@ class Controller { set worker(value) { this._worker = value; this.$.worker = null; - if (value) { - this.$http.get(`api/Workers/${value.id}`).then(res => { - this.$.worker = res.data; - }); - } + if (!value) return; + + let query = `api/Workers/${value.id}`; + let filter = { + include: [ + { + relation: 'user', + scope: { + fields: ['name', 'email', 'roleFk'], + include: { + relation: 'role', + scope: {fields: ['name']} + } + } + }, { + relation: 'client', + scope: {fields: ['fi']} + }, { + relation: 'department', + scope: {fields: ['department']} + }, { + relation: 'sip', + scope: {fields: ['extension']} + } + ] + }; + + this.$http.get(query, {params: {filter}}).then(res => { + this.$.worker = res.data; + }); } } From 8d2f56a54751e52bd55d16b3b4c678f8e5dad46b Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 30 Jan 2019 07:18:33 +0100 Subject: [PATCH 05/10] updated clientBillingData email test #1001 --- modules/client/front/billing-data/index.spec.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/client/front/billing-data/index.spec.js b/modules/client/front/billing-data/index.spec.js index d589b4dff..1463d031d 100644 --- a/modules/client/front/billing-data/index.spec.js +++ b/modules/client/front/billing-data/index.spec.js @@ -30,11 +30,12 @@ describe('Client', () => { expect(controller.notifyChanges).toHaveBeenCalledWith(); }); }); - // Excluded due mailer changes #1001 - xdescribe('notifyChanges()', () => { + + describe('notifyChanges()', () => { it(`should perform a GET query`, () => { - $httpBackend.when('GET', `/mailer/notification/payment-update/101`).respond(true); - $httpBackend.expect('GET', `/mailer/notification/payment-update/101`); + let params = {clientFk: 101}; + $httpBackend.when('POST', `/api/email/payment-update`, params).respond(true); + $httpBackend.expect('POST', `/api/email/payment-update`, params); controller.notifyChanges(); $httpBackend.flush(); }); From c20a08e99b32fcd5a1e9b611bf07f8a4711d9f73 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 30 Jan 2019 08:09:21 +0100 Subject: [PATCH 06/10] updated clientSample with new reports uri #1001 --- modules/client/front/sample/create/index.js | 40 ++++++++++------ .../client/front/sample/create/index.spec.js | 46 ++++++++++++------- modules/client/front/sample/create/style.scss | 3 +- 3 files changed, 55 insertions(+), 34 deletions(-) diff --git a/modules/client/front/sample/create/index.js b/modules/client/front/sample/create/index.js index fe3355a64..d620164a9 100644 --- a/modules/client/front/sample/create/index.js +++ b/modules/client/front/sample/create/index.js @@ -14,9 +14,20 @@ class Controller { }; } + jsonToQuery(json) { + let query = ''; + for (let param in json) { + if (query != '') + query += '&'; + query += `${param}=${json[param]}`; + } + + return query; + } + showPreview() { let sampleType = this.$scope.sampleType.selection; - let queryParams; + let params = {clientFk: this.$stateParams.id}; if (!sampleType) return this.vnApp.showError(this.$translate.instant('Choose a sample')); @@ -24,19 +35,20 @@ class Controller { if (sampleType.hasCompany && !this.clientSample.companyFk) return this.vnApp.showError(this.$translate.instant('Choose a company')); - if (sampleType.hasCompany) { - queryParams = `${sampleType.code}/${this.clientSample.companyFk}/${this.$stateParams.id}/preview`; - } else { - queryParams = `${sampleType.code}/${this.$stateParams.id}/preview`; - } + if (sampleType.hasCompany) + params.companyFk = this.clientSample.companyFk; - let query = `/mailer/notification/${queryParams}`; + let query = `/api/email/${sampleType.code}?${this.jsonToQuery(params)}`; this.$http.get(query).then(res => { if (res.data) { let dialog = this.$scope.showPreview.element; let body = dialog.querySelector('tpl-body'); + let scroll = dialog.querySelector('div:first-child'); + body.innerHTML = res.data; this.$scope.showPreview.show(); + + scroll.scrollTop = 0; } }); } @@ -50,16 +62,14 @@ class Controller { sendSample() { let sampleType = this.$scope.sampleType.selection; - let queryParams; + let params = {clientFk: this.$stateParams.id}; - if (sampleType.hasCompany) { - queryParams = `${sampleType.code}/${this.clientSample.companyFk}/${this.$stateParams.id}`; - } else { - queryParams = `${sampleType.code}/${this.$stateParams.id}`; - } + if (sampleType.hasCompany) + params.companyFk = this.clientSample.companyFk; - let query = `/mailer/notification/${queryParams}`; - this.$http.get(query).then(res => { + + let query = `/api/email/${sampleType.code}?${this.jsonToQuery(params)}`; + this.$http.post(query).then(res => { if (res) { this.vnApp.showSuccess(this.$translate.instant('Notification sent!')); this.$state.go('client.card.sample.index'); diff --git a/modules/client/front/sample/create/index.spec.js b/modules/client/front/sample/create/index.spec.js index dfc660f35..adb7b1a45 100644 --- a/modules/client/front/sample/create/index.spec.js +++ b/modules/client/front/sample/create/index.spec.js @@ -1,6 +1,6 @@ import './index'; -describe('Client', () => { +fdescribe('Client', () => { describe('Component vnClientSampleCreate', () => { let $scope; let $httpBackend; @@ -38,6 +38,22 @@ describe('Client', () => { controller = $componentController('vnClientSampleCreate', {$scope, $state}); })); + describe('jsonToQuery()', () => { + it(`should convert a JSON object with clientFk property to query params`, () => { + let myObject = {clientFk: 101}; + let result = controller.jsonToQuery(myObject); + + expect(result).toEqual('clientFk=101'); + }); + + it(`should convert a JSON object with clientFk and companyFk properties to query params`, () => { + let myObject = {clientFk: 101, companyFk: 442}; + let result = controller.jsonToQuery(myObject); + + expect(result).toEqual('clientFk=101&companyFk=442'); + }); + }); + describe('showPreview()', () => { it(`should perform a query (GET) and open a sample preview`, () => { spyOn(controller.$scope.showPreview, 'show'); @@ -48,14 +64,13 @@ describe('Client', () => { }; controller.clientSample = { - clientFk: 101, - typeFK: 1 + clientFk: 101 }; let event = {preventDefault: () => {}}; - $httpBackend.whenGET(`/mailer/notification/MyReport/101/preview`).respond(true); - $httpBackend.expectGET(`/mailer/notification/MyReport/101/preview`); + $httpBackend.when('GET', `/api/email/MyReport?clientFk=101`).respond(true); + $httpBackend.expect('GET', `/api/email/MyReport?clientFk=101`); controller.showPreview(event); $httpBackend.flush(); @@ -72,14 +87,13 @@ describe('Client', () => { controller.clientSample = { clientFk: 101, - companyFk: 442, - typeFK: 1 + companyFk: 442 }; let event = {preventDefault: () => {}}; - $httpBackend.whenGET(`/mailer/notification/MyReport/442/101/preview`).respond(true); - $httpBackend.expectGET(`/mailer/notification/MyReport/442/101/preview`); + $httpBackend.when('GET', `/api/email/MyReport?clientFk=101&companyFk=442`).respond(true); + $httpBackend.expect('GET', `/api/email/MyReport?clientFk=101&companyFk=442`); controller.showPreview(event); $httpBackend.flush(); @@ -106,12 +120,11 @@ describe('Client', () => { }; controller.clientSample = { - clientFk: 101, - typeFK: 1 + clientFk: 101 }; - $httpBackend.whenGET(`/mailer/notification/MyReport/101`).respond(true); - $httpBackend.expectGET(`/mailer/notification/MyReport/101`); + $httpBackend.when('POST', `/api/email/MyReport?clientFk=101`).respond(true); + $httpBackend.expect('POST', `/api/email/MyReport?clientFk=101`); controller.sendSample(); $httpBackend.flush(); @@ -128,12 +141,11 @@ describe('Client', () => { controller.clientSample = { clientFk: 101, - companyFk: 442, - typeFK: 1 + companyFk: 442 }; - $httpBackend.whenGET(`/mailer/notification/MyReport/442/101`).respond(true); - $httpBackend.expectGET(`/mailer/notification/MyReport/442/101`); + $httpBackend.when('POST', `/api/email/MyReport?clientFk=101&companyFk=442`).respond(true); + $httpBackend.expect('POST', `/api/email/MyReport?clientFk=101&companyFk=442`); controller.sendSample(); $httpBackend.flush(); diff --git a/modules/client/front/sample/create/style.scss b/modules/client/front/sample/create/style.scss index 72e588db5..eecc8ad09 100644 --- a/modules/client/front/sample/create/style.scss +++ b/modules/client/front/sample/create/style.scss @@ -5,8 +5,7 @@ vn-client-sample-create { } tpl-body { - min-width: 800px; - max-height: 700px; + min-width: 800px } } } \ No newline at end of file From 8aad79886cccc428b664c54e2bd33663e34ade00 Mon Sep 17 00:00:00 2001 From: Gerard Date: Wed, 30 Jan 2019 08:28:09 +0100 Subject: [PATCH 07/10] fdescribe deleted --- modules/client/front/sample/create/index.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/client/front/sample/create/index.spec.js b/modules/client/front/sample/create/index.spec.js index adb7b1a45..c56cd7eed 100644 --- a/modules/client/front/sample/create/index.spec.js +++ b/modules/client/front/sample/create/index.spec.js @@ -1,6 +1,6 @@ import './index'; -fdescribe('Client', () => { +describe('Client', () => { describe('Component vnClientSampleCreate', () => { let $scope; let $httpBackend; From 91d3e75587aeafbd4e33938b41416455fbf7bc76 Mon Sep 17 00:00:00 2001 From: Gerard Date: Wed, 30 Jan 2019 08:43:11 +0100 Subject: [PATCH 08/10] bug removing local configuration solved --- .../components/user-configuration-popover/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/front/salix/components/user-configuration-popover/index.js b/front/salix/components/user-configuration-popover/index.js index 2ee77485d..1f70b9641 100644 --- a/front/salix/components/user-configuration-popover/index.js +++ b/front/salix/components/user-configuration-popover/index.js @@ -23,7 +23,10 @@ class Controller { set localWarehouseFk(value) { window.localStorage.localWarehouseFk = value; - window.localStorage.defaultWarehouseFk = value; + if (!value && this.warehouseFk) + window.localStorage.defaultWarehouseFk = this.warehouseFk; + else + window.localStorage.defaultWarehouseFk = value; this.showOk(); } @@ -33,7 +36,10 @@ class Controller { set localCompanyFk(value) { window.localStorage.localCompanyFk = value; - window.localStorage.defaultCompanyFk = value; + if (!value && this.companyFk) + window.localStorage.defaultCompanyFk = this.companyFk; + else + window.localStorage.defaultCompanyFk = value; this.showOk(); } From b791195b89cd366554b91d292305ec605c7efd1d Mon Sep 17 00:00:00 2001 From: Gerard Date: Wed, 30 Jan 2019 08:44:15 +0100 Subject: [PATCH 09/10] #1068 claim.descriptor --- modules/claim/front/card/index.js | 9 +++++++++ modules/claim/front/descriptor/index.html | 5 ++++- modules/claim/front/descriptor/index.js | 5 +++++ modules/claim/front/locale/es.yml | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/claim/front/card/index.js b/modules/claim/front/card/index.js index 76cbaa78e..22209ee5c 100644 --- a/modules/claim/front/card/index.js +++ b/modules/claim/front/card/index.js @@ -7,6 +7,15 @@ class Controller { this.filter = { include: [ {relation: 'worker', scope: {fields: ['name', 'firstName']}}, + { + relation: 'ticket', + scope: { + fields: ['agencyModeFk'], + include: { + relation: 'agencyMode' + } + } + }, {relation: 'claimState', scope: {fields: ['id', 'description']}}, { relation: 'client', diff --git a/modules/claim/front/descriptor/index.html b/modules/claim/front/descriptor/index.html index 59b51247c..7f492e6b0 100644 --- a/modules/claim/front/descriptor/index.html +++ b/modules/claim/front/descriptor/index.html @@ -34,7 +34,10 @@ - + +
diff --git a/modules/claim/front/descriptor/index.js b/modules/claim/front/descriptor/index.js index 4ef8a5b77..abbdcf43f 100644 --- a/modules/claim/front/descriptor/index.js +++ b/modules/claim/front/descriptor/index.js @@ -26,6 +26,11 @@ class Controller { icon: 'person', state: `client.card.summary({id: ${value.clientFk}})`, tooltip: 'Client card' + }, + btnTwo: { + icon: 'icon-ticket', + state: `ticket.card.summary({id: ${this.claim.ticketFk}})`, + tooltip: 'Claimed ticket' } }; } diff --git a/modules/claim/front/locale/es.yml b/modules/claim/front/locale/es.yml index 654f20fa1..5c10c79ad 100644 --- a/modules/claim/front/locale/es.yml +++ b/modules/claim/front/locale/es.yml @@ -1,6 +1,7 @@ #Ordenar alfabeticamente Add sale: Añadir linea Client Id: Id cliente +Claimed ticket: Ticket reclamado Observation: Observación Responsible: Responsable Remove sale: Borrar linea From 21e30bcaeff0cf30033b0d125f1bbbada48e8a2f Mon Sep 17 00:00:00 2001 From: Gerard Date: Wed, 30 Jan 2019 08:46:05 +0100 Subject: [PATCH 10/10] =?UTF-8?q?#1064=20quitar=20comprobaci=C3=B3n=20isTa?= =?UTF-8?q?xDataChecked?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/order/back/methods/order/new.js | 3 -- .../back/methods/order/specs/new.spec.js | 12 ------- modules/ticket/back/methods/ticket/new.js | 3 -- .../back/methods/ticket/specs/new.spec.js | 32 +++++++++++++++++-- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/modules/order/back/methods/order/new.js b/modules/order/back/methods/order/new.js index 0375155d2..98eb0ce1a 100644 --- a/modules/order/back/methods/order/new.js +++ b/modules/order/back/methods/order/new.js @@ -34,9 +34,6 @@ module.exports = Self => { if (!address.client().isActive) throw new UserError(`You can't create an order for a inactive client`); - if (!address.client().isTaxDataChecked) - throw new UserError(`You can't create an order for a client that doesn't has tax data verified`); - query = `CALL vn.orderListCreate(?, ?, ?, ?);`; [result] = await Self.rawSql(query, [ params.landed, diff --git a/modules/order/back/methods/order/specs/new.spec.js b/modules/order/back/methods/order/specs/new.spec.js index f98cf6e40..746818ee6 100644 --- a/modules/order/back/methods/order/specs/new.spec.js +++ b/modules/order/back/methods/order/specs/new.spec.js @@ -32,18 +32,6 @@ describe('order new()', () => { expect(error).toEqual(new UserError(`You can't create an order for a inactive client`)); }); - it('should throw an error if the client isnt frozen and is active but doesnt have data checked', async() => { - let error; - let params = {addressFk: 7}; - - await app.models.Order.new(params) - .catch(e => { - error = e; - }); - - expect(error).toEqual(new UserError(`You can't create an order for a client that doesn't has tax data verified`)); - }); - it('should create a new order for the user with id 105 when all conditions are met', async() => { let params = { landed: new Date(), diff --git a/modules/ticket/back/methods/ticket/new.js b/modules/ticket/back/methods/ticket/new.js index c92f09832..84e409a60 100644 --- a/modules/ticket/back/methods/ticket/new.js +++ b/modules/ticket/back/methods/ticket/new.js @@ -39,9 +39,6 @@ module.exports = Self => { if (!address.client().isActive) throw new UserError(`You can't create a ticket for a inactive client`); - if (!address.client().isTaxDataChecked) - throw new UserError(`You can't create a ticket for a client that doesn't has tax data verified`); - let clientFk = address.clientFk; let agency; if (params.agencyModeFk) diff --git a/modules/ticket/back/methods/ticket/specs/new.spec.js b/modules/ticket/back/methods/ticket/specs/new.spec.js index ff5fa9d89..607094874 100644 --- a/modules/ticket/back/methods/ticket/specs/new.spec.js +++ b/modules/ticket/back/methods/ticket/specs/new.spec.js @@ -1,15 +1,41 @@ const app = require('vn-loopback/server/server'); +let UserError = require('vn-loopback/util/user-error'); + describe('ticket new()', () => { let ticket; let today = new Date(); let ctx = {req: {accessToken: {userId: 1}}}; - afterAll(async () => { + afterAll(async() => { await app.models.Ticket.destroyById(ticket.id); }); - it('should throw an error if the address doesnt exist', async () => { + it('should throw an error if the client is frozen', async() => { + let error; + let params = {addressFk: 121}; + + await app.models.Ticket.new(ctx, params) + .catch(e => { + error = e; + }); + + expect(error).toEqual(new UserError(`You can't create a ticket for a frozen client`)); + }); + + it('should throw an error if the client isnt frozen and isnt active', async() => { + let error; + let params = {addressFk: 6}; + + await app.models.Ticket.new(ctx, params) + .catch(e => { + error = e; + }); + + expect(error).toEqual(new UserError(`You can't create a ticket for a inactive client`)); + }); + + it('should throw an error if the address doesnt exist', async() => { let error; let params = {addressFk: 'invalid address', clientFk: 104}; @@ -22,7 +48,7 @@ describe('ticket new()', () => { expect(error).toBeDefined(); }); - it('should return the id of the created ticket', async () => { + it('should return the id of the created ticket', async() => { let params = { warehouseFk: 1, clientFk: 104,