fix(cloneWithEntries): endpoint was broken due to production changes
This commit is contained in:
parent
71f77ea69c
commit
f2f81442d9
|
@ -119,7 +119,7 @@ describe('Travel descriptor path', () => {
|
|||
await page.waitToClick(selectors.travelDescriptor.acceptClonation);
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.text).toContain('A travel with this data already exists');
|
||||
expect(message.text).toContain('Unable to clone this travel');
|
||||
});
|
||||
|
||||
it('should update the landed date to a future date to enable cloneWithEntries', async() => {
|
||||
|
|
|
@ -95,7 +95,7 @@
|
|||
"The nif cannot be empty": "The nif cannot be empty",
|
||||
"Amount cannot be zero": "Amount cannot be zero",
|
||||
"Company has to be official": "Company has to be official",
|
||||
"A travel with this data already exists": "A travel with this data already exists",
|
||||
"Unable to clone this travel": "Unable to clone this travel",
|
||||
"The observation type can't be repeated": "The observation type can't be repeated",
|
||||
"New ticket request has been created with price": "New ticket request has been created *'{{description}}'* for day *{{shipped}}*, with a quantity of *{{quantity}}* and a price of *{{price}} €*",
|
||||
"New ticket request has been created": "New ticket request has been created *'{{description}}'* for day *{{shipped}}*, with a quantity of *{{quantity}}*",
|
||||
|
|
|
@ -143,7 +143,7 @@
|
|||
"ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto",
|
||||
"Distance must be lesser than 1000": "La distancia debe ser inferior a 1000",
|
||||
"This ticket is deleted": "Este ticket está eliminado",
|
||||
"A travel with this data already exists": "Ya existe un travel con estos datos",
|
||||
"Unable to clone this travel": "No ha sido posible clonar este travel",
|
||||
"This thermograph id already exists": "La id del termógrafo ya existe",
|
||||
"Choose a date range or days forward": "Selecciona un rango de fechas o días en adelante",
|
||||
"ORDER_ALREADY_CONFIRMED": "ORDER_ALREADY_CONFIRMED",
|
||||
|
|
|
@ -18,8 +18,8 @@ describe('Client', () => {
|
|||
|
||||
describe('onAccept()', () => {
|
||||
it('should perform a POST query and show a success snackbar', () => {
|
||||
let params = {name: 'New Jersey', countryFk: 1};
|
||||
controller.province = {name: 'New Jersey', countryFk: 1};
|
||||
const params = {name: 'New Jersey', autonomyFk: 1};
|
||||
controller.province = {name: 'New Jersey', autonomyFk: 1};
|
||||
|
||||
jest.spyOn(controller.vnApp, 'showMessage');
|
||||
$httpBackend.expect('PATCH', `provinces`, params).respond(200, params);
|
||||
|
|
|
@ -14,7 +14,7 @@ module.exports = Self => {
|
|||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'Object',
|
||||
type: 'object',
|
||||
description: 'The new cloned travel id',
|
||||
root: true,
|
||||
},
|
||||
|
@ -48,46 +48,52 @@ module.exports = Self => {
|
|||
let stmts = [];
|
||||
let stmt;
|
||||
|
||||
try {
|
||||
stmt = new ParameterizedSQL(
|
||||
`CALL travel_cloneWithEntries(?, ?, ?, ?, @vTravelFk)`, [
|
||||
id, started, ended, travel.ref]);
|
||||
stmt = new ParameterizedSQL(
|
||||
`CALL travel_cloneWithEntries(?, ?, ?, ?, ?, ?, ?, @vTravelFk)`, [
|
||||
id,
|
||||
started,
|
||||
ended,
|
||||
travel.warehouseOutFk,
|
||||
travel.warehouseInFk,
|
||||
travel.ref,
|
||||
travel.agencyFk
|
||||
]
|
||||
);
|
||||
|
||||
stmts.push(stmt);
|
||||
const index = stmts.push('SELECT @vTravelFk AS id') - 1;
|
||||
stmts.push(stmt);
|
||||
const newTravelIndex = stmts.push('SELECT @vTravelFk AS id') - 1;
|
||||
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
const result = await conn.executeStmt(sql);
|
||||
const [lastInsert] = result[index];
|
||||
const newTravel = await Self.findById(lastInsert.id, {
|
||||
fields: [
|
||||
'id',
|
||||
'shipped',
|
||||
'landed',
|
||||
'warehouseInFk',
|
||||
'warehouseOutFk',
|
||||
'agencyFk',
|
||||
'ref'
|
||||
]
|
||||
});
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
const result = await conn.executeStmt(sql);
|
||||
const [lastInsert] = result[newTravelIndex];
|
||||
|
||||
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
|
||||
});
|
||||
if (!lastInsert.id)
|
||||
throw new UserError('Unable to clone this travel');
|
||||
|
||||
return newTravel.id;
|
||||
} catch (error) {
|
||||
if (error.code === 'ER_DUP_ENTRY')
|
||||
throw new UserError('A travel with this data already exists');
|
||||
throw error;
|
||||
}
|
||||
const newTravel = await Self.findById(lastInsert.id, {
|
||||
fields: [
|
||||
'id',
|
||||
'shipped',
|
||||
'landed',
|
||||
'warehouseInFk',
|
||||
'warehouseOutFk',
|
||||
'agencyFk',
|
||||
'ref'
|
||||
]
|
||||
});
|
||||
|
||||
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;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue