Merge pull request '6722-thermograph' (!3019) from 6722-thermograph into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #3019 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
40f3b6b67a
|
@ -38,7 +38,7 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
arg: 'hasFile',
|
arg: 'hasFile',
|
||||||
type: 'Boolean',
|
type: 'Boolean',
|
||||||
description: 'True if has an attached file'
|
description: 'True if has the original in paper'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'hasFileAttached',
|
arg: 'hasFileAttached',
|
||||||
|
|
|
@ -2523,14 +2523,15 @@ INSERT INTO `vn`.`thermograph`(`id`, `model`)
|
||||||
('138350-0', 'DISPOSABLE');
|
('138350-0', 'DISPOSABLE');
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO `vn`.`travelThermograph`(`thermographFk`, `created`, `warehouseFk`, `travelFk`, `temperatureFk`, `result`, `dmsFk`)
|
INSERT INTO `vn`.`travelThermograph`
|
||||||
|
(`thermographFk`, `created`, `warehouseFk`, `travelFk`, `temperatureFk`, `minTemperature`, `maxTemperature`, `result`, `dmsFk`)
|
||||||
VALUES
|
VALUES
|
||||||
('TMM190901395', util.VN_CURDATE(), 1, 1, 'WARM', 'Ok', NULL),
|
('TMM190901395', util.VN_CURDATE(), 1, 1, 'WARM', NULL, NULL, 'Ok', NULL),
|
||||||
('TL.BBA85422', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2, 'COOL', 'Ok', NULL),
|
('TL.BBA85422', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2, 'COOL', NULL, NULL, 'Ok', NULL),
|
||||||
('TL.BBA85422', util.VN_CURDATE(), 2, 1, 'COOL', 'can not read the temperature', NULL),
|
('TL.BBA85422', util.VN_CURDATE(), 2, 1, 'COOL', NULL, NULL, 'can not read the temperature', NULL),
|
||||||
('TZ1905012010', util.VN_CURDATE(), 1, 1, 'WARM', 'Temperature in range', 5),
|
('TZ1905012010', util.VN_CURDATE(), 1, 1, 'WARM', NULL, NULL, 'Temperature in range', 5),
|
||||||
('138350-0', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 'WARM', NULL, 5),
|
('138350-0', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 'WARM', 2, 12, NULL, 5),
|
||||||
('138350-0', util.VN_CURDATE(), 1, NULL, 'COOL', NULL, NULL);
|
('138350-0', util.VN_CURDATE(), 1, NULL, 'COOL', NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
REPLACE INTO `vn`.`incoterms`(`code`, `name`)
|
REPLACE INTO `vn`.`incoterms`(`code`, `name`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
ALTER TABLE `vn`.`travelThermograph`
|
||||||
|
ADD COLUMN `maxTemperature` DECIMAL(5,2) NULL AFTER `temperatureFk`,
|
||||||
|
ADD COLUMN `minTemperature` DECIMAL(5,2) NULL AFTER `maxTemperature`;
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `vn`.`travelThermograph` DROP FOREIGN KEY travelThermographDmsFgn;
|
||||||
|
ALTER TABLE `vn`.`travelThermograph` ADD CONSTRAINT travelThermographDmsFgn FOREIGN KEY (dmsFk) REFERENCES vn.dms(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -378,5 +378,6 @@
|
||||||
"The maximum height of the wagon is 200cm": "La altura máxima es 200cm",
|
"The maximum height of the wagon is 200cm": "La altura máxima es 200cm",
|
||||||
"The entry does not have stickers": "La entrada no tiene etiquetas",
|
"The entry does not have stickers": "La entrada no tiene etiquetas",
|
||||||
"Too many records": "Demasiados registros",
|
"Too many records": "Demasiados registros",
|
||||||
"This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha"
|
"This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha",
|
||||||
|
"No valid travel thermograph found": "No se encontró un termógrafo válido"
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,14 +56,16 @@ module.exports = Self => {
|
||||||
model: model
|
model: model
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
await Self.rawSql(`
|
const travelThermograph = await models.TravelThermograph.create({
|
||||||
INSERT INTO travelThermograph(thermographFk, warehouseFk, temperatureFk, created)
|
thermographFk: thermograph.id,
|
||||||
VALUES (?, ?, ?, ?)
|
warehouseFk: warehouseId,
|
||||||
`, [thermograph.id, warehouseId, temperatureFk, date], myOptions);
|
temperatureFk: temperatureFk,
|
||||||
|
created: date
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return thermograph;
|
return travelThermograph;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw err;
|
throw err;
|
||||||
|
|
|
@ -6,47 +6,42 @@ describe('Termograph createThermograph()', () => {
|
||||||
const temperatureFk = 'COOL';
|
const temperatureFk = 'COOL';
|
||||||
const warehouseId = 1;
|
const warehouseId = 1;
|
||||||
const ctx = beforeAll.getCtx();
|
const ctx = beforeAll.getCtx();
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
beforeEach(async() => {
|
||||||
|
tx = await models.Thermograph.beginTransaction({});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async() => {
|
||||||
|
await tx.rollback();
|
||||||
|
});
|
||||||
|
|
||||||
it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => {
|
it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => {
|
||||||
const tx = await models.Thermograph.beginTransaction({});
|
const options = {transaction: tx};
|
||||||
|
|
||||||
try {
|
const createdThermograph = await models.Thermograph.createThermograph(
|
||||||
const options = {transaction: tx};
|
ctx, thermographId, model, temperatureFk, warehouseId, options);
|
||||||
|
|
||||||
const createdThermograph = await models.Thermograph.createThermograph(ctx, thermographId, model, temperatureFk, warehouseId, options);
|
expect(createdThermograph.thermographFk).toEqual(thermographId);
|
||||||
|
|
||||||
expect(createdThermograph.id).toEqual(thermographId);
|
const createdTravelThermograph =
|
||||||
expect(createdThermograph.model).toEqual(model);
|
await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}, options);
|
||||||
|
|
||||||
const createdTravelThermograpth = await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}, options);
|
expect(createdTravelThermograph.warehouseFk).toEqual(warehouseId);
|
||||||
|
expect(createdTravelThermograph.temperatureFk).toEqual(temperatureFk);
|
||||||
expect(createdTravelThermograpth.warehouseFk).toEqual(warehouseId);
|
|
||||||
expect(createdTravelThermograpth.temperatureFk).toEqual(temperatureFk);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should throw an error when trying to created repeated thermograph`, async() => {
|
it(`should throw an error when trying to create a repeated thermograph`, async() => {
|
||||||
const tx = await models.Thermograph.beginTransaction({});
|
|
||||||
|
|
||||||
let error;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
await models.Thermograph.createThermograph(ctx, thermographId, model, temperatureFk, warehouseId, options);
|
await models.Thermograph.createThermograph(
|
||||||
await models.Thermograph.createThermograph(ctx, thermographId, model, temperatureFk, warehouseId, options);
|
ctx, thermographId, model, temperatureFk, warehouseId, options);
|
||||||
|
await models.Thermograph.createThermograph(
|
||||||
await tx.rollback();
|
ctx, thermographId, model, temperatureFk, warehouseId, options);
|
||||||
|
fail('Expected an error to be thrown when trying to create a repeated thermograph');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await tx.rollback();
|
expect(e.message).toBe('This thermograph id already exists');
|
||||||
error = e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error.message).toBe('This thermograph id already exists');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,103 +0,0 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethodCtx('createThermograph', {
|
|
||||||
description: 'Creates a new travel thermograph',
|
|
||||||
accessType: 'WRITE',
|
|
||||||
accepts: [{
|
|
||||||
arg: 'id',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The travel id',
|
|
||||||
http: {source: 'path'}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'thermographId',
|
|
||||||
type: 'string',
|
|
||||||
description: 'The thermograph id',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'state',
|
|
||||||
type: 'string',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'warehouseId',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The warehouse id',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'companyId',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The company id',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'dmsTypeId',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The dms type id',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'reference',
|
|
||||||
type: 'string',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'description',
|
|
||||||
type: 'string',
|
|
||||||
required: true
|
|
||||||
}],
|
|
||||||
returns: {
|
|
||||||
type: 'object',
|
|
||||||
root: true
|
|
||||||
},
|
|
||||||
http: {
|
|
||||||
path: `/:id/createThermograph`,
|
|
||||||
verb: 'POST'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.createThermograph = async(ctx, id, thermographId, state, options) => {
|
|
||||||
const models = Self.app.models;
|
|
||||||
let tx;
|
|
||||||
const myOptions = {};
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
|
||||||
Object.assign(myOptions, options);
|
|
||||||
|
|
||||||
if (!myOptions.transaction) {
|
|
||||||
tx = await Self.beginTransaction({});
|
|
||||||
myOptions.transaction = tx;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const travelThermograph = await models.TravelThermograph.findOne({
|
|
||||||
where: {
|
|
||||||
thermographFk: thermographId,
|
|
||||||
travelFk: null
|
|
||||||
}
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
if (!travelThermograph)
|
|
||||||
throw new UserError('No valid travel thermograph found');
|
|
||||||
|
|
||||||
const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions);
|
|
||||||
const firstDms = uploadedFiles[0];
|
|
||||||
|
|
||||||
await travelThermograph.updateAttributes({
|
|
||||||
dmsFk: firstDms.id,
|
|
||||||
travelFk: id,
|
|
||||||
result: state
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
|
||||||
|
|
||||||
return travelThermograph;
|
|
||||||
} catch (err) {
|
|
||||||
if (tx) await tx.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -0,0 +1,131 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('saveThermograph', {
|
||||||
|
description: 'Creates or updates a travel thermograph',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The travel id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'travelThermographFk',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The travel thermograph id',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'state',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'maxTemperature',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The maximum temperature'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'minTemperature',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The minimum temperature'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'temperatureFk',
|
||||||
|
type: 'string',
|
||||||
|
description: 'Range of temperature'
|
||||||
|
}, {
|
||||||
|
arg: 'warehouseId',
|
||||||
|
type: 'Number',
|
||||||
|
description: 'The warehouse id'
|
||||||
|
}, {
|
||||||
|
arg: 'companyId',
|
||||||
|
type: 'Number',
|
||||||
|
description: 'The company id'
|
||||||
|
}, {
|
||||||
|
arg: 'dmsTypeId',
|
||||||
|
type: 'Number',
|
||||||
|
description: 'The dms type id'
|
||||||
|
}, {
|
||||||
|
arg: 'reference',
|
||||||
|
type: 'String'
|
||||||
|
}, {
|
||||||
|
arg: 'description',
|
||||||
|
type: 'String'
|
||||||
|
}, {
|
||||||
|
arg: 'hasFileAttached',
|
||||||
|
type: 'Boolean',
|
||||||
|
description: 'True if has an attached file'
|
||||||
|
}],
|
||||||
|
returns: {type: 'object', root: true},
|
||||||
|
http: {path: `/:id/saveThermograph`, verb: 'POST'}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.saveThermograph = async(
|
||||||
|
ctx,
|
||||||
|
id,
|
||||||
|
travelThermographFk,
|
||||||
|
state,
|
||||||
|
maxTemperature,
|
||||||
|
minTemperature,
|
||||||
|
temperatureFk,
|
||||||
|
warehouseId,
|
||||||
|
companyId,
|
||||||
|
dmsTypeId,
|
||||||
|
reference,
|
||||||
|
description,
|
||||||
|
hasFileAttached,
|
||||||
|
options
|
||||||
|
) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
let tx;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
let dmsFk;
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const travelThermograph = await models.TravelThermograph.findById(
|
||||||
|
travelThermographFk,
|
||||||
|
{fields: ['id', 'dmsFk', 'warehouseFk']},
|
||||||
|
myOptions
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!travelThermograph)
|
||||||
|
throw new UserError('No valid travel thermograph found');
|
||||||
|
|
||||||
|
if (travelThermograph.dmsFk) {
|
||||||
|
await models.Dms.updateFile(ctx, travelThermograph.dmsFk, myOptions);
|
||||||
|
dmsFk = travelThermograph.dmsFk;
|
||||||
|
} else {
|
||||||
|
const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions);
|
||||||
|
const firstDms = uploadedFiles[0];
|
||||||
|
dmsFk = firstDms.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
await travelThermograph.updateAttributes({
|
||||||
|
dmsFk,
|
||||||
|
travelFk: id,
|
||||||
|
result: state,
|
||||||
|
maxTemperature,
|
||||||
|
minTemperature,
|
||||||
|
temperatureFk
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return travelThermograph;
|
||||||
|
} catch (err) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,51 +0,0 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
|
||||||
|
|
||||||
describe('Travel createThermograph()', () => {
|
|
||||||
beforeAll.mockLoopBackContext();
|
|
||||||
const travelId = 3;
|
|
||||||
const currentUserId = 1102;
|
|
||||||
const thermographId = '138350-0';
|
|
||||||
const ctx = {req: {accessToken: {userId: currentUserId}}, args: {dmsTypeId: 1}};
|
|
||||||
|
|
||||||
it(`should set the travelFk and dmsFk properties to the travel thermograph`, async() => {
|
|
||||||
const tx = await models.Travel.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 5}]);
|
|
||||||
|
|
||||||
travelThermographBefore = await models.TravelThermograph.findOne({
|
|
||||||
where: {
|
|
||||||
thermographFk: thermographId,
|
|
||||||
travelFk: null
|
|
||||||
}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
await models.Travel.createThermograph(ctx, travelId, thermographId, options);
|
|
||||||
|
|
||||||
const travelThermographAfter = await models.TravelThermograph.findOne({
|
|
||||||
where: {
|
|
||||||
thermographFk: thermographId,
|
|
||||||
travelFk: travelId
|
|
||||||
}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(models.Dms.uploadFile).toHaveBeenCalledWith(ctx, jasmine.any(Object));
|
|
||||||
|
|
||||||
expect(travelThermographBefore).toBeDefined();
|
|
||||||
expect(travelThermographBefore.thermographFk).toEqual(thermographId);
|
|
||||||
expect(travelThermographBefore.travelFk).toBeNull();
|
|
||||||
expect(travelThermographAfter).toBeDefined();
|
|
||||||
|
|
||||||
expect(travelThermographAfter.thermographFk).toEqual(thermographId);
|
|
||||||
expect(travelThermographAfter.travelFk).toEqual(travelId);
|
|
||||||
expect(travelThermographAfter.dmsFk).toEqual(5);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('Thermograph saveThermograph()', () => {
|
||||||
|
const ctx = beforeAll.getCtx();
|
||||||
|
const travelFk = 1;
|
||||||
|
const thermographId = '138350-0';
|
||||||
|
const warehouseFk = '1';
|
||||||
|
const state = 'COMPLETED';
|
||||||
|
const maxTemperature = 30;
|
||||||
|
const minTemperature = 10;
|
||||||
|
const temperatureFk = 'COOL';
|
||||||
|
let tx;
|
||||||
|
let options;
|
||||||
|
|
||||||
|
beforeEach(async() => {
|
||||||
|
options = {transaction: tx};
|
||||||
|
tx = await models.Sale.beginTransaction({});
|
||||||
|
options.transaction = tx;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async() => {
|
||||||
|
await tx.rollback();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update an existing travel thermograph', async() => {
|
||||||
|
const dmsFk = 5;
|
||||||
|
spyOn(models.Dms, 'uploadFile').and.returnValue([{id: dmsFk}]);
|
||||||
|
|
||||||
|
const travelThermograph = await models.TravelThermograph.create({
|
||||||
|
travelFk,
|
||||||
|
thermographFk: thermographId,
|
||||||
|
temperatureFk,
|
||||||
|
warehouseFk,
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
const updatedThermograph = await models.Travel.saveThermograph(
|
||||||
|
ctx,
|
||||||
|
travelFk,
|
||||||
|
travelThermograph.id,
|
||||||
|
state,
|
||||||
|
maxTemperature,
|
||||||
|
minTemperature,
|
||||||
|
temperatureFk,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null, options
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(updatedThermograph.result).toEqual(state);
|
||||||
|
expect(updatedThermograph.maxTemperature).toEqual(maxTemperature);
|
||||||
|
expect(updatedThermograph.minTemperature).toEqual(minTemperature);
|
||||||
|
expect(updatedThermograph.temperatureFk).toEqual(temperatureFk);
|
||||||
|
expect(updatedThermograph.dmsFk).toEqual(dmsFk);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if no valid travel thermograph is found', async() => {
|
||||||
|
try {
|
||||||
|
await models.Travel.saveThermograph(
|
||||||
|
ctx, null, 'notExists', state, maxTemperature, minTemperature, temperatureFk, options
|
||||||
|
);
|
||||||
|
fail('Expected an error to be thrown when no valid travel thermograph is found');
|
||||||
|
} catch (e) {
|
||||||
|
expect(e.message).toBe('No valid travel thermograph found');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,83 +0,0 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethodCtx('updateThermograph', {
|
|
||||||
description: 'Updates a travel thermograph',
|
|
||||||
accessType: 'WRITE',
|
|
||||||
accepts: [{
|
|
||||||
arg: 'id',
|
|
||||||
type: 'Number',
|
|
||||||
description: 'The travel id',
|
|
||||||
http: {source: 'path'}
|
|
||||||
}, {
|
|
||||||
arg: 'thermographId',
|
|
||||||
type: 'String',
|
|
||||||
description: 'The thermograph id',
|
|
||||||
required: true
|
|
||||||
}, {
|
|
||||||
arg: 'state',
|
|
||||||
type: 'String',
|
|
||||||
required: true
|
|
||||||
}, {
|
|
||||||
arg: 'warehouseId',
|
|
||||||
type: 'Number',
|
|
||||||
description: 'The warehouse id'
|
|
||||||
}, {
|
|
||||||
arg: 'companyId',
|
|
||||||
type: 'Number',
|
|
||||||
description: 'The company id'
|
|
||||||
}, {
|
|
||||||
arg: 'dmsTypeId',
|
|
||||||
type: 'Number',
|
|
||||||
description: 'The dms type id'
|
|
||||||
}, {
|
|
||||||
arg: 'reference',
|
|
||||||
type: 'String'
|
|
||||||
}, {
|
|
||||||
arg: 'description',
|
|
||||||
type: 'String'
|
|
||||||
}, {
|
|
||||||
arg: 'hasFileAttached',
|
|
||||||
type: 'Boolean',
|
|
||||||
description: 'True if has an attached file'
|
|
||||||
}],
|
|
||||||
returns: {
|
|
||||||
type: 'Object',
|
|
||||||
root: true
|
|
||||||
},
|
|
||||||
http: {
|
|
||||||
path: `/:id/updateThermograph`,
|
|
||||||
verb: 'POST'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.updateThermograph = async(ctx, id, thermographId, state) => {
|
|
||||||
const models = Self.app.models;
|
|
||||||
const tx = await Self.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
const travelThermograph = await models.TravelThermograph.findOne({
|
|
||||||
where: {
|
|
||||||
thermographFk: thermographId,
|
|
||||||
travelFk: id
|
|
||||||
}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
if (!travelThermograph)
|
|
||||||
throw new UserError('No valid travel thermograph found');
|
|
||||||
|
|
||||||
const dmsFk = travelThermograph.dmsFk;
|
|
||||||
await models.Dms.updateFile(ctx, dmsFk, options);
|
|
||||||
await travelThermograph.updateAttributes({
|
|
||||||
result: state
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
await tx.commit();
|
|
||||||
return travelThermograph;
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -28,6 +28,14 @@
|
||||||
"warehouseFk": {
|
"warehouseFk": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"required": true
|
"required": true
|
||||||
|
},
|
||||||
|
"maxTemperature": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Maximum temperature"
|
||||||
|
},
|
||||||
|
"minTemperature": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Minimum temperature"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -4,9 +4,8 @@ module.exports = Self => {
|
||||||
require('../methods/travel/getTravel')(Self);
|
require('../methods/travel/getTravel')(Self);
|
||||||
require('../methods/travel/getEntries')(Self);
|
require('../methods/travel/getEntries')(Self);
|
||||||
require('../methods/travel/filter')(Self);
|
require('../methods/travel/filter')(Self);
|
||||||
require('../methods/travel/createThermograph')(Self);
|
|
||||||
require('../methods/travel/deleteThermograph')(Self);
|
require('../methods/travel/deleteThermograph')(Self);
|
||||||
require('../methods/travel/updateThermograph')(Self);
|
require('../methods/travel/saveThermograph')(Self);
|
||||||
require('../methods/travel/extraCommunityFilter')(Self);
|
require('../methods/travel/extraCommunityFilter')(Self);
|
||||||
require('../methods/travel/getAverageDays')(Self);
|
require('../methods/travel/getAverageDays')(Self);
|
||||||
require('../methods/travel/cloneWithEntries')(Self);
|
require('../methods/travel/cloneWithEntries')(Self);
|
||||||
|
|
|
@ -87,7 +87,7 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
const query = `Travels/${this.travel.id}/createThermograph`;
|
const query = `Travels/${this.travel.id}/saveThermograph`;
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: query,
|
url: query,
|
||||||
|
|
|
@ -34,7 +34,7 @@ class Controller extends Section {
|
||||||
const filter = encodeURIComponent(JSON.stringify(filterObj));
|
const filter = encodeURIComponent(JSON.stringify(filterObj));
|
||||||
const path = `TravelThermographs/${this.$params.thermographId}?filter=${filter}`;
|
const path = `TravelThermographs/${this.$params.thermographId}?filter=${filter}`;
|
||||||
this.$http.get(path).then(res => {
|
this.$http.get(path).then(res => {
|
||||||
const thermograph = res.data && res.data;
|
const thermograph = res.data;
|
||||||
this.thermograph = {
|
this.thermograph = {
|
||||||
thermographId: thermograph.thermographFk,
|
thermographId: thermograph.thermographFk,
|
||||||
state: thermograph.result,
|
state: thermograph.result,
|
||||||
|
@ -51,7 +51,7 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
const query = `travels/${this.$params.id}/updateThermograph`;
|
const query = `travels/${this.$params.id}/saveThermograph`;
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: query,
|
url: query,
|
||||||
|
@ -62,8 +62,8 @@ class Controller extends Section {
|
||||||
transformRequest: files => {
|
transformRequest: files => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
for (let i = 0; i < files.length; i++)
|
for (const element of files)
|
||||||
formData.append(files[i].name, files[i]);
|
formData.append(element.name, element);
|
||||||
|
|
||||||
return formData;
|
return formData;
|
||||||
},
|
},
|
||||||
|
|
|
@ -109,7 +109,7 @@ describe('Worker', () => {
|
||||||
const files = [{id: 1, name: 'MyFile'}];
|
const files = [{id: 1, name: 'MyFile'}];
|
||||||
controller.thermograph = {files};
|
controller.thermograph = {files};
|
||||||
const serializedParams = $httpParamSerializer(controller.thermograph);
|
const serializedParams = $httpParamSerializer(controller.thermograph);
|
||||||
const query = `travels/${controller.$params.id}/updateThermograph?${serializedParams}`;
|
const query = `travels/${controller.$params.id}/saveThermograph?${serializedParams}`;
|
||||||
|
|
||||||
$httpBackend.expect('POST', query).respond({});
|
$httpBackend.expect('POST', query).respond({});
|
||||||
controller.onSubmit();
|
controller.onSubmit();
|
||||||
|
|
Loading…
Reference in New Issue