feat(origin): create method url_/geturl redf #5979
This commit is contained in:
parent
4f911e644c
commit
9870a0e60a
|
@ -25,22 +25,24 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.sendCheckingPresence = async(ctx, recipientId, message) => {
|
||||
console.log('recipientId: ', recipientId);
|
||||
if (!recipientId) return false;
|
||||
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const sender = await models.VnUser.findById(userId, {fields: ['id']});
|
||||
const recipient = await models.VnUser.findById(recipientId, null);
|
||||
console.log('sender: ', ctx.req.accessToken.userId);
|
||||
const sender = ctx.req.accessToken.userId;
|
||||
console.log('sender: ', sender);
|
||||
const recipient = recipientId;
|
||||
console.log('recipient: ', recipient);
|
||||
|
||||
console.log('recipientId == sender: ', recipientId == sender);
|
||||
|
||||
// Prevent sending messages to yourself
|
||||
if (recipientId == userId) return false;
|
||||
|
||||
if (recipientId == sender) return false;
|
||||
if (!recipient)
|
||||
throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`);
|
||||
|
||||
throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${sender}`);
|
||||
if (process.env.NODE_ENV == 'test')
|
||||
message = `[Test:Environment to user ${userId}] ` + message;
|
||||
|
||||
message = `[Test:Environment to user ${sender}] ` + message;
|
||||
console.log('chat create');
|
||||
const chat = await models.Chat.create({
|
||||
senderFk: sender.id,
|
||||
recipient: `@${recipient.name}`,
|
||||
|
@ -51,6 +53,8 @@ module.exports = Self => {
|
|||
attempts: 0
|
||||
});
|
||||
|
||||
console.log('chat: ');
|
||||
|
||||
try {
|
||||
await Self.sendCheckingUserStatus(chat);
|
||||
await Self.updateChat(chat, 'sent');
|
||||
|
|
|
@ -6,6 +6,10 @@ module.exports = Self => {
|
|||
require('../methods/chat/sendQueued')(Self);
|
||||
|
||||
Self.observe('before save', async function(ctx) {
|
||||
console.log('chat start 1');
|
||||
|
||||
console.log('ctx.isNewInstance: ', ctx.isNewInstance);
|
||||
console.log('message: ', ctx.instance);
|
||||
if (!ctx.isNewInstance) return;
|
||||
|
||||
let {message} = ctx.instance;
|
||||
|
@ -13,14 +17,15 @@ module.exports = Self => {
|
|||
|
||||
const parts = message.match(/(?<=\[)[a-zA-Z0-9_\-+!@#$%^&*()={};':"\\|,.<>/?\s]*(?=])/g);
|
||||
if (!parts) return;
|
||||
|
||||
console.log('chat start 2');
|
||||
const replacedParts = parts.map(part => {
|
||||
return part.replace(/[!$%^&*()={};':"\\,.<>/?]/g, '');
|
||||
});
|
||||
|
||||
console.log('chat start 3');
|
||||
for (const [index, part] of parts.entries())
|
||||
message = message.replace(part, replacedParts[index]);
|
||||
|
||||
ctx.instance.message = message;
|
||||
console.log('chat end');
|
||||
});
|
||||
};
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
},{
|
||||
"accessType": "READ",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@ const app = require('vn-loopback/server/server');
|
|||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('Update Claim', () => {
|
||||
let url;
|
||||
beforeAll(async() => {
|
||||
url = await app.models.Application.getUrl();
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 9},
|
||||
http: {
|
||||
|
@ -29,7 +31,6 @@ describe('Update Claim', () => {
|
|||
|
||||
it(`should throw an error as the user doesn't have rights`, async() => {
|
||||
const tx = await app.models.Claim.beginTransaction({});
|
||||
|
||||
let error;
|
||||
|
||||
try {
|
||||
|
@ -61,7 +62,7 @@ describe('Update Claim', () => {
|
|||
expect(error.message).toEqual(`You don't have enough privileges to change that field`);
|
||||
});
|
||||
|
||||
it(`should success to update the claimState to 'canceled' and send a rocket message`, async() => {
|
||||
fit(`should success to update the claimState to 'canceled' and send a rocket message`, async() => {
|
||||
const tx = await app.models.Claim.beginTransaction({});
|
||||
|
||||
try {
|
||||
|
@ -77,7 +78,7 @@ describe('Update Claim', () => {
|
|||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: claimManagerId},
|
||||
headers: {origin: 'http://localhost'}
|
||||
headers: {origin: url}
|
||||
},
|
||||
args: {
|
||||
observation: 'valid observation',
|
||||
|
@ -118,7 +119,7 @@ describe('Update Claim', () => {
|
|||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: claimManagerId},
|
||||
headers: {origin: 'http://localhost'}
|
||||
headers: {origin: url}
|
||||
},
|
||||
args: {
|
||||
observation: 'valid observation',
|
||||
|
|
|
@ -92,7 +92,6 @@ module.exports = Self => {
|
|||
// When hasToPickUp has been changed
|
||||
if (salesPerson && changedHasToPickUp && updatedClaim.hasToPickUp)
|
||||
notifyPickUp(ctx, salesPerson.id, claim);
|
||||
|
||||
// When claimState has been changed
|
||||
if (args.claimStateFk) {
|
||||
const newState = await models.ClaimState.findById(args.claimStateFk, null, myOptions);
|
||||
|
@ -123,6 +122,7 @@ module.exports = Self => {
|
|||
clientName: claim.client().name,
|
||||
claimUrl: `${url}claim/${claim.id}/summary`
|
||||
});
|
||||
console.log(`${url}claim/${claim.id}/summary`);
|
||||
await models.Chat.sendCheckingPresence(ctx, workerId, message);
|
||||
}
|
||||
|
||||
|
@ -136,6 +136,9 @@ module.exports = Self => {
|
|||
clientName: claim.client().name,
|
||||
claimUrl: `${url}claim/${claim.id}/summary`
|
||||
});
|
||||
console.log('url', `${url}claim/${claim.id}/summary`);
|
||||
console.log('claim client', claim.client().name);
|
||||
console.log('claim id', claim.id);
|
||||
await models.Chat.sendCheckingPresence(ctx, workerId, message);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue