send message
This commit is contained in:
parent
d8f4e0489e
commit
c5363155c4
|
@ -48,7 +48,7 @@ export default class ProductionActions {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_sendMessage(tickets) {
|
_sendMessage(tickets) {
|
||||||
this.$http.post(`/production/api/TicketStates/messageSend`, {tickets: tickets}).then(
|
this.$http.post(`/production/api/FakeProductions/messageSend`, {tickets: tickets}).then(
|
||||||
() => {
|
() => {
|
||||||
this.vnApp.showMessage(this.$translate.instant('Success: message send!'));
|
this.vnApp.showMessage(this.$translate.instant('Success: message send!'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "Number",
|
"type": "Number",
|
||||||
"forceId": false
|
"forceId": false
|
||||||
|
},
|
||||||
|
"username":{
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
var uuid = require('uuid');
|
||||||
module.exports = function(FakeProduction) {
|
module.exports = function(FakeProduction) {
|
||||||
FakeProduction.remoteMethodCtx('messageSend', {
|
FakeProduction.remoteMethodCtx('messageSend', {
|
||||||
description: 'Send message to salesPerson of one array of tickets',
|
description: 'Send message to salesPerson of one array of tickets',
|
||||||
|
@ -6,26 +7,65 @@ module.exports = function(FakeProduction) {
|
||||||
type: 'message'
|
type: 'message'
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: '/messageSend'
|
path: '/messageSend',
|
||||||
|
verb: 'post'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
FakeProduction.messageSend = function(ctx, cb) {
|
FakeProduction.messageSend = function(ctx, cb) {
|
||||||
var tickets = ctx.req.body.tickets;
|
var tickets = ctx.req.body.tickets;
|
||||||
|
var userId = ctx.req.accessToken.$userId;
|
||||||
|
var User = FakeProduction.app.models.User;
|
||||||
|
|
||||||
|
User.findById(userId, function (err, user) {
|
||||||
var elements = [];
|
var elements = [];
|
||||||
tickets.forEach(function(t) {
|
tickets.forEach(function(t) {
|
||||||
elements.push({salesPerson: 'nelo', message: `Revisa el tickete ${t.ticketFk}`});
|
elements.push({sender: user.username, salesPerson: t.salesPerson, message: `Revisa el tickete ${t.ticketFk}`});
|
||||||
}, this);
|
}, this);
|
||||||
messageSend(elements, cb);
|
messageSend(elements, cb);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var messageSend = function(elements, cb){
|
var messageSend = function(elements, cb){
|
||||||
|
var messages = [];
|
||||||
|
var messagesInbox = [];
|
||||||
elements.forEach(function(e) {
|
elements.forEach(function(e) {
|
||||||
var query = `select messageSend(?, ?)`;
|
var id = uuid.v1();
|
||||||
var params = [e.salesPerson, e.message];
|
var message = {uuid: id, sender: e.username, recipient: e.salesPerson, message: e.message};
|
||||||
FakeProduction.rawSql(query, params, cb);
|
var messageInbox = {uuid: id, sender: e.username, recipient: e.salesPerson, finalRecipient: e.salesPerson, message: e.message};
|
||||||
|
messages.push(message);
|
||||||
|
messagesInbox.push(messageInbox);
|
||||||
}, this);
|
}, this);
|
||||||
|
createMessage(messages, messagesInbox, cb);
|
||||||
|
}
|
||||||
|
|
||||||
cb(null, "Mensaje enviado");
|
var createMessage = function(messages, messagesInbox, cb) {
|
||||||
|
var Message = FakeProduction.app.models.Message;
|
||||||
|
FakeProduction.beginTransaction({isolationLevel: FakeProduction.Transaction.READ_COMMITTED}, function(err, tx) {
|
||||||
|
Message.create(messages, {transaction: tx}, function (err, res) {
|
||||||
|
if(err){
|
||||||
|
transaction.rollback(function(error) {
|
||||||
|
(error) ? cb(error, null) : cb(err, null);
|
||||||
|
});
|
||||||
|
} else{
|
||||||
|
createMessageInbox(messagesInbox, tx, cb);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var createMessageInbox = function(messagesInbox, tx, cb) {
|
||||||
|
var MessageInbox = FakeProduction.app.models.MessageInbox;
|
||||||
|
MessageInbox.create(messagesInbox, {transaction: tx}, function (err, res) {
|
||||||
|
if(err){
|
||||||
|
tx.rollback(function(error) {
|
||||||
|
(error) ? cb(error, null) : cb(err, null);
|
||||||
|
});
|
||||||
|
} else{
|
||||||
|
tx.commit(function(err) {
|
||||||
|
(err) ? cb(err, null) : cb(null, res);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -34,5 +34,6 @@ module.exports = function(Ticket) {
|
||||||
cb(null, response);
|
cb(null, response);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
{
|
||||||
|
"name": "MessageInbox",
|
||||||
|
"base": "MyModel",
|
||||||
|
"validateUpsert": true,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "Number",
|
||||||
|
"id": true,
|
||||||
|
"description": "Identifier"
|
||||||
|
},
|
||||||
|
"uuid":{
|
||||||
|
"type": "String"
|
||||||
|
},
|
||||||
|
"sender":{
|
||||||
|
"type": "String"
|
||||||
|
},
|
||||||
|
"recipient":{
|
||||||
|
"type": "String"
|
||||||
|
},
|
||||||
|
"finalRecipient":{
|
||||||
|
"type": "String"
|
||||||
|
},
|
||||||
|
"message":{
|
||||||
|
"type": "String"
|
||||||
|
},
|
||||||
|
"sendDate":{
|
||||||
|
"type": "date"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"acls": [
|
||||||
|
{
|
||||||
|
"accessType": "*",
|
||||||
|
"principalType": "ROLE",
|
||||||
|
"principalId": "$everyone",
|
||||||
|
"permission": "DENY"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"accessType": "*",
|
||||||
|
"principalType": "ROLE",
|
||||||
|
"principalId": "root",
|
||||||
|
"permission": "ALLOW"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
"name": "Message",
|
||||||
|
"base": "MyModel",
|
||||||
|
"validateUpsert": true,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "Number",
|
||||||
|
"id": true,
|
||||||
|
"description": "Identifier"
|
||||||
|
},
|
||||||
|
"uuid":{
|
||||||
|
"type": "String"
|
||||||
|
},
|
||||||
|
"sender":{
|
||||||
|
"type": "String"
|
||||||
|
},
|
||||||
|
"recipient":{
|
||||||
|
"type": "String"
|
||||||
|
},
|
||||||
|
"message":{
|
||||||
|
"type": "String"
|
||||||
|
},
|
||||||
|
"sendDate":{
|
||||||
|
"type": "date"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"acls": [
|
||||||
|
{
|
||||||
|
"accessType": "*",
|
||||||
|
"principalType": "ROLE",
|
||||||
|
"principalId": "$everyone",
|
||||||
|
"permission": "DENY"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"accessType": "*",
|
||||||
|
"principalType": "ROLE",
|
||||||
|
"principalId": "root",
|
||||||
|
"permission": "ALLOW"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -6,6 +6,9 @@
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "Number",
|
"type": "Number",
|
||||||
"forceId": false
|
"forceId": false
|
||||||
|
},
|
||||||
|
"username":{
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -76,5 +76,14 @@
|
||||||
"FakeProduction": {
|
"FakeProduction": {
|
||||||
"dataSource": "vn",
|
"dataSource": "vn",
|
||||||
"public": true
|
"public": true
|
||||||
|
},
|
||||||
|
"Message": {
|
||||||
|
"dataSource": "vn",
|
||||||
|
"public": true
|
||||||
|
},
|
||||||
|
"MessageInbox": {
|
||||||
|
"dataSource": "vn",
|
||||||
|
"public": true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "Number",
|
"type": "Number",
|
||||||
"forceId": false
|
"forceId": false
|
||||||
|
},
|
||||||
|
"username":{
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue