Merge branch '1878-print_with_auth' of verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
97671fd4a1
|
@ -108,7 +108,10 @@ function runFn(
|
|||
$filter,
|
||||
$interpolate,
|
||||
$window,
|
||||
vnApp) {
|
||||
vnApp,
|
||||
vnToken,
|
||||
vnConfig,
|
||||
aclService) {
|
||||
Object.assign(Component.prototype, {
|
||||
$translate,
|
||||
$q,
|
||||
|
@ -121,7 +124,10 @@ function runFn(
|
|||
$filter,
|
||||
$interpolate,
|
||||
$window,
|
||||
vnApp
|
||||
vnApp,
|
||||
vnToken,
|
||||
vnConfig,
|
||||
aclService
|
||||
});
|
||||
}
|
||||
runFn.$inject = [
|
||||
|
@ -136,7 +142,10 @@ runFn.$inject = [
|
|||
'$filter',
|
||||
'$interpolate',
|
||||
'$window',
|
||||
'vnApp'
|
||||
'vnApp',
|
||||
'vnToken',
|
||||
'vnConfig',
|
||||
'aclService'
|
||||
];
|
||||
|
||||
ngModule.run(runFn);
|
||||
|
|
|
@ -155,7 +155,6 @@ class Controller {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
onUpdateGreugeResponse(response) {
|
||||
if (response == 'accept') {
|
||||
const promises = [];
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
import ngModule from '../module';
|
||||
import Component from 'core/lib/component';
|
||||
|
||||
class Controller {
|
||||
constructor($scope, $state, $http, $translate, vnApp, aclService, $httpParamSerializer) {
|
||||
this.$scope = $scope;
|
||||
this.$state = $state;
|
||||
this.$http = $http;
|
||||
this.$translate = $translate;
|
||||
this.vnApp = vnApp;
|
||||
this.aclService = aclService;
|
||||
class Controller extends Component {
|
||||
constructor($element, $scope, $httpParamSerializer) {
|
||||
super($element, $scope);
|
||||
this.$httpParamSerializer = $httpParamSerializer;
|
||||
|
||||
this.moreOptions = [
|
||||
{callback: this.showPickupOrder, name: 'Show Pickup order'},
|
||||
{callback: this.confirmPickupOrder, name: 'Send Pickup order'},
|
||||
|
@ -22,7 +19,7 @@ class Controller {
|
|||
|
||||
return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl]));
|
||||
});
|
||||
this.$scope.moreButton.data = options;
|
||||
this.$.moreButton.data = options;
|
||||
}
|
||||
|
||||
onMoreChange(callback) {
|
||||
|
@ -63,7 +60,8 @@ class Controller {
|
|||
showPickupOrder() {
|
||||
const params = {
|
||||
clientId: this.claim.clientFk,
|
||||
claimId: this.claim.id
|
||||
claimId: this.claim.id,
|
||||
authorization: this.vnToken.token
|
||||
};
|
||||
const serializedParams = this.$httpParamSerializer(params);
|
||||
let url = `api/report/claim-pickup-order?${serializedParams}`;
|
||||
|
@ -71,7 +69,7 @@ class Controller {
|
|||
}
|
||||
|
||||
confirmPickupOrder() {
|
||||
this.$scope.confirmPickupOrder.show();
|
||||
this.$.confirmPickupOrder.show();
|
||||
}
|
||||
|
||||
sendPickupOrder(response) {
|
||||
|
@ -81,16 +79,14 @@ class Controller {
|
|||
clientId: this.claim.clientFk,
|
||||
claimId: this.claim.id
|
||||
};
|
||||
const serializedParams = this.$httpParamSerializer(params);
|
||||
const url = `email/claim-pickup-order?${serializedParams}`;
|
||||
this.$http.get(url).then(
|
||||
this.$http.get(`email/claim-pickup-order`, {params}).then(
|
||||
() => this.vnApp.showMessage(this.$translate.instant('Notification sent!'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
confirmDeleteClaim() {
|
||||
this.$scope.confirmDeleteClaim.show();
|
||||
this.$.confirmDeleteClaim.show();
|
||||
}
|
||||
|
||||
deleteClaim(response) {
|
||||
|
@ -103,7 +99,7 @@ class Controller {
|
|||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$scope', '$state', '$http', '$translate', 'vnApp', 'aclService', '$httpParamSerializer'];
|
||||
Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
|
||||
|
||||
ngModule.component('vnClaimDescriptor', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -3,14 +3,19 @@ import './index.js';
|
|||
describe('Item Component vnClaimDescriptor', () => {
|
||||
let $httpParamSerializer;
|
||||
let $httpBackend;
|
||||
let $element;
|
||||
let $scope;
|
||||
let controller;
|
||||
|
||||
beforeEach(ngModule('claim'));
|
||||
|
||||
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
|
||||
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
controller = $componentController('vnClaimDescriptor');
|
||||
$scope = $rootScope.$new();
|
||||
|
||||
$element = angular.element('<vn-claim-descriptor></vn-claim-descriptor>');
|
||||
controller = $componentController('vnClaimDescriptor', {$element, $scope});
|
||||
controller.claim = {id: 2, clientFk: 101, client: {email: 'client@email'}};
|
||||
}));
|
||||
|
||||
|
@ -31,13 +36,13 @@ describe('Item Component vnClaimDescriptor', () => {
|
|||
|
||||
describe('confirmPickupOrder()', () => {
|
||||
it('should call confirmPickupOrder.show()', () => {
|
||||
controller.$scope.confirmPickupOrder = {
|
||||
controller.$.confirmPickupOrder = {
|
||||
show: jasmine.createSpy('show')
|
||||
};
|
||||
controller.claim = {id: 2};
|
||||
controller.confirmPickupOrder();
|
||||
|
||||
expect(controller.$scope.confirmPickupOrder.show).toHaveBeenCalledWith();
|
||||
expect(controller.$.confirmPickupOrder.show).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -63,13 +68,13 @@ describe('Item Component vnClaimDescriptor', () => {
|
|||
|
||||
describe('confirmDeleteClaim()', () => {
|
||||
it('should call confirmDeleteClaim.show()', () => {
|
||||
controller.$scope.confirmDeleteClaim = {
|
||||
controller.$.confirmDeleteClaim = {
|
||||
show: jasmine.createSpy('show')
|
||||
};
|
||||
controller.claim = {id: 2};
|
||||
controller.confirmDeleteClaim();
|
||||
|
||||
expect(controller.$scope.confirmDeleteClaim.show).toHaveBeenCalledWith();
|
||||
expect(controller.$.confirmDeleteClaim.show).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -191,7 +191,6 @@ module.exports = Self => {
|
|||
if (socialNameChanged && !isAlpha(changes.socialName))
|
||||
throw new UserError('The socialName has an invalid format');
|
||||
|
||||
|
||||
if (changes.salesPerson === null) {
|
||||
changes.credit = 0;
|
||||
changes.discount = 0;
|
||||
|
@ -238,7 +237,9 @@ module.exports = Self => {
|
|||
const httpCtx = {req: loopBackContext.active};
|
||||
const httpRequest = httpCtx.req.http.req;
|
||||
const $t = httpRequest.__;
|
||||
const origin = httpRequest.headers.origin;
|
||||
const headers = httpRequest.headers;
|
||||
const origin = headers.origin;
|
||||
const authorization = headers.authorization;
|
||||
|
||||
const salesPersonId = instance.salesPersonFk;
|
||||
|
||||
|
@ -254,12 +255,14 @@ module.exports = Self => {
|
|||
|
||||
// Send email to client
|
||||
if (!instance.email) return;
|
||||
const serializedParams = httpParamSerializer({
|
||||
const params = {
|
||||
authorization: authorization,
|
||||
clientId: instance.id,
|
||||
recipient: instance.email
|
||||
};
|
||||
await request.get(`${origin}/api/email/payment-update`, {
|
||||
qs: params
|
||||
});
|
||||
const query = `${origin}/api/email/payment-update?${serializedParams}`;
|
||||
await request.get(query);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ class Controller extends Component {
|
|||
constructor($element, $, $httpParamSerializer) {
|
||||
super($element, $);
|
||||
this.$httpParamSerializer = $httpParamSerializer;
|
||||
|
||||
this.moreOptions = [
|
||||
{name: 'Simple ticket', callback: this.newTicket},
|
||||
{name: 'Send SMS', callback: this.showSMSDialog},
|
||||
|
@ -72,8 +73,13 @@ class Controller extends Component {
|
|||
|
||||
sendConsumerReport(response) {
|
||||
if (response === 'accept') {
|
||||
const data = {from: this.from, to: this.to, clientId: this.client.id};
|
||||
const serializedParams = this.$httpParamSerializer(data);
|
||||
const params = {
|
||||
authorization: this.vnToken.token,
|
||||
clientId: this.client.id,
|
||||
from: this.from,
|
||||
to: this.to,
|
||||
};
|
||||
const serializedParams = this.$httpParamSerializer(params);
|
||||
const url = `api/report/campaign-metrics?${serializedParams}`;
|
||||
window.open(url);
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@ import ngModule from '../module';
|
|||
import Component from 'core/lib/component';
|
||||
|
||||
class Controller extends Component {
|
||||
constructor($element, $, $httpParamSerializer, vnConfig) {
|
||||
constructor($element, $, $httpParamSerializer) {
|
||||
super($element, $);
|
||||
this.vnConfig = vnConfig;
|
||||
this.$httpParamSerializer = $httpParamSerializer;
|
||||
|
||||
this.moreOptions = [
|
||||
{name: 'Show entry report', callback: this.showEntryReport}
|
||||
];
|
||||
|
@ -59,6 +59,7 @@ class Controller extends Component {
|
|||
|
||||
showEntryReport() {
|
||||
const params = {
|
||||
authorization: this.vnToken.token,
|
||||
clientId: this.vnConfig.storage.currentUserWorkerId,
|
||||
entryId: this.entry.id
|
||||
};
|
||||
|
@ -68,7 +69,7 @@ class Controller extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$element', '$scope', '$httpParamSerializer', 'vnConfig'];
|
||||
Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
|
||||
|
||||
ngModule.component('vnEntryDescriptor', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
import ngModule from '../module';
|
||||
import Component from 'core/lib/component';
|
||||
|
||||
class Controller extends Component {
|
||||
constructor($element, $scope, $httpParamSerializer) {
|
||||
super($element, $scope);
|
||||
|
||||
class Controller {
|
||||
constructor($, $http, vnApp, $translate, aclService, $httpParamSerializer) {
|
||||
this.$http = $http;
|
||||
this.vnApp = vnApp;
|
||||
this.$translate = $translate;
|
||||
this.$ = $;
|
||||
this.aclService = aclService;
|
||||
this.$httpParamSerializer = $httpParamSerializer;
|
||||
this.moreOptions = [
|
||||
{callback: this.showRouteReport, name: 'Show route report'},
|
||||
|
@ -39,6 +37,7 @@ class Controller {
|
|||
showRouteReport() {
|
||||
const user = this.route.worker.user;
|
||||
const params = {
|
||||
authorization: this.vnToken.token,
|
||||
clientId: user.id,
|
||||
routeId: this.route.id
|
||||
};
|
||||
|
@ -54,9 +53,7 @@ class Controller {
|
|||
clientId: user.id,
|
||||
routeId: this.route.id
|
||||
};
|
||||
const serializedParams = this.$httpParamSerializer(params);
|
||||
const url = `email/driver-route?${serializedParams}`;
|
||||
this.$http.get(url).then(() => {
|
||||
this.$http.get(`email/driver-route`, {params}).then(() => {
|
||||
this.vnApp.showSuccess(this.$translate.instant('Report sent'));
|
||||
});
|
||||
}
|
||||
|
@ -76,7 +73,7 @@ class Controller {
|
|||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate', 'aclService', '$httpParamSerializer'];
|
||||
Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
|
||||
|
||||
ngModule.component('vnRouteDescriptor', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -2,10 +2,10 @@ import ngModule from '../module';
|
|||
import Component from 'core/lib/component';
|
||||
|
||||
class Controller extends Component {
|
||||
constructor($element, $, aclService, $httpParamSerializer) {
|
||||
constructor($element, $, $httpParamSerializer) {
|
||||
super($element, $);
|
||||
this.aclService = aclService;
|
||||
this.$httpParamSerializer = $httpParamSerializer;
|
||||
|
||||
this.moreOptions = [
|
||||
{
|
||||
name: 'Add turn',
|
||||
|
@ -220,7 +220,8 @@ class Controller extends Component {
|
|||
showDeliveryNote() {
|
||||
const params = {
|
||||
clientId: this.ticket.client.id,
|
||||
ticketId: this.ticket.id
|
||||
ticketId: this.ticket.id,
|
||||
authorization: this.vnToken.token
|
||||
};
|
||||
const serializedParams = this.$httpParamSerializer(params);
|
||||
let url = `api/report/delivery-note?${serializedParams}`;
|
||||
|
@ -332,7 +333,7 @@ class Controller extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$element', '$scope', 'aclService', '$httpParamSerializer'];
|
||||
Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
|
||||
|
||||
ngModule.component('vnTicketDescriptor', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import './index.js';
|
||||
|
||||
|
||||
describe('Component vnWorkerTimeControl', () => {
|
||||
let $httpBackend;
|
||||
let $scope;
|
||||
|
@ -9,7 +8,7 @@ describe('Component vnWorkerTimeControl', () => {
|
|||
|
||||
beforeEach(ngModule('worker'));
|
||||
|
||||
beforeEach(angular.mock.inject(($componentController, $compile, $rootScope, $stateParams, _$httpBackend_) => {
|
||||
beforeEach(angular.mock.inject(($componentController, $rootScope, $stateParams, _$httpBackend_) => {
|
||||
$stateParams.id = 1;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$scope = $rootScope.$new();
|
||||
|
|
|
@ -52,5 +52,3 @@ module.exports = app => {
|
|||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ class Email extends Component {
|
|||
return `../templates/email/${this.name}`;
|
||||
}
|
||||
|
||||
|
||||
async getSubject() {
|
||||
if (!this.lang) await this.getLang();
|
||||
const locale = this.locale.messages;
|
||||
|
|
|
@ -3,3 +3,5 @@ require('./date');
|
|||
require('./uppercase');
|
||||
require('./currency');
|
||||
require('./percentage');
|
||||
require('./number');
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
const Vue = require('vue');
|
||||
const config = require('../config');
|
||||
const defaultLocale = config.i18n.locale;
|
||||
|
||||
Vue.filter('number', function(value, locale = defaultLocale) {
|
||||
if (!locale) locale = defaultLocale;
|
||||
return new Intl.NumberFormat(locale, {
|
||||
style: 'decimal'
|
||||
}).format(parseFloat(value));
|
||||
});
|
|
@ -1,6 +1,62 @@
|
|||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const db = require('./database');
|
||||
|
||||
module.exports = app => {
|
||||
// Import methods
|
||||
require('../methods/closure')(app);
|
||||
require('../methods/report')(app);
|
||||
require('../methods/email')(app);
|
||||
const methodsPath = path.resolve(__dirname, '../methods');
|
||||
const methodsDir = fs.readdirSync(methodsPath);
|
||||
const methods = [];
|
||||
|
||||
// Get all methods
|
||||
methodsDir.forEach(method => {
|
||||
methods.push(method.replace('.js', ''));
|
||||
});
|
||||
|
||||
// Auth middleware
|
||||
const paths = [];
|
||||
for (let method of methods)
|
||||
paths.push(`/api/${method}/*`);
|
||||
|
||||
app.use(paths, async function(request, response, next) {
|
||||
const authorization = getToken(request);
|
||||
const query = `SELECT userId, ttl, created
|
||||
FROM salix.AccessToken WHERE id = ?`;
|
||||
|
||||
try {
|
||||
const authToken = await db.findOne(query, [authorization]);
|
||||
|
||||
if (!authToken || isTokenExpired(authToken.created, authToken.ttl))
|
||||
throw new Error('Invalid authorization token');
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
function getToken(request) {
|
||||
const headers = request.headers;
|
||||
const params = request.query;
|
||||
|
||||
if (headers.authorization)
|
||||
params.authorization = headers.authorization;
|
||||
|
||||
return headers.authorization || params.authorization;
|
||||
}
|
||||
|
||||
function isTokenExpired(created, ttl) {
|
||||
const date = new Date(created);
|
||||
const currentDate = new Date();
|
||||
|
||||
date.setSeconds(date.getSeconds() + ttl);
|
||||
|
||||
if (currentDate > date)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Mount methods
|
||||
for (let method of methods)
|
||||
require(`../methods/${method}`)(app);
|
||||
};
|
||||
|
|
|
@ -37,6 +37,9 @@ module.exports = {
|
|||
'attachment': attachment.build()
|
||||
},
|
||||
props: {
|
||||
authorization: {
|
||||
required: true
|
||||
},
|
||||
clientId: {
|
||||
required: true
|
||||
},
|
||||
|
|
|
@ -37,11 +37,14 @@ module.exports = {
|
|||
'attachment': attachment.build()
|
||||
},
|
||||
props: {
|
||||
authorization: {
|
||||
required: true
|
||||
},
|
||||
clientId: {
|
||||
required: true
|
||||
},
|
||||
companyId: {
|
||||
required: true
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<th>{{$t('reference')}}</th>
|
||||
<th class="number">{{$t('quantity')}}</th>
|
||||
<th class="number">{{$t('claims')}}</th>
|
||||
<th>{{$t('concept')}}</th>
|
||||
<th width="50%">{{$t('concept')}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody v-for="sale in sales" v-bind:key="sale.id">
|
||||
|
@ -69,7 +69,7 @@
|
|||
<td class="font gray">{{sale.id}}</td>
|
||||
<td class="number">{{sale.quantity}}</td>
|
||||
<td class="number">{{sale.claimQuantity}}</td>
|
||||
<td>{{sale.concept}}</td>
|
||||
<td width="50%">{{sale.concept}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -63,12 +63,12 @@
|
|||
<table class="column-oriented">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{{$t('boxes')}}</td>
|
||||
<td class="number">{{$t('boxes')}}</td>
|
||||
<td class="number">{{$t('packing')}}</td>
|
||||
<td width="50%">{{$t('concept')}}</td>
|
||||
<td class="number">{{$t('quantity')}}</td>
|
||||
<td class="number">{{$t('price')}}</td>
|
||||
<td class="number">{{$t('amount')}}</td>
|
||||
<td width="10%" class="number">{{$t('quantity')}}</td>
|
||||
<td width="15%" class="number">{{$t('price')}}</td>
|
||||
<td width="15%" class="number">{{$t('amount')}}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody v-for="buy in buys">
|
||||
|
@ -76,9 +76,9 @@
|
|||
<td class="number">{{buy.box}}</td>
|
||||
<td class="number">{{buy.packing}}</td>
|
||||
<td width="50%">{{buy.itemName}}</td>
|
||||
<td class="number">{{buy.quantity}}</td>
|
||||
<td class="number">{{buy.buyingValue | currency('EUR', locale)}}</td>
|
||||
<td class="number">{{buy.buyingValue * buy.quantity | currency('EUR', locale)}}</td>
|
||||
<td width="10%" class="number">{{buy.quantity | number}}</td>
|
||||
<td width="15%" class="number">{{buy.buyingValue | currency('EUR', locale)}}</td>
|
||||
<td width="15%" class="number">{{buy.buyingValue * buy.quantity | currency('EUR', locale)}}</td>
|
||||
</tr>
|
||||
<tr class="description">
|
||||
<td colspan="2">
|
||||
|
|
Loading…
Reference in New Issue