From 35f6eebeb631a5ef944d331e2194bbd02fc7f5bf Mon Sep 17 00:00:00 2001 From: Dominic H Date: Thu, 15 Aug 2019 14:28:27 +0100 Subject: [PATCH 1/5] Sustainability sub categories for launch #360 - Tested on local db --- migrations/011.sustainability.down.sql | 26 ++++++++++++ migrations/012.sustainability.up.sql | 58 ++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 migrations/011.sustainability.down.sql create mode 100644 migrations/012.sustainability.up.sql diff --git a/migrations/011.sustainability.down.sql b/migrations/011.sustainability.down.sql new file mode 100644 index 00000000..252ed0b3 --- /dev/null +++ b/migrations/011.sustainability.down.sql @@ -0,0 +1,26 @@ +-- Remove sustainability fields, update in paralell with adding new fields +-- BREEAM rating +ALTER TABLE buildings DROP COLUMN IF EXISTS sust_breeam_rating; +-- BREEAM date +ALTER TABLE buildings DROP COLUMN IF EXISTS sust_breeam_date; + +-- DEC (display energy certifcate, only applies to non domestic buildings) +ALTER TABLE buildings DROP COLUMN IF EXISTS sust_dec; +-- DEC date +ALTER TABLE buildings DROP COLUMN IF EXISTS sust_dec_date; + +--TODO: DEC certifcate number, is there an online store for these? + +-- Aggregate EPC rating (Estimated) for a building, derived from inidividual certificates +ALTER TABLE buildings DROP COLUMN IF EXISTS sust_aggregate_estimate_epc; + +-- Last significant retrofit date YYYY +ALTER TABLE buildings DROP COLUMN IF EXISTS sust_retrofit_date; + +--TODO : Embodied carbon + +--TODO : Life expectancy minimum + +--TODO : Average lifespan for typology + +--TODO : Adaptability rating diff --git a/migrations/012.sustainability.up.sql b/migrations/012.sustainability.up.sql new file mode 100644 index 00000000..1be3da7f --- /dev/null +++ b/migrations/012.sustainability.up.sql @@ -0,0 +1,58 @@ +-- BREEAM ratings, one of: +-- - Outstanding +-- - Excellent +-- - Very good +-- - Good +-- - Pass +-- - Unclassified +CREATE TYPE sust_breeam_rating +AS ENUM ('Outstanding', + 'Excellent', + 'Very good', + 'Good', + 'Pass', + 'Unclassified'); + +ALTER TABLE buildings + ADD COLUMN IF NOT EXISTS sust_breeam_rating sust_breeam_rating DEFAULT 'Unclassified'; + +-- Date of BREEAM +ALTER TABLE buildings + ADD COLUMN IF NOT EXISTS sust_breeam_date smallint; + +-- DEC (display energy certifcate, only applies to non domestic buildings) +-- A - G +CREATE TYPE sust_dec +AS ENUM ('A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G'); + +-- Date of DEC YYYY +ALTER TABLE buildings + ADD COLUMN IF NOT EXISTS sust_dec_date smallint; + + +ALTER TABLE buildings + ADD COLUMN IF NOT EXISTS sust_dec sust_dec; + +-- Aggregate EPC rating (Estimated) for a building, derived from inidividual certificates +-- A+ - G +CREATE TYPE sust_aggregate_estimate_epc +AS ENUM ('A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G'); + +ALTER TABLE buildings + ADD COLUMN IF NOT EXISTS sust_aggregate_estimate_epc sust_aggregate_estimate_epc; + +-- Last significant retrofit date YYYY +ALTER TABLE buildings + ADD COLUMN IF NOT EXISTS sust_retrofit_date smallint; From 7cc358dcb7c1153bedc89730a890537014b50899 Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Thu, 22 Aug 2019 15:56:04 +0100 Subject: [PATCH 2/5] Introduce env variable for webapp origin --- app/src/api/controllers/userController.ts | 11 +++++++++-- ecosystem.config.dev-template.js | 1 + ecosystem.config.template.js | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/api/controllers/userController.ts b/app/src/api/controllers/userController.ts index 9a2b1004..ecde5ee9 100644 --- a/app/src/api/controllers/userController.ts +++ b/app/src/api/controllers/userController.ts @@ -72,8 +72,7 @@ async function resetPassword(req: express.Request, res: express.Response) { if(req.body.email != undefined) { // first stage: send reset token to email address - // this relies on the API being on the same hostname as the frontend - const { origin } = new URL(req.protocol + '://' + req.headers.host); + const origin = getWebAppOrigin(); await passwordResetService.sendPasswordResetToken(req.body.email, origin); return res.status(202).send({ success: true }); @@ -96,6 +95,14 @@ async function resetPassword(req: express.Request, res: express.Response) { } } +function getWebAppOrigin() : string { + const origin = process.env.WEBAPP_ORIGIN; + if (origin == undefined) { + throw new Error('WEBAPP_ORIGIN not defined'); + } + return origin; +} + export default { createUser, getCurrentUser, diff --git a/ecosystem.config.dev-template.js b/ecosystem.config.dev-template.js index 02e13a4f..5c26ec70 100644 --- a/ecosystem.config.dev-template.js +++ b/ecosystem.config.dev-template.js @@ -25,6 +25,7 @@ module.exports = { MAIL_SERVER_PORT: 587, MAIL_SERVER_USER: "mail_username", MAIL_SERVER_PASSWORD: "longrandompassword", + WEBAPP_ORIGIN: "http://localhost:3000", } } ] diff --git a/ecosystem.config.template.js b/ecosystem.config.template.js index 695440d5..34b454d7 100644 --- a/ecosystem.config.template.js +++ b/ecosystem.config.template.js @@ -22,6 +22,7 @@ module.exports = { MAIL_SERVER_PORT: 587, MAIL_SERVER_USER: "mail_username", MAIL_SERVER_PASSWORD: "longrandompassword", + WEBAPP_ORIGIN: "https://beta.colouring.london", } } ] From ac233dced1b70244749dbc18846c8bcfeb755411 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Aug 2019 09:55:24 +0000 Subject: [PATCH 3/5] Bump connect-pg-simple from 5.0.0 to 6.0.1 in /app Bumps [connect-pg-simple](https://github.com/voxpelli/node-connect-pg-simple) from 5.0.0 to 6.0.1. - [Release notes](https://github.com/voxpelli/node-connect-pg-simple/releases) - [Changelog](https://github.com/voxpelli/node-connect-pg-simple/blob/master/CHANGELOG.md) - [Commits](https://github.com/voxpelli/node-connect-pg-simple/compare/v5.0.0...v6.0.1) Signed-off-by: dependabot[bot] --- app/package-lock.json | 118 ++++++++++++++++++++++++------------------ app/package.json | 2 +- 2 files changed, 70 insertions(+), 50 deletions(-) diff --git a/app/package-lock.json b/app/package-lock.json index 3c6c3b3d..50274133 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -2875,9 +2875,9 @@ "dev": true }, "buffer-writer": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-1.0.1.tgz", - "integrity": "sha1-Iqk2kB4wKa/NdUfrRIfOtpejvwg=" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz", + "integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==" }, "buffer-xor": { "version": "1.0.3", @@ -3439,11 +3439,11 @@ "dev": true }, "connect-pg-simple": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/connect-pg-simple/-/connect-pg-simple-5.0.0.tgz", - "integrity": "sha512-WZ7xkN+qe5bbDLgZ1L9GxnSbr155cJHmfNRzVR5hBvqio7Pg/vuH7Cf8lPUSFClQjtybYSejUqyO54sYt4cg+w==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/connect-pg-simple/-/connect-pg-simple-6.0.1.tgz", + "integrity": "sha512-zW5AOtRNOLcXxphSmQ+oYj0snlLs1Je3u5K2NWyF7WhMVoPvnQXraK2wzS8f7qLwhMcmYukah2ymu0Gdxf7Qsg==", "requires": { - "pg": "7.4.3" + "pg": "^7.4.3" } }, "consola": { @@ -6349,7 +6349,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -6370,12 +6371,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "1.0.0", "concat-map": "0.0.1" @@ -6390,17 +6393,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -6517,7 +6523,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -6529,6 +6536,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "1.0.1" } @@ -6543,6 +6551,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "1.1.11" } @@ -6550,12 +6559,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "5.1.2", "yallist": "3.0.3" @@ -6574,6 +6585,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -6654,7 +6666,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -6666,6 +6679,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1.0.2" } @@ -6751,7 +6765,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -6787,6 +6802,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "1.1.0", "is-fullwidth-code-point": "1.0.0", @@ -6806,6 +6822,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "2.1.1" } @@ -6849,12 +6866,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -9462,7 +9481,7 @@ }, "minimist": { "version": "0.0.8", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" }, "minipass": { @@ -10214,9 +10233,9 @@ "dev": true }, "packet-reader": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-0.3.1.tgz", - "integrity": "sha1-zWLmCvjX/qinBexP+ZCHHEaHHyc=" + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz", + "integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==" }, "pako": { "version": "1.0.10", @@ -10388,16 +10407,16 @@ "dev": true }, "pg": { - "version": "7.4.3", - "resolved": "https://registry.npmjs.org/pg/-/pg-7.4.3.tgz", - "integrity": "sha1-97b5P1NA7MJZavu5ShPj1rYJg0s=", + "version": "7.12.1", + "resolved": "https://registry.npmjs.org/pg/-/pg-7.12.1.tgz", + "integrity": "sha512-l1UuyfEvoswYfcUe6k+JaxiN+5vkOgYcVSbSuw3FvdLqDbaoa2RJo1zfJKfPsSYPFVERd4GHvX3s2PjG1asSDA==", "requires": { - "buffer-writer": "1.0.1", - "packet-reader": "0.3.1", + "buffer-writer": "2.0.0", + "packet-reader": "1.0.0", "pg-connection-string": "0.1.3", - "pg-pool": "2.0.3", - "pg-types": "1.12.1", - "pgpass": "1.0.2", + "pg-pool": "^2.0.4", + "pg-types": "^2.1.0", + "pgpass": "1.x", "semver": "4.3.2" }, "dependencies": { @@ -10424,9 +10443,9 @@ "integrity": "sha512-8aZ9xdx7Pe/ppFYVOqvU5KgmM6ttXjaBlsl9Y8yzrUH4xSNVucJKKOwm4Y4H+LCvzZGjZIm4Rkf2Ajt5ixtkBQ==" }, "pg-pool": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.3.tgz", - "integrity": "sha1-wCIDLIlJ8xKk+R+2QJzgQHa+Mlc=" + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.7.tgz", + "integrity": "sha512-UiJyO5B9zZpu32GSlP0tXy8J2NsJ9EFGFfz5v6PSbdz/1hBLX1rNiiy5+mAm5iJJYwfCv4A0EBcQLGWwjbpzZw==" }, "pg-promise": { "version": "8.7.5", @@ -10499,14 +10518,15 @@ } }, "pg-types": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-1.12.1.tgz", - "integrity": "sha1-1kCH45A7WP+q0nnnWVxSIIoUw9I=", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", + "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", "requires": { - "postgres-array": "1.0.2", - "postgres-bytea": "1.0.0", - "postgres-date": "1.0.3", - "postgres-interval": "1.1.2" + "pg-int8": "1.0.1", + "postgres-array": "~2.0.0", + "postgres-bytea": "~1.0.0", + "postgres-date": "~1.0.4", + "postgres-interval": "^1.1.0" } }, "pgpass": { @@ -13122,9 +13142,9 @@ } }, "postgres-array": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-1.0.2.tgz", - "integrity": "sha1-jgsy6wO/d6XAp4UeBEHBaaJWojg=" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", + "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==" }, "postgres-bytea": { "version": "1.0.0", @@ -13132,9 +13152,9 @@ "integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU=" }, "postgres-date": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.3.tgz", - "integrity": "sha1-4tiXAu/bJY/52c7g/pG9BpdSV6g=" + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.4.tgz", + "integrity": "sha512-bESRvKVuTrjoBluEcpv2346+6kgB7UlnqWZsnbnCccTNq/pqfj1j6oBaN5+b/NrDXepYUT/HKadqv3iS9lJuVA==" }, "postgres-interval": { "version": "1.1.2", @@ -13590,7 +13610,7 @@ "dependencies": { "minimist": { "version": "1.2.0", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" } } @@ -16999,7 +17019,7 @@ "dependencies": { "minimist": { "version": "1.2.0", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true } @@ -17840,7 +17860,7 @@ }, "wrap-ansi": { "version": "2.1.0", - "resolved": "http://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", "dev": true, "requires": { diff --git a/app/package.json b/app/package.json index 24d15a57..f9e2c505 100644 --- a/app/package.json +++ b/app/package.json @@ -18,7 +18,7 @@ "@mapbox/sphericalmercator": "^1.1.0", "body-parser": "^1.19.0", "bootstrap": "^4.3.1", - "connect-pg-simple": "^5.0.0", + "connect-pg-simple": "^6.0.1", "express": "^4.17.1", "express-session": "^1.16.2", "leaflet": "^1.5.1", From 21c2c6cccc3aad1353002626a3a527f0db3c07bc Mon Sep 17 00:00:00 2001 From: Dominic H Date: Thu, 29 Aug 2019 16:13:09 +0100 Subject: [PATCH 4/5] Addresses review comments for #360 --- migrations/011.sustainability.down.sql | 14 ++++++++------ migrations/012.sustainability.up.sql | 9 +++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/migrations/011.sustainability.down.sql b/migrations/011.sustainability.down.sql index 252ed0b3..8cdf14eb 100644 --- a/migrations/011.sustainability.down.sql +++ b/migrations/011.sustainability.down.sql @@ -9,7 +9,8 @@ ALTER TABLE buildings DROP COLUMN IF EXISTS sust_dec; -- DEC date ALTER TABLE buildings DROP COLUMN IF EXISTS sust_dec_date; ---TODO: DEC certifcate number, is there an online store for these? +--DEC certifcate lmk key, this would be lmkkey, no online lookup but can scrape through API. Numeric (25) +ALTER TABLE buildings DROP COLUMN IF EXISTS sust_dec_lmkey; -- Aggregate EPC rating (Estimated) for a building, derived from inidividual certificates ALTER TABLE buildings DROP COLUMN IF EXISTS sust_aggregate_estimate_epc; @@ -17,10 +18,11 @@ ALTER TABLE buildings DROP COLUMN IF EXISTS sust_aggregate_estimate_epc; -- Last significant retrofit date YYYY ALTER TABLE buildings DROP COLUMN IF EXISTS sust_retrofit_date; ---TODO : Embodied carbon +--How much embodied carbon? One for ML, tons CO2 int +ALTER TABLE buildings DROP COLUMN IF EXISTS sust_embodied_carbon; ---TODO : Life expectancy minimum +--Life expectancy of the building, via further analysis +ALTER TABLE buildings DROP COLUMN IF EXISTS sust_life_expectancy; ---TODO : Average lifespan for typology - ---TODO : Adaptability rating +--Average lifespan of typology based on statistical analysis of similar stock +ALTER TABLE buildings DROP COLUMN IF EXISTS sust_lifespan_average; diff --git a/migrations/012.sustainability.up.sql b/migrations/012.sustainability.up.sql index 1be3da7f..c76d0133 100644 --- a/migrations/012.sustainability.up.sql +++ b/migrations/012.sustainability.up.sql @@ -56,3 +56,12 @@ ALTER TABLE buildings -- Last significant retrofit date YYYY ALTER TABLE buildings ADD COLUMN IF NOT EXISTS sust_retrofit_date smallint; + +--How much embodied carbon? One for ML, tons CO2 int +ALTER TABLE buildings ADD COLUMN IF NOT EXISTS sust_embodied_carbon numeric(7,2); + +--Life expectancy of the building, via further analysis +ALTER TABLE buildings ADD COLUMN IF NOT EXISTS sust_life_expectancy smallint; + +--Average lifespan of typology based on statistical analysis of similar stock +ALTER TABLE buildings ADD COLUMN IF NOTE EXISTS sust_lifespan_average smallint; From f9a48f4a55910f67c748a058438034f7b369d437 Mon Sep 17 00:00:00 2001 From: dominic Date: Fri, 30 Aug 2019 13:02:37 +0100 Subject: [PATCH 5/5] File rename to follow conventions for #360 - In future years do we want tocapture DEC certifcate date? --- .../{012.sustainability.up.sql => 011.sustainability.up.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename migrations/{012.sustainability.up.sql => 011.sustainability.up.sql} (100%) diff --git a/migrations/012.sustainability.up.sql b/migrations/011.sustainability.up.sql similarity index 100% rename from migrations/012.sustainability.up.sql rename to migrations/011.sustainability.up.sql