61 lines
1.7 KiB
JavaScript
61 lines
1.7 KiB
JavaScript
|
module.exports = Self => {
|
||
|
Self.remoteMethod('createThermograph', {
|
||
|
description: 'Creates a new thermograph',
|
||
|
accessType: 'WRITE',
|
||
|
accepts: [{
|
||
|
arg: 'thermographId',
|
||
|
type: 'String',
|
||
|
description: 'The thermograph id',
|
||
|
required: true
|
||
|
}, {
|
||
|
arg: 'model',
|
||
|
type: 'String',
|
||
|
description: 'The thermograph model',
|
||
|
required: true
|
||
|
}, {
|
||
|
arg: 'temperature',
|
||
|
type: 'String',
|
||
|
description: 'The thermograph temperature',
|
||
|
required: true
|
||
|
}, {
|
||
|
arg: 'warehouseId',
|
||
|
type: 'Number',
|
||
|
description: 'The warehouse id',
|
||
|
required: true
|
||
|
}],
|
||
|
returns: {
|
||
|
type: 'Object',
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/createThermograph`,
|
||
|
verb: 'POST'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.createThermograph = async(thermographId, model, temperature, warehouseId) => {
|
||
|
const models = Self.app.models;
|
||
|
const tx = await Self.beginTransaction({});
|
||
|
|
||
|
try {
|
||
|
const options = {transaction: tx};
|
||
|
const thermograph = await models.Thermograph.create({
|
||
|
id: thermographId,
|
||
|
model: model
|
||
|
}, options);
|
||
|
|
||
|
await Self.rawSql(`
|
||
|
INSERT INTO travelThermograph(thermographFk, warehouseFk, temperature, created)
|
||
|
VALUES (?, ?,?, NOW())
|
||
|
`, [thermograph.id, warehouseId, temperature], options);
|
||
|
|
||
|
await tx.commit();
|
||
|
|
||
|
return thermograph;
|
||
|
} catch (err) {
|
||
|
await tx.rollback();
|
||
|
throw err;
|
||
|
}
|
||
|
};
|
||
|
};
|