2019-03-12 14:04:09 +00:00
|
|
|
|
|
|
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
|
|
|
|
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('nodeAdd', {
|
|
|
|
description: 'Returns the first shipped and landed possible for params',
|
2019-05-22 10:35:24 +00:00
|
|
|
accessType: 'WRITE',
|
2019-03-12 14:04:09 +00:00
|
|
|
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(
|
2019-04-29 09:49:43 +00:00
|
|
|
`CALL nst.nodeAdd('vn', 'department', ?, ?)`, [parentFk, name])) - 1;
|
2019-03-12 14:04:09 +00:00
|
|
|
|
|
|
|
stmts.push(`CALL nst.nodeRecalc('vn', 'department')`);
|
|
|
|
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let result = await conn.executeStmt(sql);
|
|
|
|
let [node] = result[nodeIndex];
|
|
|
|
|
|
|
|
return node;
|
|
|
|
};
|
|
|
|
};
|