Make Plans: the Code
1
const
pgp
=
require
(
'pg-promise'
)();
2
function
main
(
params
)
{
3
var
postgres_url
=
params
[
'__bx_creds'
][
'compose-for-postgresql'
][
'uri'
];
4
var
base_url
=
params
[
'__ow_headers'
][
'x-forwarded-url'
];
5
return
new
Promise
(
function
(
resolve
,
reject
)
{
6
db
=
pgp
(
postgres_url
,
[]);
7
8
db
.
one
(
"INSERT INTO plans (location, travel_date) VALUES
9
($1, $2) RETURNING plan_id"
,
10
[
location
,
travel_date
])
11
.
then
(
function
(
data
)
{
12
var
redirect_to
=
base_url
"/"
data
.
plan_id
;
13
resolve
({
headers
:
{
"Location"
:
redirect_to
},
14
statusCode
:
303
})
15
})
@lornajane