Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Peter Lundin
cmdb
Commits
91d2c01b
Commit
91d2c01b
authored
Dec 22, 2017
by
Peter Lundin
Browse files
Delete options.js
parent
c17047b6
Changes
1
Hide whitespace changes
Inline
Side-by-side
routes/options.js
deleted
100644 → 0
View file @
c17047b6
var
express
=
require
(
'
express
'
);
var
router
=
express
.
Router
();
const
jQuery
=
require
(
'
jquery
'
);
const
path
=
require
(
'
path
'
);
const
config
=
require
(
'
./config
'
);
const
pg
=
require
(
'
pg
'
);
const
winston
=
require
(
'
winston
'
);
const
connectionString
=
process
.
env
.
DATABASE_URL
||
config
.
storageConfig
;
router
.
post
(
'
/family_type
'
,
(
req
,
res
,
next
)
=>
{
var
pool
=
new
pg
.
Pool
({
connectionString
:
connectionString
,
});
// Get a Postgres client from the connection pool
pool
.
connect
(
function
(
err
,
client
,
done
){
// Handle connection errors
if
(
err
)
{
done
();
return
res
.
status
(
500
).
json
({
success
:
false
,
data
:
err
});
}
var
sql
=
"
select display_name as
\"
DisplayText
\"
, id as
\"
Value
\"
from cmdb.family_type;
"
;
client
.
query
(
sql
,
[],
function
(
err
,
result
){
done
();
if
(
err
){
return
res
.
json
(
JSON
.
parse
(
'
{"Result":"ERROR", "Message":"
'
+
sql
+
'
"}
'
));
}
else
{
var
response
=
'
{"Result":"OK", "Options":
'
;
response
+=
JSON
.
stringify
(
result
.
rows
);
response
+=
'
,"TotalRecordCount":
'
+
result
.
rowCount
+
'
}
'
;
return
res
.
json
(
JSON
.
parse
(
response
));
}
});
});
});
router
.
post
(
'
/parent
'
,
(
req
,
res
,
next
)
=>
{
var
pool
=
new
pg
.
Pool
({
connectionString
:
connectionString
,
});
// Get a Postgres client from the connection pool
pool
.
connect
(
function
(
err
,
client
,
done
){
// Handle connection errors
if
(
err
)
{
done
();
return
res
.
status
(
500
).
json
({
success
:
false
,
data
:
err
});
}
var
sql
=
"
select display_name as
\"
DisplayText
\"
, id as
\"
Value
\"
from cmdb.ci;
"
;
client
.
query
(
sql
,
[],
function
(
err
,
result
){
done
();
if
(
err
){
return
res
.
json
(
JSON
.
parse
(
'
{"Result":"ERROR", "Message":"
'
+
sql
+
'
"}
'
));
}
else
{
var
response
=
'
{"Result":"OK", "Options":
'
;
response
+=
JSON
.
stringify
(
result
.
rows
);
response
+=
'
,"TotalRecordCount":
'
+
result
.
rowCount
+
'
}
'
;
return
res
.
json
(
JSON
.
parse
(
response
));
}
});
});
});
router
.
post
(
'
/families/:family_type_id
'
,
(
req
,
res
,
next
)
=>
{
var
pool
=
new
pg
.
Pool
({
connectionString
:
connectionString
,
});
// Get a Postgres client from the connection pool
pool
.
connect
(
function
(
err
,
client
,
done
){
// Handle connection errors
if
(
err
)
{
done
();
return
res
.
status
(
500
).
json
({
success
:
false
,
data
:
err
});
}
// SQL Query > Select Data
var
sql
=
"
select display_name as
\"
DisplayText
\"
, id as
\"
Value
\"
from cmdb.family where family_type_id=$1;
"
;
var
parameters
=
req
.
params
[
'
family_type_id
'
];
client
.
query
(
sql
,
[
parameters
],
function
(
err
,
result
){
done
();
if
(
err
){
return
res
.
json
(
JSON
.
parse
(
'
{"Result":"ERROR", "Message":"
'
+
sql
+
'
"}
'
));
}
else
{
var
response
=
'
{"Result":"OK", "Options":
'
;
response
+=
JSON
.
stringify
(
result
.
rows
);
response
+=
'
,"TotalRecordCount":
'
+
result
.
rowCount
+
'
}
'
;
return
res
.
json
(
JSON
.
parse
(
response
));
}
});
});
});
router
.
post
(
'
/families
'
,
(
req
,
res
,
next
)
=>
{
var
pool
=
new
pg
.
Pool
({
connectionString
:
connectionString
,
});
// Get a Postgres client from the connection pool
pool
.
connect
(
function
(
err
,
client
,
done
){
// Handle connection errors
if
(
err
)
{
done
();
return
res
.
status
(
500
).
json
({
success
:
false
,
data
:
err
});
}
// SQL Query > Select Data
var
sql
=
"
select display_name as
\"
DisplayText
\"
, id as
\"
Value
\"
from cmdb.family;
"
;
var
parameters
=
req
.
params
[
'
family_type
'
];
client
.
query
(
sql
,
[],
function
(
err
,
result
){
done
();
if
(
err
){
return
res
.
json
(
JSON
.
parse
(
'
{"Result":"ERROR", "Message":"
'
+
sql
+
'
"}
'
));
}
else
{
var
response
=
'
{"Result":"OK", "Options":
'
;
response
+=
JSON
.
stringify
(
result
.
rows
);
response
+=
'
,"TotalRecordCount":
'
+
result
.
rowCount
+
'
}
'
;
return
res
.
json
(
JSON
.
parse
(
response
));
}
});
});
});
router
.
post
(
'
/classes
'
,
(
req
,
res
,
next
)
=>
{
var
pool
=
new
pg
.
Pool
({
connectionString
:
connectionString
,
});
// Get a Postgres client from the connection pool
pool
.
connect
(
function
(
err
,
client
,
done
){
// Handle connection errors
if
(
err
)
{
done
();
return
res
.
status
(
500
).
json
({
success
:
false
,
data
:
err
});
}
// SQL Query > Select Data
var
sql
=
"
select display_name as
\"
DisplayText
\"
, id as
\"
Value
\"
from cmdb.class;
"
;
var
parameters
=
req
.
params
[
'
class_type
'
];
client
.
query
(
sql
,
[],
function
(
err
,
result
){
done
();
if
(
err
){
return
res
.
json
(
JSON
.
parse
(
'
{"Result":"ERROR", "Message":"
'
+
sql
+
'
"}
'
));
}
else
{
var
response
=
'
{"Result":"OK", "Options":
'
;
response
+=
JSON
.
stringify
(
result
.
rows
);
response
+=
'
,"TotalRecordCount":
'
+
result
.
rowCount
+
'
}
'
;
return
res
.
json
(
JSON
.
parse
(
response
));
}
});
});
});
router
.
post
(
'
/classes/:class_type
'
,
(
req
,
res
,
next
)
=>
{
var
pool
=
new
pg
.
Pool
({
connectionString
:
connectionString
,
});
// Get a Postgres client from the connection pool
pool
.
connect
(
function
(
err
,
client
,
done
){
// Handle connection errors
if
(
err
)
{
done
();
return
res
.
status
(
500
).
json
({
success
:
false
,
data
:
err
});
}
// SQL Query > Select Data
var
sql
=
"
select display_name as
\"
DisplayText
\"
, id as
\"
Value
\"
from cmdb.class where class_type_id = $1;
"
;
var
parameters
=
req
.
params
[
'
class_type
'
];
client
.
query
(
sql
,
[
parameters
],
function
(
err
,
result
){
done
();
if
(
err
){
return
res
.
json
(
JSON
.
parse
(
'
{"Result":"ERROR", "Message":"
'
+
sql
+
'
"}
'
));
}
else
{
var
response
=
'
{"Result":"OK", "Options":
'
;
response
+=
JSON
.
stringify
(
result
.
rows
);
response
+=
'
,"TotalRecordCount":
'
+
result
.
rowCount
+
'
}
'
;
return
res
.
json
(
JSON
.
parse
(
response
));
}
});
});
});
module
.
exports
=
router
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment