2020-05-27 11:11:41 +00:00
|
|
|
module.exports = Self => {
|
2023-06-01 06:32:06 +00:00
|
|
|
Self.remoteMethodCtx('createThermograph', {
|
2020-05-27 11:11:41 +00:00
|
|
|
description: 'Creates a new thermograph',
|
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'thermographId',
|
2021-09-06 14:38:27 +00:00
|
|
|
type: 'string',
|
2020-05-27 11:11:41 +00:00
|
|
|
description: 'The thermograph id',
|
|
|
|
required: true
|
2021-09-06 14:38:27 +00:00
|
|
|
},
|
|
|
|
{
|
2020-05-27 11:11:41 +00:00
|
|
|
arg: 'model',
|
2021-09-06 14:38:27 +00:00
|
|
|
type: 'string',
|
2020-05-27 11:11:41 +00:00
|
|
|
description: 'The thermograph model',
|
|
|
|
required: true
|
2021-09-06 14:38:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'temperatureFk',
|
|
|
|
type: 'string',
|
2020-05-27 11:11:41 +00:00
|
|
|
description: 'The thermograph temperature',
|
|
|
|
required: true
|
2021-09-06 14:38:27 +00:00
|
|
|
},
|
|
|
|
{
|
2020-05-27 11:11:41 +00:00
|
|
|
arg: 'warehouseId',
|
2021-09-06 14:38:27 +00:00
|
|
|
type: 'number',
|
2020-05-27 11:11:41 +00:00
|
|
|
description: 'The warehouse id',
|
|
|
|
required: true
|
|
|
|
}],
|
|
|
|
returns: {
|
2021-09-06 14:38:27 +00:00
|
|
|
type: 'object',
|
2020-05-27 11:11:41 +00:00
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/createThermograph`,
|
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-06-01 06:32:06 +00:00
|
|
|
Self.createThermograph = async(ctx, thermographId, model, temperatureFk, warehouseId, options) => {
|
2020-05-27 11:11:41 +00:00
|
|
|
const models = Self.app.models;
|
2021-09-06 14:38:27 +00:00
|
|
|
let tx;
|
2023-06-01 06:32:06 +00:00
|
|
|
const myOptions = {userId: ctx.req.accessToken.userId};
|
2023-01-16 14:18:24 +00:00
|
|
|
const date = Date.vnNew();
|
2021-09-06 14:38:27 +00:00
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
|
|
|
if (!myOptions.transaction) {
|
|
|
|
tx = await Self.beginTransaction({});
|
|
|
|
myOptions.transaction = tx;
|
|
|
|
}
|
2020-05-27 11:11:41 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
const thermograph = await models.Thermograph.create({
|
|
|
|
id: thermographId,
|
|
|
|
model: model
|
2021-09-06 14:38:27 +00:00
|
|
|
}, myOptions);
|
2020-05-27 11:11:41 +00:00
|
|
|
|
|
|
|
await Self.rawSql(`
|
2021-09-06 14:38:27 +00:00
|
|
|
INSERT INTO travelThermograph(thermographFk, warehouseFk, temperatureFk, created)
|
2022-06-09 11:33:01 +00:00
|
|
|
VALUES (?, ?, ?, ?)
|
|
|
|
`, [thermograph.id, warehouseId, temperatureFk, date], myOptions);
|
2020-05-27 11:11:41 +00:00
|
|
|
|
2021-09-06 14:38:27 +00:00
|
|
|
if (tx) await tx.commit();
|
2020-05-27 11:11:41 +00:00
|
|
|
|
|
|
|
return thermograph;
|
|
|
|
} catch (err) {
|
2021-09-06 14:38:27 +00:00
|
|
|
if (tx) await tx.rollback();
|
2020-05-27 11:11:41 +00:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|