44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
|
|
||
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||
|
|
||
|
module.exports = Self => {
|
||
|
Self.remoteMethod('nodeAdd', {
|
||
|
description: 'Returns the first shipped and landed possible for params',
|
||
|
accessType: '',
|
||
|
accepts: [{
|
||
|
arg: 'parentFk',
|
||
|
type: 'Number',
|
||
|
required: false,
|
||
|
},
|
||
|
{
|
||
|
arg: 'name',
|
||
|
type: 'String',
|
||
|
required: true,
|
||
|
}],
|
||
|
returns: {
|
||
|
type: 'object',
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/nodeAdd`,
|
||
|
verb: 'POST'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.nodeAdd = async(parentFk = 1, name) => {
|
||
|
let stmts = [];
|
||
|
let conn = Self.dataSource.connector;
|
||
|
let nodeIndex = stmts.push(new ParameterizedSQL(
|
||
|
`CALL nst.NodeAdd('vn', 'department', ?, ?)`, [parentFk, name])) - 1;
|
||
|
|
||
|
stmts.push(`CALL nst.nodeRecalc('vn', 'department')`);
|
||
|
|
||
|
|
||
|
let sql = ParameterizedSQL.join(stmts, ';');
|
||
|
let result = await conn.executeStmt(sql);
|
||
|
let [node] = result[nodeIndex];
|
||
|
|
||
|
return node;
|
||
|
};
|
||
|
};
|