This commit is contained in:
Carlos Jimenez Ruiz 2019-01-30 08:51:18 +01:00
commit 15ded03ef9
52 changed files with 465 additions and 288 deletions

View File

@ -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"
},

View File

@ -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;
};
};

View File

@ -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",

View File

@ -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"
}
}
}

View File

@ -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"
}
}
}

View File

@ -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": {

View File

@ -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() => {

View File

@ -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();
}

View File

@ -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;

View File

@ -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

View File

@ -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"
}

View File

@ -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",

View File

@ -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;
}
};

View File

@ -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

View File

@ -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]
);

View File

@ -20,9 +20,6 @@
"ZoneIncluded": {
"dataSource": "vn"
},
"ZoneTreeview": {
"dataSource": "vn"
},
"LabourHoliday": {
"dataSource": "vn"
},

View File

@ -0,0 +1,3 @@
module.exports = Self => {
require('../methods/zone-geo/getLeaves')(Self);
};

View File

@ -19,6 +19,12 @@
},
"rgt": {
"type": "Number"
},
"depth": {
"type": "Number"
},
"sons": {
"type": "Number"
}
}
}

View File

@ -1,3 +0,0 @@
module.exports = Self => {
require('../methods/zone-treeview/getLeaves')(Self);
};

View File

@ -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"
}
}
}

View File

@ -1,6 +1,6 @@
<vn-crud-model
vn-id="model"
url="/agency/api/ZoneTreeviews/getLeaves"
url="/agency/api/ZoneGeos/getLeaves"
filter="::$ctrl.filter"
params="{zoneFk: $ctrl.$stateParams.id, parentFk: 1}">
</vn-crud-model>

View File

@ -34,7 +34,7 @@ module.exports = Self => {
let isSalesAssistant;
let currentUserId = ctx.req.accessToken.userId;
isSalesAssistant = await models.Account.hasRole(currentUserId, 'SalesAssistant');
isSalesAssistant = await models.Account.hasRole(currentUserId, 'salesAssistant');
if (!isSalesAssistant) {
let oldClaim = await models.Claim.findById(id);

View File

@ -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',

View File

@ -34,7 +34,10 @@
<vn-label-value label="Attended by"
value="{{$ctrl.claim.worker.firstName}} {{$ctrl.claim.worker.name}}">
</vn-label-value>
<vn-label-value label="Ticket" ui-sref="ticket.card.summary({id: $ctrl.claim.ticketFk})" class="link"
<vn-label-value label="Agency"
value="{{$ctrl.claim.ticket.agencyMode.name}}">
</vn-label-value>
<vn-label-value label="Ticket"
value="{{$ctrl.claim.ticketFk}}">
</vn-label-value>
</div>

View File

@ -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'
}
};
}

View File

@ -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

View File

@ -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!'))
);
}

View File

@ -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();
});

View File

@ -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');

View File

@ -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();

View File

@ -5,8 +5,7 @@ vn-client-sample-create {
}
tpl-body {
min-width: 800px;
max-height: 700px;
min-width: 800px
}
}
}

View File

@ -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']
}
}
]

View File

@ -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,

View File

@ -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(),

View File

@ -4,46 +4,45 @@ module.exports = Self => {
Self.remoteMethodCtx('changeState', {
description: 'Change the state of a ticket',
accessType: 'WRITE',
accepts: [{
arg: 'params',
type: 'object',
required: true,
description: 'ticketFk, stateFk',
http: {source: 'body'}
}],
accepts: [
{
arg: 'data',
description: 'Model instance data',
type: 'Object',
required: true,
http: {source: 'body'}
}
],
returns: {
type: 'string',
root: true
},
http: {
path: `/changeState`,
verb: 'post'
verb: 'POST'
}
});
Self.changeState = async(ctx, params) => {
Self.changeState = async(ctx, data) => {
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 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 isEditable = await models.Ticket.isEditable(data.ticketFk);
let assignedState = await models.State.findOne({where: {code: 'PICKER_DESIGNED'}});
let isAssigned = assignedState.id === data.stateFk;
if ((!isEditable && !isProduction) || (isEditable && !isAssigned && isSalesperson) || (!isSalesperson && !isProduction))
throw new UserError(`You don't have enough privileges to change the state of this ticket`);
let isProduction = await models.Account.hasRole(userId, 'production');
let isSalesPerson = await models.Account.hasRole(userId, 'salesPerson');
let isAllowed = isProduction || isSalesPerson && isEditable && isAssigned;
if (!isAllowed)
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
if (!isAssigned) {
let worker = await models.Worker.findOne({where: {userFk: currentUserId}});
params.workerFk = worker.id;
let worker = await models.Worker.findOne({where: {userFk: userId}});
data.workerFk = worker.id;
}
return await Self.app.models.TicketTracking.create(params);
return await models.TicketTracking.create(data);
};
};

View File

@ -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() => {

View File

@ -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'});

View File

@ -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)

View File

@ -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,

View File

@ -1 +1,20 @@
{}
{
"Worker": {
"dataSource": "vn"
},
"WorkerMana": {
"dataSource": "vn"
},
"WorkerTeam": {
"dataSource": "vn"
},
"WorkerTeamCollegues": {
"dataSource": "vn"
},
"WorkerMedia": {
"dataSource": "vn"
},
"WorkerDepartment": {
"dataSource": "vn"
}
}

View File

@ -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"
}
}
}

View File

@ -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"
}
}
}

View File

@ -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"
}
}
}

View File

@ -21,6 +21,9 @@
"type": "string",
"required": true
},
"phone": {
"type" : "String"
},
"userFk": {
"type" : "Number",
"required": true
@ -32,6 +35,21 @@
"model": "Account",
"foreignKey": "userFk"
},
"client": {
"type": "belongsTo",
"model": "Client",
"foreignKey": "userFk"
},
"sip": {
"type": "belongsTo",
"model": "Sip",
"foreignKey": "userFk"
},
"department": {
"type": "belongsTo",
"model": "WorkerDepartment",
"foreignKey": "id"
},
"collegues": {
"type": "hasMany",
"model": "WorkerTeamCollegues",

View File

@ -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;
});
}

View File

@ -9,13 +9,39 @@
<span></span>
</vn-horizontal>
<div class="body">
<vn-one>
<div class="attributes">
<h5>{{::$ctrl.worker.firstName}} {{::$ctrl.worker.name}}</h5>
<vn-label-value label="Id"
value="{{$ctrl.worker.id}}">
value="{{::$ctrl.worker.id}}">
</vn-label-value>
<vn-label-value label="Name"
value="{{$ctrl.worker.name}}">
<vn-label-value label="User"
value="{{::$ctrl.worker.user.name}}">
</vn-label-value>
</vn-one>
<vn-label-value label="Email"
value="{{::$ctrl.worker.user.email}}">
</vn-label-value>
<vn-label-value label="Fiscal identifier"
value="{{::$ctrl.worker.client.fi}}">
</vn-label-value>
<vn-label-value label="Department"
value="{{::$ctrl.worker.department.department}}">
</vn-label-value>
<vn-label-value label="Phone"
value="{{::$ctrl.worker.phone}}">
</vn-label-value>
<vn-label-value label="Extension"
value="{{::$ctrl.worker.sip.phone}}">
</vn-label-value>
</div>
<div class="quicklinks">
<a
ui-sref="client.card.summary({id: $ctrl.worker.userFk})"
vn-tooltip="Go to client">
<vn-icon
class="mdl-button mdl-js-button mdl-button--colored"
icon="person">
</vn-icon>
</a>
</div>
</div>
</div>

View File

@ -1,10 +1,10 @@
<vn-crud-model
vn-id="model"
url="/agency/api/Workers"
filter="::$ctrl.filter"
include="::$ctrl.include"
limit="20"
data="workers"
auto-load="true">
auto-load="false">
</vn-crud-model>
<div class="index-block">
<div class="vn-list">
@ -18,17 +18,26 @@
</vn-card>
<vn-card margin-medium-v>
<a ng-repeat="worker in workers track by worker.id"
ui-sref="worker.card.summary({ id: {{::worker.id}} })"
ui-sref="worker.card.summary({id: worker.id})"
translate-attr="{title: 'View worker'}"
class="vn-list-item">
<vn-horizontal ng-click="$ctrl.onClick($event)">
<vn-one>
<h6>{{::$ctrl.worker.name}}</h6>
<h6>{{::worker.firstName}} {{::worker.name}}</h6>
<vn-label-value label="Id"
value="{{::worker.id}}">
</vn-label-value>
<vn-label-value label="Name"
value="{{::worker.name}}">
<vn-label-value label="User"
value="{{::worker.user.name}}">
</vn-label-value>
<vn-label-value label="Email"
value="{{::worker.user.email}}">
</vn-label-value>
<vn-label-value label="Fiscal identifier"
value="{{::worker.client.fi}}">
</vn-label-value>
<vn-label-value label="Department"
value="{{::worker.department.department}}">
</vn-label-value>
</vn-one>
<vn-horizontal class="buttons">

View File

@ -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};

View File

@ -17,6 +17,13 @@
<vn-textfield
vn-one
label="Name"
model="filter.firstName">
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield
vn-one
label="Last name"
model="filter.name">
</vn-textfield>
</vn-horizontal>

View File

@ -1,15 +1,38 @@
<vn-card class="summary">
<h5>{{worker.name}}</h5>
<vn-vertical pad-medium>
<vn-horizontal pad-medium>
<vn-one>
<vn-label-value label="Id"
value="{{worker.id}}">
</vn-label-value>
<vn-label-value label="Name"
value="{{worker.name}}">
</vn-label-value>
</vn-one>
</vn-horizontal>
</vn-vertical>
<h5>{{worker.firstName}} {{worker.name}}</h5>
<vn-horizontal pad-medium>
<vn-one>
<h4 translate>Basic data</h4>
<vn-label-value label="Id"
value="{{worker.id}}">
</vn-label-value>
<vn-label-value label="Fiscal identifier"
value="{{worker.client.fi}}">
</vn-label-value>
<vn-label-value label="Email"
value="{{worker.user.email}}">
</vn-label-value>
<vn-label-value label="Department"
value="{{worker.department.department}}">
</vn-label-value>
<vn-label-value label="Phone"
value="{{worker.phone}}">
</vn-label-value>
</vn-one>
<vn-one>
<h4 translate>User info</h4>
<vn-label-value label="User id"
value="{{worker.userFk}}">
</vn-label-value>
<vn-label-value label="User"
value="{{worker.user.name}}">
</vn-label-value>
<vn-label-value label="Role"
value="{{worker.user.role.name}}">
</vn-label-value>
<vn-label-value label="Extension"
value="{{worker.sip.phone}}">
</vn-label-value>
</vn-one>
</vn-horizontal>
</vn-card>

View File

@ -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;
});
}
}

View File

@ -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',