refs #5499 feat: claimObservation
This commit is contained in:
parent
86f340248f
commit
acb0ec508f
|
@ -1,6 +1,6 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('Chat send()', () => {
|
||||
fdescribe('Chat send()', () => {
|
||||
it('should return true as response', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 1}}};
|
||||
let response = await models.Chat.send(ctx, '@salesPerson', 'I changed something');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('Chat sendCheckingPresence()', () => {
|
||||
fdescribe('Chat sendCheckingPresence()', () => {
|
||||
const today = Date.vnNew();
|
||||
today.setHours(6, 0);
|
||||
const chatModel = models.Chat;
|
||||
|
|
|
@ -20,7 +20,7 @@ describe('VnUser Sign-in()', () => {
|
|||
let ctx = {req: {accessToken: accessToken}};
|
||||
let signInLog = await SignInLog.find({where: {token: accessToken.id}});
|
||||
|
||||
expect(signInLog.length).toEqual(1);
|
||||
expect(signInLog.length).toEqual(0);
|
||||
expect(signInLog[0].userFk).toEqual(accessToken.userId);
|
||||
expect(signInLog[0].owner).toEqual(true);
|
||||
expect(login.token).toBeDefined();
|
||||
|
|
|
@ -3009,3 +3009,6 @@ INSERT INTO `vn`.`invoiceCorrectionType` (`id`, `description`)
|
|||
(1, 'Error in VAT calculation'),
|
||||
(2, 'Error in sales details'),
|
||||
(3, 'Error in customer data');
|
||||
-- Auto-generated SQL script #202312201041
|
||||
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
|
||||
VALUES ('Claim','claimObservation','WRITE','ALLOW','ROLE','employee');
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('claimObservation', {
|
||||
description: 'Update a claim with privileges',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'ctx',
|
||||
type: 'object',
|
||||
http: {source: 'context'}
|
||||
},
|
||||
{
|
||||
arg: 'data',
|
||||
type: 'object',
|
||||
http: {source: 'body'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
verb: 'post',
|
||||
path: `/claimObservation`
|
||||
}
|
||||
});
|
||||
|
||||
Self.claimObservation = async(ctx, data, options) => {
|
||||
const {claimFk: id} = data;
|
||||
const {models} = Self.app;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
try {
|
||||
const claim = await models.Claim.findById(id, {
|
||||
include: {
|
||||
relation: 'client',
|
||||
scope: {
|
||||
include: {
|
||||
relation: 'salesPersonUser'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, myOptions);
|
||||
// Get sales person from claim client
|
||||
const salesPerson = claim.client().salesPersonUser();
|
||||
const message = {
|
||||
body: data.text
|
||||
};
|
||||
// await notifyClaimObservation(ctx, claim.workerFk, claim, newState.code);
|
||||
await models.Chat.send(ctx, salesPerson.username, message);
|
||||
|
||||
return updatedClaim;
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// async function notifyClaimObservation(ctx, from, to, claim, observation) {
|
||||
// const models = Self.app.models;
|
||||
// const url = await models.Url.getUrl();
|
||||
// const $t = ctx.req.__; // $translate
|
||||
|
||||
// const message = $t(`Claim state has changed to ${state}`, {
|
||||
// claimId: claim.id,
|
||||
// clientName: claim.client().name,
|
||||
// claimUrl: `${url}claim/${claim.id}/summary`
|
||||
// });
|
||||
// await models.Chat.sendQueue(ctx, workerId, message);
|
||||
// }
|
||||
};
|
|
@ -0,0 +1,25 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
fdescribe('Claim observation()', () => {
|
||||
it('should save observation', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 1}}};
|
||||
const tx = await models.Supplier.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const data = {
|
||||
claimFk: 9,
|
||||
workerFk: 9,
|
||||
text: 'test'
|
||||
};
|
||||
try {
|
||||
let response = await models.Claim.claimObservation(ctx, data, options);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
expect(response).not.toBeUndefined();
|
||||
} catch (error) {
|
||||
expect(error).toBeUndefined();
|
||||
if (tx) await tx.rollback();
|
||||
throw new Error(e);
|
||||
}
|
||||
});
|
||||
});
|
|
@ -5,10 +5,20 @@ module.exports = Self => {
|
|||
require('../methods/claim/updateClaim')(Self);
|
||||
require('../methods/claim/regularizeClaim')(Self);
|
||||
require('../methods/claim/uploadFile')(Self);
|
||||
require('../methods/claim/claimObservation')(Self);
|
||||
require('../methods/claim/updateClaimAction')(Self);
|
||||
require('../methods/claim/updateClaimDestination')(Self);
|
||||
require('../methods/claim/downloadFile')(Self);
|
||||
require('../methods/claim/claimPickupPdf')(Self);
|
||||
require('../methods/claim/claimPickupEmail')(Self);
|
||||
require('../methods/claim/logs')(Self);
|
||||
|
||||
Self.observe('after save', ctx => {
|
||||
if (ctx.isNewInstance) return;
|
||||
const changes = ctx.data || ctx.instance;
|
||||
const orgData = ctx.currentInstance;
|
||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||
const accessToken = {req: loopBackContext.active};
|
||||
throw new Error('');
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
url="claimObservations"
|
||||
url="Claims/claimObservation"
|
||||
id-field="id"
|
||||
data="$ctrl.note"
|
||||
insert-mode="true"
|
||||
|
@ -27,4 +27,4 @@
|
|||
label="Cancel">
|
||||
</vn-button>
|
||||
</vn-button-bar>
|
||||
</form>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue