send message
This commit is contained in:
parent
d8f4e0489e
commit
c5363155c4
|
@ -48,7 +48,7 @@ export default class ProductionActions {
|
|||
);
|
||||
}
|
||||
_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!'));
|
||||
}
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
"id": true,
|
||||
"type": "Number",
|
||||
"forceId": false
|
||||
},
|
||||
"username":{
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
var uuid = require('uuid');
|
||||
module.exports = function(FakeProduction) {
|
||||
FakeProduction.remoteMethodCtx('messageSend', {
|
||||
description: 'Send message to salesPerson of one array of tickets',
|
||||
|
@ -6,26 +7,65 @@ module.exports = function(FakeProduction) {
|
|||
type: 'message'
|
||||
},
|
||||
http: {
|
||||
path: '/messageSend'
|
||||
path: '/messageSend',
|
||||
verb: 'post'
|
||||
}
|
||||
});
|
||||
|
||||
FakeProduction.messageSend = function(ctx, cb) {
|
||||
var tickets = ctx.req.body.tickets;
|
||||
var elements = [];
|
||||
tickets.forEach(function(t) {
|
||||
elements.push({salesPerson: 'nelo', message: `Revisa el tickete ${t.ticketFk}`});
|
||||
}, this);
|
||||
messageSend(elements, cb);
|
||||
var userId = ctx.req.accessToken.$userId;
|
||||
var User = FakeProduction.app.models.User;
|
||||
|
||||
User.findById(userId, function (err, user) {
|
||||
var elements = [];
|
||||
tickets.forEach(function(t) {
|
||||
elements.push({sender: user.username, salesPerson: t.salesPerson, message: `Revisa el tickete ${t.ticketFk}`});
|
||||
}, this);
|
||||
messageSend(elements, cb);
|
||||
});
|
||||
};
|
||||
|
||||
var messageSend = function(elements, cb){
|
||||
var messages = [];
|
||||
var messagesInbox = [];
|
||||
elements.forEach(function(e) {
|
||||
var query = `select messageSend(?, ?)`;
|
||||
var params = [e.salesPerson, e.message];
|
||||
FakeProduction.rawSql(query, params, cb);
|
||||
var id = uuid.v1();
|
||||
var message = {uuid: id, sender: e.username, recipient: e.salesPerson, message: e.message};
|
||||
var messageInbox = {uuid: id, sender: e.username, recipient: e.salesPerson, finalRecipient: e.salesPerson, message: e.message};
|
||||
messages.push(message);
|
||||
messagesInbox.push(messageInbox);
|
||||
}, this);
|
||||
|
||||
cb(null, "Mensaje enviado");
|
||||
createMessage(messages, messagesInbox, cb);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
}
|
|
@ -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,
|
||||
"type": "Number",
|
||||
"forceId": false
|
||||
},
|
||||
"username":{
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -76,5 +76,14 @@
|
|||
"FakeProduction": {
|
||||
"dataSource": "vn",
|
||||
"public": true
|
||||
},
|
||||
"Message": {
|
||||
"dataSource": "vn",
|
||||
"public": true
|
||||
},
|
||||
"MessageInbox": {
|
||||
"dataSource": "vn",
|
||||
"public": true
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
"id": true,
|
||||
"type": "Number",
|
||||
"forceId": false
|
||||
},
|
||||
"username":{
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue