+ order="shipped ASC, isOk ASC">
+ on-response="$ctrl.denyRequest(response)">
-
+ Specify the reasons to deny this request
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/modules/item/front/request/index.js b/modules/item/front/request/index.js
index f887be9a8..c18800001 100644
--- a/modules/item/front/request/index.js
+++ b/modules/item/front/request/index.js
@@ -9,8 +9,23 @@ export default class Controller {
this.$ = $;
this.vnApp = vnApp;
this._ = $translate;
- if (!$stateParams.q)
- this.filter = {isOk: false, mine: true};
+ if (!$stateParams.q) {
+ const today = new Date();
+ today.setHours(23, 59, 59, 59);
+
+ const lastWeek = new Date();
+ lastWeek.setHours(0, 0, 0, 0);
+ lastWeek.setDate(lastWeek.getDate() - 7);
+
+ this.filter = {
+ where: {
+ isOk: false,
+ mine: true,
+ from: lastWeek,
+ to: today
+ }
+ };
+ }
}
$postLink() {
@@ -21,7 +36,7 @@ export default class Controller {
getState(isOk) {
if (isOk === null)
return 'Nueva';
- else if (isOk === -1 || isOk === 1)
+ else if (isOk === -1 || isOk)
return 'Aceptada';
else
return 'Denegada';
@@ -34,14 +49,12 @@ export default class Controller {
quantity: request.saleQuantity
};
- let endpoint = `/api/TicketRequests/${request.id}/confirm`;
+ let query = `/api/TicketRequests/${request.id}/confirm`;
+ this.$http.post(query, params).then(res => {
+ request.itemDescription = res.data.concept;
+ request.isOk = true;
- this.$http.post(endpoint, params).then(() => {
this.vnApp.showSuccess(this._.instant('Data saved!'));
- this.$.model.refresh();
- }).catch( e => {
- this.$.model.refresh();
- throw e;
});
}
}
@@ -56,10 +69,7 @@ export default class Controller {
this.$http.patch(endpoint, params).then(() => {
this.vnApp.showSuccess(this._.instant('Data saved!'));
- }).catch( e => {
- this.$.model.refresh();
- throw e;
- });
+ }).then(() => this.confirmRequest(request));
} else
this.confirmRequest(request);
}
@@ -86,7 +96,7 @@ export default class Controller {
}
showDenyReason(event, requestId) {
- this.denyRequestId = requestId;
+ this.selectedRequest = requestId;
this.$.denyReason.parent = event.target;
this.$.denyReason.show();
document.querySelector('vn-item-request vn-textarea textArea').focus();
@@ -96,17 +106,21 @@ export default class Controller {
delete this.denyRequestId;
}
- denyRequest() {
+ denyRequest(response) {
+ if (response !== 'ACCEPT') return;
+
let params = {
observation: this.denyObservation
};
- let endpoint = `/api/TicketRequests/${this.denyRequestId}/deny`;
+ let query = `/api/TicketRequests/${this.selectedRequest.id}/deny`;
+ this.$http.post(query, params).then(res => {
+ const request = res.data;
+ this.selectedRequest.isOk = request.isOk;
+ this.selectedRequest.attenderFk = request.attenderFk;
+ this.selectedRequest.response = request.response;
- this.$http.post(endpoint, params).then(() => {
this.vnApp.showSuccess(this._.instant('Data saved!'));
- this.$.model.refresh();
- this.$.denyReason.hide();
this.denyObservation = null;
});
}
diff --git a/modules/item/front/request/index.spec.js b/modules/item/front/request/index.spec.js
index e27bc3879..1704c61a1 100644
--- a/modules/item/front/request/index.spec.js
+++ b/modules/item/front/request/index.spec.js
@@ -53,15 +53,15 @@ describe('Item', () => {
let model = controller.$.model;
spyOn(model, 'refresh');
+ const expectedResult = {concept: 'Melee Weapon'};
let request = {itemFk: 1, saleQuantity: 1, id: 1};
- $httpBackend.when('POST', `/api/TicketRequests/${request.id}/confirm`).respond();
- $httpBackend.expect('POST', `/api/TicketRequests/${request.id}/confirm`).respond();
+ $httpBackend.when('POST', `/api/TicketRequests/${request.id}/confirm`).respond(expectedResult);
+ $httpBackend.expect('POST', `/api/TicketRequests/${request.id}/confirm`).respond(expectedResult);
controller.confirmRequest(request);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
- expect($scope.model.refresh).toHaveBeenCalledWith();
});
});
@@ -110,20 +110,17 @@ describe('Item', () => {
describe('denyRequest()', () => {
it(`should perform a query and call vnApp.showSuccess(), refresh(), hide() and set denyObservation to null in the controller`, () => {
spyOn(controller.vnApp, 'showSuccess');
- let model = controller.$.model;
- spyOn(model, 'refresh');
- spyOn(controller.$.denyReason, 'hide');
- controller.denyRequestId = 1;
+ const request = {id: 1};
+ const expectedResult = {isOk: false, attenderFk: 106, response: 'Denied!'};
+ controller.selectedRequest = request;
- $httpBackend.when('POST', `/api/TicketRequests/${controller.denyRequestId}/deny`).respond();
- $httpBackend.expect('POST', `/api/TicketRequests/${controller.denyRequestId}/deny`).respond();
- controller.denyRequest();
+ $httpBackend.when('POST', `/api/TicketRequests/${request.id}/deny`).respond(expectedResult);
+ $httpBackend.expect('POST', `/api/TicketRequests/${request.id}/deny`).respond(expectedResult);
+ controller.denyRequest('ACCEPT');
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
- expect($scope.model.refresh).toHaveBeenCalledWith();
- expect($scope.denyReason.hide).toHaveBeenCalledWith();
});
});
});
diff --git a/modules/item/front/request/locale/es.yml b/modules/item/front/request/locale/es.yml
index 760f30bd3..33710a327 100644
--- a/modules/item/front/request/locale/es.yml
+++ b/modules/item/front/request/locale/es.yml
@@ -1,5 +1,6 @@
Discard: Descartar
-Indicate the reasons to deny this request: Indique las razones para descartar esta peticion
+Specify the reasons to deny this request: Especifica las razones para descartar la peticiĆ³n
Buy requests: Peticiones de compra
Search request by id or alias: Buscar peticiones por identificador o alias
-Sale quantity: C. conseguida
\ No newline at end of file
+Requested: Solicitado
+Achieved: Conseguido
\ No newline at end of file
diff --git a/modules/ticket/back/methods/ticket-request/confirm.js b/modules/ticket/back/methods/ticket-request/confirm.js
index 92dd06dae..53fb2527c 100644
--- a/modules/ticket/back/methods/ticket-request/confirm.js
+++ b/modules/ticket/back/methods/ticket-request/confirm.js
@@ -38,27 +38,27 @@ module.exports = Self => {
try {
let options = {transaction: tx};
- let item = await models.Item.findById(ctx.args.itemFk);
+ let item = await models.Item.findById(ctx.args.itemFk, null, options);
if (!item)
throw new UserError(`That item doesn't exists`);
let request = await models.TicketRequest.findById(ctx.args.id, {
include: {relation: 'ticket'}
- });
+ }, options);
let [[stock]] = await Self.rawSql(`CALL vn.getItemVisibleAvailable(?,?,?,?)`, [
ctx.args.itemFk,
request.ticket().shipped,
request.ticket().warehouseFk,
false
- ]);
+ ], options);
if (stock.available < 0)
throw new UserError(`This item is not available`);
if (request.saleFk) {
- sale = await models.Sale.findById(request.saleFk);
+ sale = await models.Sale.findById(request.saleFk, null, options);
sale.updateAttributes({
itemFk: ctx.args.itemFk,
quantity: ctx.args.quantity,
@@ -71,7 +71,11 @@ module.exports = Self => {
quantity: ctx.args.quantity,
concept: item.name
}, options);
- request.updateAttributes({saleFk: sale.id, itemFk: sale.itemFk, isOk: true}, options);
+ request.updateAttributes({
+ saleFk: sale.id,
+ itemFk: sale.itemFk,
+ isOk: true
+ }, options);
}
query = `CALL vn.ticketCalculateSale(?)`;
@@ -86,6 +90,8 @@ module.exports = Self => {
}, options);
await tx.commit();
+
+ return sale;
} catch (error) {
await tx.rollback();
throw error;
diff --git a/modules/ticket/back/methods/ticket-request/deny.js b/modules/ticket/back/methods/ticket-request/deny.js
index 817c90782..e663ef1bc 100644
--- a/modules/ticket/back/methods/ticket-request/deny.js
+++ b/modules/ticket/back/methods/ticket-request/deny.js
@@ -29,7 +29,7 @@ module.exports = Self => {
let params = {
isOk: false,
- atenderFk: worker.id,
+ attenderFk: worker.id,
response: ctx.args.observation,
};
diff --git a/modules/ticket/back/methods/ticket-request/filter.js b/modules/ticket/back/methods/ticket-request/filter.js
index 40c1f7652..82e1ee8e0 100644
--- a/modules/ticket/back/methods/ticket-request/filter.js
+++ b/modules/ticket/back/methods/ticket-request/filter.js
@@ -28,7 +28,7 @@ module.exports = Self => {
type: 'Number',
description: `Search by warehouse`
}, {
- arg: 'atenderFk',
+ arg: 'attenderFk',
type: 'Number',
description: `Search requests atended by the given worker`
}, {
@@ -65,7 +65,7 @@ module.exports = Self => {
let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}});
if (ctx.args.mine)
- ctx.args.atenderFk = worker.id;
+ ctx.args.attenderFk = worker.id;
let where = buildFilter(ctx.args, (param, value) => {
switch (param) {
@@ -75,7 +75,7 @@ module.exports = Self => {
: {'t.nickname': {like: `%${value}%`}};
case 'ticketFk':
return {'t.id': value};
- case 'atenderFk':
+ case 'attenderFk':
return {'tr.atenderFk': value};
case 'isOk':
return {'tr.isOk': value};
@@ -106,13 +106,13 @@ module.exports = Self => {
tr.ticketFk,
tr.quantity,
tr.price,
- tr.atenderFk,
+ tr.atenderFk attenderFk,
tr.description,
tr.response,
tr.saleFk,
tr.isOk,
s.quantity AS saleQuantity,
- s.itemFK,
+ s.itemFk,
i.name AS itemDescription,
t.shipped,
t.nickname,
diff --git a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js
index 574469d86..2383fe560 100644
--- a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js
+++ b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js
@@ -1,27 +1,14 @@
const app = require('vn-loopback/server/server');
describe('ticket-request confirm()', () => {
- let request;
- let sale;
+ let originalRequest;
+ let originalSale;
let createdSaleId;
afterAll(async done => {
- const paramsForRequest = {
- saleFk: request.saleFk,
- isOk: request.isOk,
- itemFk: request.itemFk,
- ticketFk: request.ticketFk
- };
-
- const paramsForSale = {
- itemFk: sale.itemFk,
- quantity: sale.quantity,
- concept: sale.concept,
- };
-
- await request.updateAttributes(paramsForRequest);
- await sale.updateAttributes(paramsForSale);
- app.models.Sale.destroyById(createdSaleId);
+ await originalRequest.updateAttributes(originalRequest);
+ await originalSale.updateAttributes(originalSale);
+ await app.models.Sale.destroyById(createdSaleId);
done();
});
@@ -65,10 +52,11 @@ describe('ticket-request confirm()', () => {
const itemId = 1;
const quantity = 10;
- request = await app.models.TicketRequest.findById(requestId);
- sale = await app.models.Sale.findById(saleId);
+ originalRequest = await app.models.TicketRequest.findById(requestId);
+ originalSale = await app.models.Sale.findById(saleId);
- request.updateAttributes({saleFk: saleId});
+ const request = await app.models.TicketRequest.findById(requestId);
+ await request.updateAttributes({saleFk: saleId});
let ctx = {req: {accessToken: {userId: 9}}, args: {
itemFk: itemId,
@@ -89,7 +77,8 @@ describe('ticket-request confirm()', () => {
const itemId = 1;
const quantity = 10;
- request.updateAttributes({saleFk: null});
+ const request = await app.models.TicketRequest.findById(requestId);
+ await request.updateAttributes({saleFk: null});
let ctx = {req: {accessToken: {userId: 9}}, args: {
itemFk: itemId,
diff --git a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js
index cac63586e..04152fa21 100644
--- a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js
+++ b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js
@@ -5,7 +5,7 @@ describe('ticket-request deny()', () => {
afterAll(async done => {
let params = {
isOk: null,
- atenderFk: request.atenderFk,
+ attenderFk: request.attenderFk,
response: null,
};
diff --git a/modules/ticket/back/methods/ticket-request/specs/filter.spec.js b/modules/ticket/back/methods/ticket-request/specs/filter.spec.js
index 24e74e4df..329688866 100644
--- a/modules/ticket/back/methods/ticket-request/specs/filter.spec.js
+++ b/modules/ticket/back/methods/ticket-request/specs/filter.spec.js
@@ -37,7 +37,7 @@ describe('ticket-request filter()', () => {
});
it('should return the ticket request matching the atender ID', async() => {
- let ctx = {req: {accessToken: {userId: 9}}, args: {atenderFk: 35}};
+ let ctx = {req: {accessToken: {userId: 9}}, args: {attenderFk: 35}};
let result = await app.models.TicketRequest.filter(ctx);
let requestId = result[0].id;
diff --git a/modules/ticket/back/models/ticket-request.json b/modules/ticket/back/models/ticket-request.json
index dfb609e3c..7f1cb4b02 100644
--- a/modules/ticket/back/models/ticket-request.json
+++ b/modules/ticket/back/models/ticket-request.json
@@ -33,9 +33,12 @@
"isOk": {
"type": "Boolean"
},
- "atenderFk": {
+ "attenderFk": {
"type": "Number",
- "required": true
+ "required": true,
+ "mysql": {
+ "columnName": "atenderFk"
+ }
},
"response": {
"type": "String"
@@ -55,7 +58,7 @@
"atender": {
"type": "belongsTo",
"model": "Worker",
- "foreignKey": "atenderFk"
+ "foreignKey": "attenderFk"
},
"requester": {
"type": "belongsTo",
diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js
index a33e57e14..05b4e719a 100644
--- a/modules/ticket/front/descriptor/index.js
+++ b/modules/ticket/front/descriptor/index.js
@@ -176,7 +176,7 @@ class Controller {
links.btnTwo = {
icon: 'icon-stowaway',
state: `ticket.card.summary({id: ${value.stowaway.shipFk}})`,
- tooltip: 'Ship'
+ tooltip: 'Ship stowaways'
};
}
diff --git a/modules/ticket/front/request/create/index.html b/modules/ticket/front/request/create/index.html
index 1b7044c20..dd10d8afe 100644
--- a/modules/ticket/front/request/create/index.html
+++ b/modules/ticket/front/request/create/index.html
@@ -18,7 +18,7 @@
+ ng-click="$ctrl.showWorkerDescriptor($event, request.attenderFk)">
{{::request.atender.user.nickname | dashIfEmpty}}