salesPersonUser replaces salesPerson relation #378

Merged
joan merged 1 commits from 2396-client_model_replace_relation_salesPerson into dev 2020-09-16 08:36:44 +00:00
30 changed files with 103 additions and 158 deletions

View File

@ -51,15 +51,9 @@ module.exports = Self => {
scope: { scope: {
fields: ['salesPersonFk', 'name'], fields: ['salesPersonFk', 'name'],
include: { include: {
relation: 'salesPerson', relation: 'salesPersonUser',
scope: { scope: {
fields: ['userFk'], fields: ['id', 'name']
include: {
relation: 'user',
scope: {
fields: ['nickname']
}
}
} }
} }
} }

View File

@ -45,7 +45,7 @@ module.exports = Self => {
if (addressId) if (addressId)
address = await models.Address.findById(addressId, null, options); address = await models.Address.findById(addressId, null, options);
const salesPerson = sale.ticket().client().salesPerson(); const salesPerson = sale.ticket().client().salesPersonUser();
if (salesPerson) { if (salesPerson) {
const nickname = address && address.nickname || destination.description; const nickname = address && address.nickname || destination.description;
const origin = ctx.req.headers.origin; const origin = ctx.req.headers.origin;
@ -113,7 +113,10 @@ module.exports = Self => {
relation: 'client', relation: 'client',
scope: { scope: {
include: { include: {
relation: 'salesPerson' relation: 'salesPersonUser',
scope: {
fields: ['id', 'name']
}
} }
} }
} }

View File

@ -16,7 +16,7 @@
</vn-label-value> </vn-label-value>
<vn-label-value <vn-label-value
label="Salesperson" label="Salesperson"
value="{{$ctrl.summary.claim.client.salesPerson.user.nickname}}"> value="{{$ctrl.summary.claim.client.salesPersonUser.name}}">
</vn-label-value> </vn-label-value>
<vn-label-value <vn-label-value
label="Attended by" label="Attended by"

View File

@ -46,7 +46,6 @@ module.exports = function(Self) {
isEqualizated: data.isEqualizated isEqualizated: data.isEqualizated
}, options); }, options);
let address = await Address.create({ let address = await Address.create({
clientFk: client.id, clientFk: client.id,
nickname: client.name, nickname: client.name,

View File

@ -25,17 +25,6 @@ module.exports = function(Self) {
}, },
include: [ include: [
{ {
relation: 'salesPerson',
scope: {
fields: ['userFk', 'firstName'],
include: {
relation: 'user',
scope: {
fields: ['name', 'nickname']
}
}
}
}, {
relation: 'contactChannel', relation: 'contactChannel',
scope: { scope: {
fields: ['id', 'name'] fields: ['id', 'name']

View File

@ -25,17 +25,17 @@ module.exports = Self => {
let conn = Self.dataSource.connector; let conn = Self.dataSource.connector;
let stmt = new ParameterizedSQL(` let stmt = new ParameterizedSQL(`
SELECT SELECT
t.id, t.id,
t.clientFk, t.clientFk,
t.created, t.created,
t.amount / 100 amount, t.amount / 100 amount,
t.receiptFk IS NOT NULL AS isConfirmed, t.receiptFk IS NOT NULL AS isConfirmed,
tt.message responseMessage, tt.message responseMessage,
te.message errorMessage te.message errorMessage
FROM hedera.tpvTransaction t FROM hedera.tpvTransaction t
JOIN hedera.tpvMerchant m ON m.id = t.merchantFk JOIN hedera.tpvMerchant m ON m.id = t.merchantFk
LEFT JOIN hedera.tpvResponse tt ON tt.id = t.response LEFT JOIN hedera.tpvResponse tt ON tt.id = t.response
LEFT JOIN hedera.tpvError te ON te.code = errorCode`); LEFT JOIN hedera.tpvError te ON te.code = errorCode`);
stmt.merge(conn.makeSuffix(filter, 't')); stmt.merge(conn.makeSuffix(filter, 't'));

View File

@ -30,8 +30,8 @@ module.exports = Self => {
}); });
Self.hasCustomerRole = (id, context, callback) => { Self.hasCustomerRole = (id, context, callback) => {
let query = let query = `
`SELECT COUNT(*) > 0 isCustomer SELECT COUNT(*) > 0 isCustomer
FROM salix.Account A FROM salix.Account A
JOIN salix.Role r ON r.id = A.roleFK JOIN salix.Role r ON r.id = A.roleFK
WHERE r.name = 'customer' WHERE r.name = 'customer'

View File

@ -30,12 +30,12 @@ module.exports = Self => {
}); });
Self.isValidClient = async id => { Self.isValidClient = async id => {
let query = let query = `
`SELECT r.name SELECT r.name
FROM salix.Account a FROM salix.Account a
JOIN vn.client c ON a.id = c.id JOIN vn.client c ON a.id = c.id
JOIN salix.RoleMapping rm ON rm.principalId = a.id JOIN salix.RoleMapping rm ON rm.principalId = a.id
JOIN salix.Role r ON r.id = rm.roleId JOIN salix.Role r ON r.id = rm.roleId
WHERE a.id = ? AND c.isActive AND c.isTaxDataChecked`; WHERE a.id = ? AND c.isActive AND c.isTaxDataChecked`;
let roleNames = await Self.rawSql(query, [id]); let roleNames = await Self.rawSql(query, [id]);

View File

@ -42,15 +42,9 @@ module.exports = Self => {
} }
}, },
{ {
relation: 'salesPerson', relation: 'salesPersonUser',
scope: { scope: {
fields: ['userFk'], fields: ['id', 'name']
include: {
relation: 'user',
scope: {
fields: ['name']
}
}
} }
}, },
{ {

View File

@ -25,7 +25,6 @@ module.exports = Self => {
Self.createWithInsurance = async(data, ctx) => { Self.createWithInsurance = async(data, ctx) => {
const tx = await Self.beginTransaction({}); const tx = await Self.beginTransaction({});
const models = Self.app.models; const models = Self.app.models;
const $t = ctx.req.__; // $translate
try { try {
let options = {transaction: tx}; let options = {transaction: tx};

View File

@ -105,7 +105,7 @@ module.exports = Self => {
}); });
function hasSalesMan(err) { function hasSalesMan(err) {
if (this.payMethod && !this.salesPerson) if (this.payMethod && !this.salesPersonUser)
err(); err();
} }

View File

@ -131,11 +131,6 @@
"model": "PayMethod", "model": "PayMethod",
"foreignKey": "payMethodFk" "foreignKey": "payMethodFk"
}, },
"salesPerson": {
"type": "belongsTo",
"model": "Worker",
"foreignKey": "salesPersonFk"
},
"salesPersonUser": { "salesPersonUser": {
"type": "belongsTo", "type": "belongsTo",
"model": "Account", "model": "Account",

View File

@ -51,7 +51,7 @@ module.exports = function(Self) {
const data = ctx.instance; const data = ctx.instance;
const insurance = await Self.findById(data.id, null, options); const insurance = await Self.findById(data.id, null, options);
const client = insurance.classification().customer(); const client = insurance.classification().customer();
const salesPerson = client.salesPerson(); const salesPerson = client.salesPersonUser();
if (!salesPerson) return; if (!salesPerson) return;

View File

@ -43,15 +43,9 @@
"scope": { "scope": {
"fields": ["name", "salesPersonFk"], "fields": ["name", "salesPersonFk"],
"include": { "include": {
"relation": "salesPerson", "relation": "salesPersonUser",
"scope": { "scope": {
"fields": "userFk", "fields": ["id", "name"]
"include": {
"relation": "user",
"scope": {
"fields": ["name"]
}
}
} }
} }
} }

View File

@ -39,7 +39,7 @@
<span <span
ng-click="workerDescriptor.show($event, $ctrl.client.salesPersonFk)" ng-click="workerDescriptor.show($event, $ctrl.client.salesPersonFk)"
class="link"> class="link">
{{$ctrl.client.salesPerson.user.name}} {{$ctrl.client.salesPersonUser.name}}
</span> </span>
</vn-label-value> </vn-label-value>
</div> </div>

View File

@ -1,5 +1,5 @@
<vn-card class="summary"> <vn-card class="summary">
<h5>{{$ctrl.summary.name}} - {{$ctrl.summary.id}} - {{$ctrl.summary.salesPerson.user.nickname}}</h5> <h5>{{$ctrl.summary.name}} - {{$ctrl.summary.id}} - {{$ctrl.summary.salesPersonUser.name}}</h5>
<vn-horizontal> <vn-horizontal>
<vn-one> <vn-one>
<h4 translate>Basic data</h4> <h4 translate>Basic data</h4>
@ -25,7 +25,7 @@
<span <span
ng-click="workerDescriptor.show($event, $ctrl.summary.salesPersonFk)" ng-click="workerDescriptor.show($event, $ctrl.summary.salesPersonFk)"
class="link"> class="link">
{{$ctrl.summary.salesPerson.user.name}} {{$ctrl.summary.salesPersonUser.name}}
</span> </span>
</vn-label-value> </vn-label-value>
<vn-label-value label="Channel" <vn-label-value label="Channel"

View File

@ -91,30 +91,31 @@ module.exports = Self => {
] ]
)); ));
stmt = new ParameterizedSQL(`SELECT stmt = new ParameterizedSQL(`
i.id, SELECT
i.name, i.id,
i.subName, i.name,
i.image, i.subName,
i.tag5, i.image,
i.value5, i.tag5,
i.tag6, i.value5,
i.value6, i.tag6,
i.tag7, i.value6,
i.value7, i.tag7,
i.tag8, i.value7,
i.value8, i.tag8,
tci.price, i.value8,
tci.available, tci.price,
w.lastName AS lastName, tci.available,
w.firstName, w.lastName AS lastName,
tci.priceKg, w.firstName,
ink.hex tci.priceKg,
FROM tmp.ticketCalculateItem tci ink.hex
JOIN vn.item i ON i.id = tci.itemFk FROM tmp.ticketCalculateItem tci
JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.item i ON i.id = tci.itemFk
JOIN vn.ink ON ink.id = i.inkFk JOIN vn.itemType it ON it.id = i.typeFk
JOIN vn.worker w on w.id = it.workerFk`); JOIN vn.ink ON ink.id = i.inkFk
JOIN vn.worker w on w.id = it.workerFk`);
// Apply order by tag // Apply order by tag
if (orderBy.isTag) { if (orderBy.isTag) {

View File

@ -38,16 +38,16 @@ module.exports = Self => {
order.agencyModeFk order.agencyModeFk
]); ]);
stmts.push(stmt); stmts.push(stmt);
stmt = new ParameterizedSQL(`SELECT it.id, it.name, ic.name categoryName stmt = new ParameterizedSQL(`
FROM tmp.availableCalc ac SELECT it.id, it.name, ic.name categoryName
JOIN cache.available a ON a.calc_id = ac.calcFk FROM tmp.availableCalc ac
JOIN item i ON i.id = a.item_id JOIN cache.available a ON a.calc_id = ac.calcFk
JOIN itemType it ON it.id = i.typeFk JOIN item i ON i.id = a.item_id
JOIN itemCategory ic ON ic.id = it.categoryFk JOIN itemType it ON it.id = i.typeFk
WHERE it.categoryFk = ? JOIN itemCategory ic ON ic.id = it.categoryFk
GROUP BY it.id`, [ WHERE it.categoryFk = ?
itemCategoryId GROUP BY it.id`, [itemCategoryId]
]); );
let categoriesIndex = stmts.push(stmt) - 1; let categoriesIndex = stmts.push(stmt) - 1;
let sql = ParameterizedSQL.join(stmts, ';'); let sql = ParameterizedSQL.join(stmts, ';');

View File

@ -28,7 +28,6 @@ module.exports = Self => {
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.order'); stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.order');
stmt = new ParameterizedSQL(` stmt = new ParameterizedSQL(`
CREATE TEMPORARY TABLE tmp.order CREATE TEMPORARY TABLE tmp.order
(INDEX (orderFk)) (INDEX (orderFk))

View File

@ -31,14 +31,17 @@ module.exports = Self => {
async function getOrderData(Self, orderId) { async function getOrderData(Self, orderId) {
let filter = { let filter = {
include: [ include: [
{relation: 'agencyMode', scope: {fields: ['name']}}, {
relation: 'agencyMode', scope: {fields: ['name']}},
{ {
relation: 'client', relation: 'client',
scope: { scope: {
fields: ['salesPersonFk', 'name'], fields: ['salesPersonFk', 'name'],
include: { include: {
relation: 'salesPerson', relation: 'salesPersonUser',
fields: ['firstName', 'name'] scope: {
fields: ['id', 'name']
}
} }
} }
}, },

View File

@ -31,15 +31,9 @@ class Controller extends ModuleCard {
'isTaxDataChecked' 'isTaxDataChecked'
], ],
include: { include: {
relation: 'salesPerson', relation: 'salesPersonUser',
scope: { scope: {
fields: ['userFk'], fields: ['id', 'name']
include: {
relation: 'user',
scope: {
fields: ['name']
}
}
} }
} }
} }

View File

@ -19,7 +19,7 @@
<span <span
ng-click="workerDescriptor.show($event, $ctrl.order.client.salesPersonFk)" ng-click="workerDescriptor.show($event, $ctrl.order.client.salesPersonFk)"
class="link"> class="link">
{{$ctrl.order.client.salesPerson.user.name}} {{$ctrl.order.client.salesPersonUser.name}}
</span> </span>
</vn-label-value> </vn-label-value>
<vn-label-value <vn-label-value

View File

@ -31,7 +31,10 @@ module.exports = Self => {
relation: 'client', relation: 'client',
scope: { scope: {
include: { include: {
relation: 'salesPerson' relation: 'salesPersonUser',
scope: {
fields: ['id', 'name']
}
} }
} }
}] }]
@ -69,7 +72,7 @@ module.exports = Self => {
await ticketTracking.destroy(); await ticketTracking.destroy();
const salesPerson = ticket.client().salesPerson(); const salesPerson = ticket.client().salesPersonUser();
if (salesPerson) { if (salesPerson) {
const origin = ctx.req.headers.origin; const origin = ctx.req.headers.origin;
const message = $t('This ticket is not an stowaway anymore', { const message = $t('This ticket is not an stowaway anymore', {

View File

@ -260,12 +260,12 @@ module.exports = Self => {
stmt = new ParameterizedSQL(` stmt = new ParameterizedSQL(`
SELECT SELECT
f.*, f.*,
tt.total, tt.total,
tp.* tp.*
FROM tmp.filter f FROM tmp.filter f
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id
LEFT JOIN tmp.ticketTotal tt ON tt.ticketFk = f.id`); LEFT JOIN tmp.ticketTotal tt ON tt.ticketFk = f.id`);
if (args.problems != undefined && (!args.from && !args.to)) if (args.problems != undefined && (!args.from && !args.to))
throw new UserError('Choose a date range or days forward'); throw new UserError('Choose a date range or days forward');

View File

@ -89,12 +89,9 @@ module.exports = Self => {
scope: { scope: {
fields: ['id', 'salesPersonFk'], fields: ['id', 'salesPersonFk'],
include: { include: {
relation: 'salesPerson', relation: 'salesPersonUser',
scope: { scope: {
fields: ['id', 'userFk'], fields: ['id', 'name']
include: {
relation: 'user'
}
} }
} }
} }
@ -121,15 +118,14 @@ module.exports = Self => {
} }
// Send notification to salesPerson // Send notification to salesPerson
const salesPerson = ticket.client().salesPerson(); const salesPersonUser = ticket.client().salesPersonUser();
if (salesPerson) { if (salesPersonUser) {
const salesPersonUser = salesPerson.user().name;
const origin = ctx.req.headers.origin; const origin = ctx.req.headers.origin;
const message = $t(`Has deleted the ticket id`, { const message = $t(`Has deleted the ticket id`, {
id: id, id: id,
url: `${origin}/#!/ticket/${id}/summary` url: `${origin}/#!/ticket/${id}/summary`
}); });
await models.Chat.send(ctx, `@${salesPersonUser}`, message); await models.Chat.send(ctx, `@${salesPersonUser.name}`, message);
} }
return ticket.updateAttribute('isDeleted', true); return ticket.updateAttribute('isDeleted', true);

View File

@ -57,15 +57,9 @@ module.exports = Self => {
scope: { scope: {
fields: ['salesPersonFk', 'name', 'phone', 'mobile'], fields: ['salesPersonFk', 'name', 'phone', 'mobile'],
include: { include: {
relation: 'salesPerson', relation: 'salesPersonUser',
scope: { scope: {
fields: ['userFk'], fields: ['id', 'name']
include: {
relation: 'user',
scope: {
fields: ['name']
}
}
} }
} }
} }

View File

@ -38,15 +38,9 @@ class Controller extends ModuleCard {
'mobile' 'mobile'
], ],
include: { include: {
relation: 'salesPerson', relation: 'salesPersonUser',
scope: { scope: {
fields: ['userFk'], fields: ['id', 'name']
include: {
relation: 'user',
scope: {
fields: ['name']
}
}
} }
}, },
}, },

View File

@ -94,7 +94,7 @@
<span <span
ng-click="workerDescriptor.show($event, $ctrl.ticket.client.salesPersonFk)" ng-click="workerDescriptor.show($event, $ctrl.ticket.client.salesPersonFk)"
class="link"> class="link">
{{$ctrl.ticket.client.salesPerson.user.name}} {{$ctrl.ticket.client.salesPersonUser.name}}
</span> </span>
</vn-label-value> </vn-label-value>
<vn-label-value <vn-label-value

View File

@ -204,15 +204,9 @@ class Controller extends Descriptor {
'isTaxDataChecked' 'isTaxDataChecked'
], ],
include: { include: {
relation: 'salesPerson', relation: 'salesPersonUser',
scope: { scope: {
fields: ['userFk'], fields: ['id', 'name']
include: {
relation: 'user',
scope: {
fields: ['name']
}
}
} }
} }
} }

View File

@ -22,7 +22,7 @@
<span <span
ng-click="workerDescriptor.show($event, $ctrl.summary.client.salesPersonFk)" ng-click="workerDescriptor.show($event, $ctrl.summary.client.salesPersonFk)"
class="link"> class="link">
{{$ctrl.summary.client.salesPerson.user.name}} {{$ctrl.summary.client.salesPersonUser.name}}
</span> </span>
</vn-label-value> </vn-label-value>
<vn-label-value label="Agency" <vn-label-value label="Agency"