refs #5816 Remove duplicated logs #1634
|
@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [2328.01] - 2023-07-13
|
||||
|
||||
### Added
|
||||
|
||||
### Changed
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
## [2326.01] - 2023-06-29
|
||||
|
||||
### Added
|
||||
|
|
|
@ -1167,8 +1167,6 @@ export default {
|
|||
allBuyCheckbox: 'vn-entry-buy-index thead vn-check',
|
||||
firstBuyCheckbox: 'vn-entry-buy-index tbody:nth-child(2) vn-check',
|
||||
deleteBuysButton: 'vn-entry-buy-index vn-button[icon="delete"]',
|
||||
addBuyButton: 'vn-entry-buy-index vn-icon[icon="add"]',
|
||||
secondBuyPackingPrice: 'vn-entry-buy-index tbody:nth-child(3) > tr:nth-child(1) vn-input-number[ng-model="buy.price3"]',
|
||||
secondBuyGroupingPrice: 'vn-entry-buy-index tbody:nth-child(3) > tr:nth-child(1) vn-input-number[ng-model="buy.price2"]',
|
||||
secondBuyPrice: 'vn-entry-buy-index tbody:nth-child(3) > tr:nth-child(1) vn-input-number[ng-model="buy.buyingValue"]',
|
||||
secondBuyGrouping: 'vn-entry-buy-index tbody:nth-child(3) > tr:nth-child(1) vn-input-number[ng-model="buy.grouping"]',
|
||||
|
|
|
@ -66,97 +66,4 @@ describe('Entry import, create and edit buys path', () => {
|
|||
await page.waitToClick(selectors.globalItems.acceptButton);
|
||||
await page.waitForNumberOfElements(selectors.entryBuys.anyBuyLine, 1);
|
||||
});
|
||||
|
||||
it('should add a new buy', async() => {
|
||||
await page.waitToClick(selectors.entryBuys.addBuyButton);
|
||||
await page.write(selectors.entryBuys.secondBuyPackingPrice, '999');
|
||||
await page.write(selectors.entryBuys.secondBuyGroupingPrice, '999');
|
||||
await page.write(selectors.entryBuys.secondBuyPrice, '999');
|
||||
await page.write(selectors.entryBuys.secondBuyGrouping, '999');
|
||||
await page.write(selectors.entryBuys.secondBuyPacking, '999');
|
||||
await page.write(selectors.entryBuys.secondBuyWeight, '999');
|
||||
await page.write(selectors.entryBuys.secondBuyStickers, '999');
|
||||
await page.autocompleteSearch(selectors.entryBuys.secondBuyPackage, '1');
|
||||
await page.write(selectors.entryBuys.secondBuyQuantity, '999');
|
||||
await page.autocompleteSearch(selectors.entryBuys.secondBuyItem, '1');
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.text).toContain('Data saved!');
|
||||
|
||||
await page.waitForNumberOfElements(selectors.entryBuys.anyBuyLine, 2);
|
||||
});
|
||||
|
||||
it('should edit the newest buy and check data', async() => {
|
||||
await page.clearInput(selectors.entryBuys.secondBuyPackingPrice);
|
||||
await page.waitForTimeout(250);
|
||||
await page.write(selectors.entryBuys.secondBuyPackingPrice, '100');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.waitForSnackbar();
|
||||
|
||||
await page.clearInput(selectors.entryBuys.secondBuyGroupingPrice);
|
||||
await page.waitForTimeout(250);
|
||||
await page.write(selectors.entryBuys.secondBuyGroupingPrice, '200');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.waitForSnackbar();
|
||||
|
||||
await page.clearInput(selectors.entryBuys.secondBuyPrice);
|
||||
await page.waitForTimeout(250);
|
||||
await page.write(selectors.entryBuys.secondBuyPrice, '300');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.waitForSnackbar();
|
||||
|
||||
await page.clearInput(selectors.entryBuys.secondBuyGrouping);
|
||||
await page.waitForTimeout(250);
|
||||
await page.write(selectors.entryBuys.secondBuyGrouping, '400');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.waitForSnackbar();
|
||||
|
||||
await page.clearInput(selectors.entryBuys.secondBuyPacking);
|
||||
await page.waitForTimeout(250);
|
||||
await page.write(selectors.entryBuys.secondBuyPacking, '500');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.waitForSnackbar();
|
||||
|
||||
await page.clearInput(selectors.entryBuys.secondBuyWeight);
|
||||
await page.waitForTimeout(250);
|
||||
await page.write(selectors.entryBuys.secondBuyWeight, '600');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.waitForSnackbar();
|
||||
|
||||
await page.clearInput(selectors.entryBuys.secondBuyStickers);
|
||||
await page.waitForTimeout(250);
|
||||
await page.write(selectors.entryBuys.secondBuyStickers, '700');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.waitForSnackbar();
|
||||
|
||||
await page.autocompleteSearch(selectors.entryBuys.secondBuyPackage, '94');
|
||||
await page.waitForSnackbar();
|
||||
|
||||
await page.clearInput(selectors.entryBuys.secondBuyQuantity);
|
||||
await page.waitForTimeout(250);
|
||||
await page.write(selectors.entryBuys.secondBuyQuantity, '800');
|
||||
await page.keyboard.press('Enter');
|
||||
|
||||
await page.reloadSection('entry.card.buy.index');
|
||||
|
||||
const secondBuyPackingPrice = await page.getValue(selectors.entryBuys.secondBuyPackingPrice);
|
||||
const secondBuyGroupingPrice = await page.getValue(selectors.entryBuys.secondBuyGroupingPrice);
|
||||
const secondBuyPrice = await page.getValue(selectors.entryBuys.secondBuyPrice);
|
||||
const secondBuyGrouping = await page.getValue(selectors.entryBuys.secondBuyGrouping);
|
||||
const secondBuyPacking = await page.getValue(selectors.entryBuys.secondBuyPacking);
|
||||
const secondBuyWeight = await page.getValue(selectors.entryBuys.secondBuyWeight);
|
||||
const secondBuyStickers = await page.getValue(selectors.entryBuys.secondBuyStickers);
|
||||
const secondBuyPackage = await page.getValue(selectors.entryBuys.secondBuyPackage);
|
||||
const secondBuyQuantity = await page.getValue(selectors.entryBuys.secondBuyQuantity);
|
||||
|
||||
expect(secondBuyPackingPrice).toEqual('100');
|
||||
expect(secondBuyGroupingPrice).toEqual('200');
|
||||
expect(secondBuyPrice).toEqual('300');
|
||||
expect(secondBuyGrouping).toEqual('400');
|
||||
expect(secondBuyPacking).toEqual('500');
|
||||
expect(secondBuyWeight).toEqual('600');
|
||||
expect(secondBuyStickers).toEqual('700');
|
||||
expect(secondBuyPackage).toEqual('94');
|
||||
expect(secondBuyQuantity).toEqual('800');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -177,7 +177,6 @@
|
|||
"You can not select this payment method without a registered bankery account": "No se puede utilizar este método de pago si no has registrado una cuenta bancaria",
|
||||
"Action not allowed on the test environment": "Esta acción no está permitida en el entorno de pruebas",
|
||||
"The selected ticket is not suitable for this route": "El ticket seleccionado no es apto para esta ruta",
|
||||
"Sorts whole route": "Reordena ruta entera",
|
||||
"New ticket request has been created with price": "Se ha creado una nueva petición de compra '{{description}}' para el día *{{shipped}}*, con una cantidad de *{{quantity}}* y un precio de *{{price}} €*",
|
||||
"New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día *{{shipped}}*, con una cantidad de *{{quantity}}*",
|
||||
"Swift / BIC cannot be empty": "Swift / BIC no puede estar vacío",
|
||||
|
|
|
@ -77,14 +77,6 @@ module.exports = Self => {
|
|||
if (salesPersonId)
|
||||
await models.Chat.sendCheckingPresence(ctx, salesPersonId, message);
|
||||
|
||||
await models.ClaimLog.create({
|
||||
originFk: args.id,
|
||||
userFk: userId,
|
||||
action: 'insert',
|
||||
description: 'Claim-pickup-order sent',
|
||||
changedModel: 'Mail'
|
||||
});
|
||||
|
||||
const email = new Email('claim-pickup-order', params);
|
||||
|
||||
return email.send();
|
||||
|
|
|
@ -19,9 +19,6 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.confirmTransaction = async(ctx, id, options) => {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
let tx;
|
||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||
|
||||
|
@ -34,29 +31,8 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
const oldTpvTransaction = await models.TpvTransaction.findById(id, null, myOptions);
|
||||
|
||||
const confirm = await Self.rawSql('CALL hedera.tpvTransaction_confirmById(?)', [id], myOptions);
|
||||
|
||||
const tpvTransaction = await models.TpvTransaction.findById(id, null, myOptions);
|
||||
|
||||
const oldInstance = {status: oldTpvTransaction.status};
|
||||
const newInstance = {status: tpvTransaction.status};
|
||||
|
||||
const logRecord = {
|
||||
originFk: tpvTransaction.clientFk,
|
||||
userFk: userId,
|
||||
action: 'update',
|
||||
changedModel: 'TpvTransaction',
|
||||
changedModelId: id,
|
||||
oldInstance: oldInstance,
|
||||
newInstance: newInstance
|
||||
};
|
||||
|
||||
await models.ClientLog.create(logRecord, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return confirm;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
|
|
|
@ -30,34 +30,9 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.sendSms = async(ctx, id, destination, message, options) => {
|
||||
Self.sendSms = async(ctx, id, destination, message) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
const sms = await models.Sms.send(ctx, destination, message);
|
||||
const logRecord = {
|
||||
juan marked this conversation as resolved
Outdated
|
||||
originFk: id,
|
||||
userFk: userId,
|
||||
action: 'insert',
|
||||
changedModel: 'sms',
|
||||
newInstance: {
|
||||
destinationFk: id,
|
||||
destination: destination,
|
||||
message: message,
|
||||
statusCode: sms.statusCode,
|
||||
status: sms.status
|
||||
}
|
||||
};
|
||||
|
||||
const clientLog = await models.ClientLog.create(logRecord, myOptions);
|
||||
|
||||
sms.logId = clientLog.id;
|
||||
|
||||
return sms;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -13,10 +13,7 @@ describe('client sendSms()', () => {
|
|||
|
||||
const sms = await models.Client.sendSms(ctx, id, destination, message, options);
|
||||
|
||||
const createdLog = await models.ClientLog.findById(sms.logId, null, options);
|
||||
const json = JSON.parse(JSON.stringify(createdLog.newInstance));
|
||||
|
||||
expect(json.message).toEqual(message);
|
||||
expect(sms).toBeDefined();
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
|
|
@ -144,20 +144,7 @@ module.exports = Self => {
|
|||
|
||||
if (taxDataChecked && !hasSageData)
|
||||
throw new UserError(`You need to fill sage information before you check verified data`);
|
||||
if (args.despiteOfClient) {
|
||||
const logRecord = {
|
||||
originFk: clientId,
|
||||
userFk: userId,
|
||||
action: 'update',
|
||||
changedModel: 'Client',
|
||||
changedModelId: clientId,
|
||||
description: $t(`Client checked as validated despite of duplication`, {
|
||||
clientId: args.despiteOfClient
|
||||
})
|
||||
};
|
||||
|
||||
await models.ClientLog.create(logRecord, myOptions);
|
||||
}
|
||||
// Remove unwanted properties
|
||||
delete args.ctx;
|
||||
delete args.id;
|
||||
|
|
|
@ -479,21 +479,6 @@ module.exports = Self => {
|
|||
hasChanges = oldData.name != changes.name || oldData.active != changes.active;
|
||||
|
||||
if (!hasChanges) return;
|
||||
|
||||
const isClient = await Self.app.models.Client.count({id: oldData.id});
|
||||
if (isClient) {
|
||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||
const userId = loopBackContext.active.accessToken.userId;
|
||||
const logRecord = {
|
||||
originFk: oldData.id,
|
||||
userFk: userId,
|
||||
action: 'update',
|
||||
changedModel: 'VnUser',
|
||||
oldInstance: {name: oldData.name, active: oldData.active},
|
||||
newInstance: {name: changes.name, active: changes.active}
|
||||
};
|
||||
await Self.app.models.ClientLog.create(logRecord);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,165 +0,0 @@
|
|||
|
||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('addBuy', {
|
||||
description: 'Inserts a new buy for the current entry',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The entry id',
|
||||
http: {source: 'path'}
|
||||
},
|
||||
{
|
||||
arg: 'itemFk',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'quantity',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'packageFk',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'packing',
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
arg: 'grouping',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'weight',
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
arg: 'stickers',
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
arg: 'price2',
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
arg: 'price3',
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
arg: 'buyingValue',
|
||||
type: 'number'
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/addBuy`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.addBuy = async(ctx, options) => {
|
||||
const conn = Self.dataSource.connector;
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const models = Self.app.models;
|
||||
|
||||
ctx.args.entryFk = ctx.args.id;
|
||||
|
||||
// remove unwanted properties
|
||||
delete ctx.args.id;
|
||||
delete ctx.args.ctx;
|
||||
|
||||
const newBuy = await models.Buy.create(ctx.args, myOptions);
|
||||
|
||||
const filter = {
|
||||
fields: [
|
||||
'id',
|
||||
'itemFk',
|
||||
'stickers',
|
||||
'packing',
|
||||
'grouping',
|
||||
'quantity',
|
||||
'packageFk',
|
||||
'weight',
|
||||
'buyingValue',
|
||||
'price2',
|
||||
'price3'
|
||||
],
|
||||
include: {
|
||||
relation: 'item',
|
||||
scope: {
|
||||
fields: [
|
||||
'id',
|
||||
'typeFk',
|
||||
'name',
|
||||
'size',
|
||||
'minPrice',
|
||||
'tag5',
|
||||
'value5',
|
||||
'tag6',
|
||||
'value6',
|
||||
'tag7',
|
||||
'value7',
|
||||
'tag8',
|
||||
'value8',
|
||||
'tag9',
|
||||
'value9',
|
||||
'tag10',
|
||||
'value10',
|
||||
'groupingMode'
|
||||
],
|
||||
include: {
|
||||
relation: 'itemType',
|
||||
scope: {
|
||||
fields: ['code', 'description']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const stmts = [];
|
||||
let stmt;
|
||||
|
||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc');
|
||||
stmt = new ParameterizedSQL(
|
||||
`CREATE TEMPORARY TABLE tmp.buyRecalc
|
||||
(INDEX (id))
|
||||
ENGINE = MEMORY
|
||||
SELECT ? AS id`, [newBuy.id]);
|
||||
|
||||
stmts.push(stmt);
|
||||
stmts.push('CALL buy_recalcPrices()');
|
||||
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
await conn.executeStmt(sql, myOptions);
|
||||
|
||||
const buy = await models.Buy.findById(newBuy.id, filter, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return buy;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -1,42 +0,0 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('entry addBuy()', () => {
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 18},
|
||||
};
|
||||
|
||||
const ctx = {
|
||||
req: activeCtx
|
||||
};
|
||||
|
||||
const entryId = 2;
|
||||
it('should create a new buy for the given entry', async() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
const itemId = 4;
|
||||
const quantity = 10;
|
||||
|
||||
ctx.args = {
|
||||
id: entryId,
|
||||
itemFk: itemId,
|
||||
quantity: quantity,
|
||||
packageFk: 3
|
||||
};
|
||||
|
||||
const tx = await models.Entry.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
const newBuy = await models.Entry.addBuy(ctx, options);
|
||||
|
||||
expect(newBuy.itemFk).toEqual(itemId);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -3,7 +3,6 @@ module.exports = Self => {
|
|||
require('../methods/entry/filter')(Self);
|
||||
require('../methods/entry/getEntry')(Self);
|
||||
require('../methods/entry/getBuys')(Self);
|
||||
require('../methods/entry/addBuy')(Self);
|
||||
require('../methods/entry/importBuys')(Self);
|
||||
require('../methods/entry/importBuysPreview')(Self);
|
||||
require('../methods/entry/lastItemBuys')(Self);
|
||||
|
|
|
@ -222,13 +222,6 @@
|
|||
</vn-data-viewer>
|
||||
<div fixed-bottom-right>
|
||||
<vn-vertical style="align-items: center;">
|
||||
<vn-button class="round md vn-mb-sm"
|
||||
ng-click="model.insert({})"
|
||||
icon="add"
|
||||
vn-tooltip="Add buy"
|
||||
tooltip-position="left"
|
||||
vn-bind="+">
|
||||
</vn-button>
|
||||
<a ui-sref="entry.card.buy.import" >
|
||||
<vn-button class="round md vn-mb-sm"
|
||||
icon="publish"
|
||||
|
|
|
@ -13,11 +13,6 @@ export default class Controller extends Section {
|
|||
query: `Buys/${buy.id}`,
|
||||
method: 'patch'
|
||||
};
|
||||
} else {
|
||||
options = {
|
||||
query: `Entries/${this.entry.id}/addBuy`,
|
||||
method: 'post'
|
||||
};
|
||||
}
|
||||
this.$http[options.method](options.query, buy).then(res => {
|
||||
if (!res.data) return;
|
||||
|
|
|
@ -25,17 +25,6 @@ describe('Entry buy', () => {
|
|||
controller.saveBuy(buy);
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it(`should call the entry addBuy post route if the received buy has no ID`, () => {
|
||||
controller.entry = {id: 1};
|
||||
const buy = {itemFk: 1, quantity: 1, packageFk: 1};
|
||||
|
||||
const query = `Entries/${controller.entry.id}/addBuy`;
|
||||
|
||||
$httpBackend.expectPOST(query).respond(200);
|
||||
controller.saveBuy(buy);
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteBuys()', () => {
|
||||
|
|
|
@ -21,7 +21,6 @@ module.exports = Self => {
|
|||
|
||||
Self.guessPriority = async(ctx, id) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const $t = ctx.req.__; // $translate
|
||||
const query = `CALL vn.routeGuessPriority(?)`;
|
||||
const tx = await Self.beginTransaction({});
|
||||
|
||||
|
@ -30,16 +29,6 @@ module.exports = Self => {
|
|||
|
||||
const priority = await Self.rawSql(query, [id], options);
|
||||
|
||||
let logRecord = {
|
||||
originFk: id,
|
||||
userFk: userId,
|
||||
action: 'update',
|
||||
changedModel: 'Route',
|
||||
description: $t('Sorts whole route')
|
||||
};
|
||||
|
||||
await Self.app.models.RouteLog.create(logRecord, options);
|
||||
|
||||
await tx.commit();
|
||||
return priority;
|
||||
} catch (e) {
|
||||
|
|
|
@ -31,18 +31,6 @@ describe('route updateVolume()', () => {
|
|||
const updatedRoute = await app.models.Route.findById(routeId, null, options);
|
||||
|
||||
expect(updatedRoute.m3).not.toEqual(route.m3);
|
||||
|
||||
const logs = await app.models.RouteLog.find({
|
||||
fields: ['id', 'newInstance']
|
||||
}, options);
|
||||
|
||||
const m3Log = logs.filter(log => {
|
||||
if (log.newInstance)
|
||||
return log.newInstance.m3 === updatedRoute.m3;
|
||||
});
|
||||
|
||||
expect(m3Log.length).toEqual(1);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
|
|
|
@ -35,24 +35,9 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
const originalRoute = await models.Route.findById(id, null, myOptions);
|
||||
|
||||
await Self.rawSql(`CALL vn.routeUpdateM3(?)`, [id], myOptions);
|
||||
|
||||
const updatedRoute = await models.Route.findById(id, null, myOptions);
|
||||
|
||||
await models.RouteLog.create({
|
||||
juan marked this conversation as resolved
Outdated
jgallego
commented
este se puso porque ellos necesitan saber si alguien ha ejecutado esa accion. Cual es la alternativa? este se puso porque ellos necesitan saber si alguien ha ejecutado esa accion. Cual es la alternativa?
juan
commented
El procedimiento El procedimiento `vn.routeUpdateM3` ya actualiza las rutas y ese registro ya se inserta con el log binario, además no se comprueba que si el nuevo valor es distinto del antiguo. Actualmente el log aparece duplicado.
|
||||
originFk: id,
|
||||
userFk: userId,
|
||||
action: 'update',
|
||||
changedModel: 'Route',
|
||||
changedModelId: id,
|
||||
oldInstance: {m3: originalRoute.m3},
|
||||
newInstance: {m3: updatedRoute.m3}
|
||||
}, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return updatedRoute;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
|
|
|
@ -97,22 +97,6 @@ module.exports = Self => {
|
|||
});
|
||||
await models.Chat.sendCheckingPresence(ctx, requesterId, message, myOptions);
|
||||
|
||||
const logRecord = {
|
||||
juan marked this conversation as resolved
Outdated
jgallego
commented
En este caso he hecho una prueba y no logea nada.. En este caso he hecho una prueba y no logea nada..
juan
commented
Esto ya se registra con el log binario y aparece duplicado. Esto ya se registra con el log binario y aparece duplicado.
|
||||
originFk: sale.ticketFk,
|
||||
userFk: userId,
|
||||
action: 'update',
|
||||
changedModel: 'ticketRequest',
|
||||
newInstance: {
|
||||
destinationFk: sale.ticketFk,
|
||||
quantity: sale.quantity,
|
||||
concept: sale.concept,
|
||||
itemId: sale.itemFk,
|
||||
ticketId: sale.ticketFk,
|
||||
}
|
||||
};
|
||||
|
||||
await Self.app.models.TicketLog.create(logRecord, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return sale;
|
||||
|
|
|
@ -242,16 +242,6 @@ module.exports = Self => {
|
|||
const oldProperties = await loggable.translateValues(Self, changes.old);
|
||||
const newProperties = await loggable.translateValues(Self, changes.new);
|
||||
|
||||
await models.TicketLog.create({
|
||||
originFk: args.id,
|
||||
userFk: userId,
|
||||
action: 'update',
|
||||
changedModel: 'Ticket',
|
||||
changedModelId: args.id,
|
||||
oldInstance: oldProperties,
|
||||
newInstance: newProperties
|
||||
}, myOptions);
|
||||
|
||||
const salesPersonId = originalTicket.client().salesPersonFk;
|
||||
if (salesPersonId) {
|
||||
const origin = ctx.req.headers.origin;
|
||||
|
|
|
@ -52,23 +52,10 @@ module.exports = Self => {
|
|||
});
|
||||
if (!ticket.originId || !ticket.destinationId) continue;
|
||||
|
||||
const ticketDestinationLogRecord = {
|
||||
originFk: ticket.destinationId,
|
||||
userFk: ctx.req.accessToken.userId,
|
||||
action: 'update',
|
||||
changedModel: 'Ticket',
|
||||
changedModelId: ticket.destinationId,
|
||||
changedModelValue: ticket.destinationId,
|
||||
oldInstance: {},
|
||||
newInstance: {mergedTicket: ticket.originId}
|
||||
};
|
||||
|
||||
await models.Sale.updateAll({ticketFk: ticket.originId}, {ticketFk: ticket.destinationId}, myOptions);
|
||||
if (await models.Ticket.setDeleted(ctx, ticket.originId, myOptions)) {
|
||||
await models.TicketLog.create(ticketDestinationLogRecord, myOptions);
|
||||
if (await models.Ticket.setDeleted(ctx, ticket.originId, myOptions))
|
||||
await models.Chat.sendCheckingPresence(ctx, ticket.workerFk, message);
|
||||
}
|
||||
}
|
||||
if (tx)
|
||||
await tx.commit();
|
||||
} catch (e) {
|
||||
|
|
|
@ -30,54 +30,12 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.sendSms = async(ctx, id, destination, message, options) => {
|
||||
Self.sendSms = async(ctx, id, destination, message) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
try {
|
||||
const sms = await models.Sms.send(ctx, destination, message);
|
||||
|
||||
const newTicketSms = {
|
||||
await models.TicketSms.create({
|
||||
ticketFk: id,
|
||||
smsFk: sms.id
|
||||
};
|
||||
await models.TicketSms.create(newTicketSms);
|
||||
|
||||
const logRecord = {
|
||||
originFk: id,
|
||||
userFk: userId,
|
||||
action: 'insert',
|
||||
changedModel: 'sms',
|
||||
newInstance: {
|
||||
destinationFk: id,
|
||||
destination: destination,
|
||||
message: message,
|
||||
statusCode: sms.statusCode,
|
||||
status: sms.status
|
||||
}
|
||||
};
|
||||
|
||||
const ticketLog = await models.TicketLog.create(logRecord, myOptions);
|
||||
|
||||
sms.logId = ticketLog.id;
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return sms;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -43,12 +43,10 @@ describe('ticket merge()', () => {
|
|||
|
||||
await models.Ticket.merge(ctx, [tickets], options);
|
||||
|
||||
const createdTicketLog = await models.TicketLog.find({where: {originFk: tickets.destinationId}}, options);
|
||||
const deletedTicket = await models.Ticket.findOne({where: {id: tickets.originId}}, options);
|
||||
const salesTicketFuture = await models.Sale.find({where: {ticketFk: tickets.destinationId}}, options);
|
||||
const chatNotificationAfterMerge = await models.Chat.find(null, options);
|
||||
|
||||
expect(createdTicketLog.length).toEqual(1);
|
||||
expect(deletedTicket.isDeleted).toEqual(true);
|
||||
expect(salesTicketFuture.length).toEqual(2);
|
||||
expect(chatNotificationBeforeMerge.length).toEqual(chatNotificationAfterMerge.length - 2);
|
||||
|
|
|
@ -12,19 +12,14 @@ describe('ticket sendSms()', () => {
|
|||
const destination = 222222222;
|
||||
const message = 'this is the message created in a test';
|
||||
|
||||
const sms = await models.Ticket.sendSms(ctx, id, destination, message, options);
|
||||
|
||||
const createdLog = await models.TicketLog.findById(sms.logId, null, options);
|
||||
await models.Ticket.sendSms(ctx, id, destination, message, options);
|
||||
|
||||
const filter = {
|
||||
ticketFk: createdLog.originFk
|
||||
ticketFk: id
|
||||
};
|
||||
const ticketSms = await models.TicketSms.findOne(filter, options);
|
||||
|
||||
const json = JSON.parse(JSON.stringify(createdLog.newInstance));
|
||||
|
||||
expect(json.message).toEqual(message);
|
||||
expect(ticketSms.ticketFk).toEqual(createdLog.originFk);
|
||||
expect(ticketSms.ticketFk).toEqual(id);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
|
|
@ -84,13 +84,6 @@ module.exports = Self => {
|
|||
|
||||
for (const sale of sales) {
|
||||
const originalSale = map.get(sale.id);
|
||||
const originalSaleData = { // <-- Loopback modifies original instance on save
|
||||
itemFk: originalSale.itemFk,
|
||||
quantity: originalSale.quantity,
|
||||
concept: originalSale.concept,
|
||||
ticketFk: originalSale.ticketFk
|
||||
};
|
||||
|
||||
if (sale.quantity == originalSale.quantity) {
|
||||
query = `UPDATE sale
|
||||
SET ticketFk = ?
|
||||
|
@ -100,48 +93,6 @@ module.exports = Self => {
|
|||
await transferPartialSale(
|
||||
ticketId, originalSale, sale, myOptions);
|
||||
}
|
||||
|
||||
// Log to original ticket
|
||||
await models.TicketLog.create({
|
||||
originFk: id,
|
||||
userFk: userId,
|
||||
action: 'update',
|
||||
changedModel: 'Sale',
|
||||
changedModelId: sale.id,
|
||||
oldInstance: {
|
||||
item: originalSaleData.itemFk,
|
||||
quantity: originalSaleData.quantity,
|
||||
concept: originalSaleData.concept,
|
||||
ticket: originalSaleData.ticketFk
|
||||
},
|
||||
newInstance: {
|
||||
item: sale.itemFk,
|
||||
quantity: sale.quantity,
|
||||
concept: sale.concept,
|
||||
ticket: ticketId
|
||||
}
|
||||
}, myOptions);
|
||||
|
||||
// Log to destination ticket
|
||||
await models.TicketLog.create({
|
||||
originFk: ticketId,
|
||||
userFk: userId,
|
||||
action: 'update',
|
||||
changedModel: 'Sale',
|
||||
changedModelId: sale.id,
|
||||
oldInstance: {
|
||||
item: originalSaleData.itemFk,
|
||||
quantity: originalSaleData.quantity,
|
||||
concept: originalSaleData.concept,
|
||||
ticket: originalSaleData.ticketFk
|
||||
},
|
||||
newInstance: {
|
||||
item: sale.itemFk,
|
||||
quantity: sale.quantity,
|
||||
concept: sale.concept,
|
||||
ticket: ticketId
|
||||
}
|
||||
}, myOptions);
|
||||
}
|
||||
|
||||
const isTicketEmpty = await models.Ticket.isEmpty(id, myOptions);
|
||||
|
|
|
@ -1,30 +1,4 @@
|
|||
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
module.exports = Self => {
|
||||
// Methods
|
||||
require('./ticket-methods')(Self);
|
||||
|
||||
Self.observe('before save', async function(ctx) {
|
||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||
const httpCtx = loopBackContext.active;
|
||||
|
||||
if (ctx.isNewInstance) return;
|
||||
|
||||
let changes = ctx.data || ctx.instance;
|
||||
|
||||
if (changes.routeFk === null && ctx.currentInstance.routeFk != null) {
|
||||
let instance = JSON.parse(JSON.stringify(ctx.currentInstance));
|
||||
let userId = httpCtx.accessToken.userId;
|
||||
let logRecord = {
|
||||
originFk: ctx.currentInstance.routeFk,
|
||||
userFk: userId,
|
||||
action: 'delete',
|
||||
changedModel: 'Route',
|
||||
oldInstance: {ticket: instance.id},
|
||||
newInstance: null
|
||||
};
|
||||
await Self.app.models.RouteLog.create(logRecord);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -25,9 +25,7 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.cloneWithEntries = async(ctx, id) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const conn = Self.dataSource.connector;
|
||||
const models = Self.app.models;
|
||||
const travel = await Self.findById(id, {
|
||||
fields: [
|
||||
'id',
|
||||
|
@ -81,18 +79,6 @@ module.exports = Self => {
|
|||
]
|
||||
});
|
||||
|
||||
const oldProperties = await loggable.translateValues(Self, travel);
|
||||
const newProperties = await loggable.translateValues(Self, newTravel);
|
||||
await models.TravelLog.create({
|
||||
originFk: newTravel.id,
|
||||
userFk: userId,
|
||||
action: 'insert',
|
||||
changedModel: 'Travel',
|
||||
changedModelId: newTravel.id,
|
||||
oldInstance: oldProperties,
|
||||
newInstance: newProperties
|
||||
});
|
||||
|
||||
return newTravel.id;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -30,24 +30,8 @@ module.exports = Self => {
|
|||
SET travelFk = NULL, dmsFk = NULL
|
||||
WHERE id = ?`, [id], {userId});
|
||||
|
||||
const oldInstance = {
|
||||
travelFk: travelThermograph.travelFk,
|
||||
dmsFk: travelThermograph.dmsFk
|
||||
};
|
||||
|
||||
await models.TravelLog.create({
|
||||
originFk: travelThermograph.travelFk,
|
||||
userFk: userId,
|
||||
action: 'delete',
|
||||
changedModel: 'TravelThermograph',
|
||||
changedModelId: id,
|
||||
oldInstance: oldInstance,
|
||||
newInstance: {}
|
||||
});
|
||||
|
||||
travelThermograph.travelFk = null;
|
||||
travelThermograph.dmsFk = null;
|
||||
|
||||
return travelThermograph;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -40,7 +40,6 @@ module.exports = Self => {
|
|||
Self.updateWorkerTimeControlMail = async(ctx, options) => {
|
||||
const models = Self.app.models;
|
||||
const args = ctx.args;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
const myOptions = {};
|
||||
|
||||
|
@ -57,9 +56,6 @@ module.exports = Self => {
|
|||
|
||||
if (!workerTimeControlMail) throw new UserError(`There aren't records for this week`);
|
||||
|
||||
const oldState = workerTimeControlMail.state;
|
||||
const oldReason = workerTimeControlMail.reason;
|
||||
|
||||
await workerTimeControlMail.updateAttributes({
|
||||
state: args.state,
|
||||
reason: args.reason || null
|
||||
|
@ -70,22 +66,5 @@ module.exports = Self => {
|
|||
sendedCounter: workerTimeControlMail.sendedCounter + 1
|
||||
}, myOptions);
|
||||
}
|
||||
|
||||
const logRecord = {
|
||||
originFk: args.workerId,
|
||||
userFk: userId,
|
||||
action: 'update',
|
||||
changedModel: 'WorkerTimeControlMail',
|
||||
oldInstance: {
|
||||
state: oldState,
|
||||
reason: oldReason
|
||||
},
|
||||
newInstance: {
|
||||
state: args.state,
|
||||
reason: args.reason
|
||||
}
|
||||
};
|
||||
|
||||
return models.WorkerLog.create(logRecord, myOptions);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "salix-back",
|
||||
"version": "23.26.01",
|
||||
"version": "23.28.01",
|
||||
"author": "Verdnatura Levante SL",
|
||||
"description": "Salix backend",
|
||||
"license": "GPL-3.0",
|
||||
|
|
Loading…
Reference in New Issue
Esto lo pidieron para saber que a un cliente que info se le ha enviado, sobre todo durante el mismo dia
Se solucionará en la tarea https://redmine.verdnatura.es/issues/5934