From f2df7c7f0958930eb0d8d3c3238ba0b4317bbcb9 Mon Sep 17 00:00:00 2001 From: Thai Ngoc Nguyen Date: Tue, 31 Mar 2020 22:32:39 -0700 Subject: [PATCH 1/9] ALP-108 Add new function app --- .vscode/launch.json | 22 +- .vscode/settings.json | 5 +- aunt-leahs-functions-admin/.funcignore | 7 + aunt-leahs-functions-admin/.gitignore | 94 +++ aunt-leahs-functions-admin/config.js | 16 + aunt-leahs-functions-admin/host.json | 7 + aunt-leahs-functions-admin/package-lock.json | 618 ++++++++++++++++++ aunt-leahs-functions-admin/package.json | 13 + aunt-leahs-functions-admin/proxies.json | 4 + .../volunteers/function.json | 19 + .../volunteers/index.js | 126 ++++ .../volunteers/sample.dat | 3 + 12 files changed, 921 insertions(+), 13 deletions(-) create mode 100644 aunt-leahs-functions-admin/.funcignore create mode 100644 aunt-leahs-functions-admin/.gitignore create mode 100644 aunt-leahs-functions-admin/config.js create mode 100644 aunt-leahs-functions-admin/host.json create mode 100644 aunt-leahs-functions-admin/package-lock.json create mode 100644 aunt-leahs-functions-admin/package.json create mode 100644 aunt-leahs-functions-admin/proxies.json create mode 100644 aunt-leahs-functions-admin/volunteers/function.json create mode 100644 aunt-leahs-functions-admin/volunteers/index.js create mode 100644 aunt-leahs-functions-admin/volunteers/sample.dat diff --git a/.vscode/launch.json b/.vscode/launch.json index e7be044..9306c8a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,12 +1,12 @@ { - "version": "0.2.0", - "configurations": [ - { - "name": "Attach to Node Functions", - "type": "node", - "request": "attach", - "port": 9229, - "preLaunchTask": "func: host start" - } - ] -} \ No newline at end of file + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to Node Functions", + "type": "node", + "request": "attach", + "port": 9229, + "preLaunchTask": "func: host start" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 885f177..5792253 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,8 @@ { - "azureFunctions.deploySubpath": "aunt-leahs-functions", + "azureFunctions.deploySubpath": "aunt-leahs-functions-admin", "azureFunctions.projectLanguage": "JavaScript", "azureFunctions.projectRuntime": "~3", "debug.internalConsoleOptions": "neverOpen", - "azureFunctions.preDeployTask": "npm prune" + "azureFunctions.preDeployTask": "npm prune", + "azureFunctions.projectSubpath": "aunt-leahs-functions-admin" } \ No newline at end of file diff --git a/aunt-leahs-functions-admin/.funcignore b/aunt-leahs-functions-admin/.funcignore new file mode 100644 index 0000000..5179222 --- /dev/null +++ b/aunt-leahs-functions-admin/.funcignore @@ -0,0 +1,7 @@ +*.js.map +*.ts +.git* +.vscode +local.settings.json +test +tsconfig.json \ No newline at end of file diff --git a/aunt-leahs-functions-admin/.gitignore b/aunt-leahs-functions-admin/.gitignore new file mode 100644 index 0000000..772851c --- /dev/null +++ b/aunt-leahs-functions-admin/.gitignore @@ -0,0 +1,94 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TypeScript output +dist +out + +# Azure Functions artifacts +bin +obj +appsettings.json +local.settings.json \ No newline at end of file diff --git a/aunt-leahs-functions-admin/config.js b/aunt-leahs-functions-admin/config.js new file mode 100644 index 0000000..5572e6c --- /dev/null +++ b/aunt-leahs-functions-admin/config.js @@ -0,0 +1,16 @@ +var config = { + server: process.env["sqldb_server"], + options: { + encrypt: true, + database: process.env["sqldb_database"] + }, + authentication: { + type: 'default', + options: { + userName: process.env["sqldb_username"], + password: process.env["sqldb_password"] + } + } + } + + module.exports = config; \ No newline at end of file diff --git a/aunt-leahs-functions-admin/host.json b/aunt-leahs-functions-admin/host.json new file mode 100644 index 0000000..d342a8e --- /dev/null +++ b/aunt-leahs-functions-admin/host.json @@ -0,0 +1,7 @@ +{ + "version": "2.0", + "extensionBundle": { + "id": "Microsoft.Azure.Functions.ExtensionBundle", + "version": "[1.*, 2.0.0)" + } +} diff --git a/aunt-leahs-functions-admin/package-lock.json b/aunt-leahs-functions-admin/package-lock.json new file mode 100644 index 0000000..3891d1e --- /dev/null +++ b/aunt-leahs-functions-admin/package-lock.json @@ -0,0 +1,618 @@ +{ + "name": "aunt-leahs-admin", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@azure/ms-rest-azure-env": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@azure/ms-rest-azure-env/-/ms-rest-azure-env-1.1.2.tgz", + "integrity": "sha512-l7z0DPCi2Hp88w12JhDTtx5d0Y3+vhfE7JKJb9O7sEz71Cwp053N8piTtTnnk/tUor9oZHgEKi/p3tQQmLPjvA==" + }, + "@azure/ms-rest-js": { + "version": "1.8.14", + "resolved": "https://registry.npmjs.org/@azure/ms-rest-js/-/ms-rest-js-1.8.14.tgz", + "integrity": "sha512-IrCPN22c8RbKWA06ZXuFwwEb15cSnr0zZ6J8Fspp9ns1SSNTERf7hv+gWvTIis1FlwHy42Mfk8hVu0/r3a0AWA==", + "requires": { + "@types/tunnel": "0.0.0", + "axios": "^0.19.0", + "form-data": "^2.3.2", + "tough-cookie": "^2.4.3", + "tslib": "^1.9.2", + "tunnel": "0.0.6", + "uuid": "^3.2.1", + "xml2js": "^0.4.19" + } + }, + "@azure/ms-rest-nodeauth": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@azure/ms-rest-nodeauth/-/ms-rest-nodeauth-2.0.2.tgz", + "integrity": "sha512-KmNNICOxt3EwViAJI3iu2VH8t8BQg5J2rSAyO4IUYLF9ZwlyYsP419pdvl4NBUhluAP2cgN7dfD2V6E6NOMZlQ==", + "requires": { + "@azure/ms-rest-azure-env": "^1.1.2", + "@azure/ms-rest-js": "^1.8.7", + "adal-node": "^0.1.28" + } + }, + "@js-joda/core": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@js-joda/core/-/core-2.0.0.tgz", + "integrity": "sha512-OWm/xa9O9e4ugzNHoRT3IsXZZYfaV6Ia1aRwctOmCQ2GYWMnhKBzMC1WomqCh/oGxEZKNtPy5xv5//VIAOgMqw==" + }, + "@types/node": { + "version": "13.9.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.9.8.tgz", + "integrity": "sha512-1WgO8hsyHynlx7nhP1kr0OFzsgKz5XDQL+Lfc3b1Q3qIln/n8cKD4m09NJ0+P1Rq7Zgnc7N0+SsMnoD1rEb0kA==" + }, + "@types/tunnel": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/@types/tunnel/-/tunnel-0.0.0.tgz", + "integrity": "sha512-FGDp0iBRiBdPjOgjJmn1NH0KDLN+Z8fRmo+9J7XGBhubq1DPrGrbmG4UTlGzrpbCpesMqD0sWkzi27EYkOMHyg==", + "requires": { + "@types/node": "*" + } + }, + "adal-node": { + "version": "0.1.28", + "resolved": "https://registry.npmjs.org/adal-node/-/adal-node-0.1.28.tgz", + "integrity": "sha1-RoxLs+u9lrEnBmn0ucuk4AZepIU=", + "requires": { + "@types/node": "^8.0.47", + "async": ">=0.6.0", + "date-utils": "*", + "jws": "3.x.x", + "request": ">= 2.52.0", + "underscore": ">= 1.3.1", + "uuid": "^3.1.0", + "xmldom": ">= 0.1.x", + "xpath.js": "~1.1.0" + }, + "dependencies": { + "@types/node": { + "version": "8.10.59", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.59.tgz", + "integrity": "sha512-8RkBivJrDCyPpBXhVZcjh7cQxVBSmRk9QM7hOketZzp6Tg79c0N8kkpAIito9bnJ3HCVCHVYz+KHTEbfQNfeVQ==" + } + } + }, + "ajv": { + "version": "6.12.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.0.tgz", + "integrity": "sha512-D6gFiFA0RRLyUbvijN74DWAjXSFxWKaWP7mldxkVhyhAV3+SWA9HEJPHQ2c9soIeTFJqcSdFDGFgdqs1iUU2Hw==", + "requires": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + } + }, + "asn1": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", + "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", + "requires": { + "safer-buffer": "~2.1.0" + } + }, + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" + }, + "async": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", + "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==" + }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, + "aws-sign2": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", + "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=" + }, + "aws4": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", + "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" + }, + "axios": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", + "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", + "requires": { + "follow-redirects": "1.5.10" + } + }, + "bcrypt-pbkdf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", + "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", + "requires": { + "tweetnacl": "^0.14.3" + } + }, + "bl": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-3.0.0.tgz", + "integrity": "sha512-EUAyP5UHU5hxF8BPT0LKW8gjYLhq1DQIcneOX/pL/m2Alo+OYDQAJlHq+yseMP50Os2nHXOSic6Ss3vSQeyf4A==", + "requires": { + "readable-stream": "^3.0.1" + } + }, + "buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" + }, + "caseless": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", + "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" + }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "requires": { + "delayed-stream": "~1.0.0" + } + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "dashdash": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "requires": { + "assert-plus": "^1.0.0" + } + }, + "date-utils": { + "version": "1.2.21", + "resolved": "https://registry.npmjs.org/date-utils/-/date-utils-1.2.21.tgz", + "integrity": "sha1-YfsWzcEnSzyayq/+n8ad+HIKK2Q=" + }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" + }, + "depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==" + }, + "ecc-jsbn": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", + "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", + "requires": { + "jsbn": "~0.1.0", + "safer-buffer": "^2.1.0" + } + }, + "ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "requires": { + "safe-buffer": "^5.0.1" + } + }, + "extend": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" + }, + "extsprintf": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" + }, + "fast-deep-equal": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz", + "integrity": "sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==" + }, + "fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" + }, + "follow-redirects": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", + "requires": { + "debug": "=3.1.0" + } + }, + "forever-agent": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" + }, + "form-data": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz", + "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + } + }, + "getpass": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "requires": { + "assert-plus": "^1.0.0" + } + }, + "har-schema": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", + "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=" + }, + "har-validator": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.3.tgz", + "integrity": "sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g==", + "requires": { + "ajv": "^6.5.5", + "har-schema": "^2.0.0" + } + }, + "http-signature": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", + "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", + "requires": { + "assert-plus": "^1.0.0", + "jsprim": "^1.2.2", + "sshpk": "^1.7.0" + } + }, + "iconv-lite": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.5.1.tgz", + "integrity": "sha512-ONHr16SQvKZNSqjQT9gy5z24Jw+uqfO02/ngBSBoqChZ+W8qXX7GPRa1RoUnzGADw8K63R1BXUMzarCVQBpY8Q==", + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" + }, + "isstream": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" + }, + "jsbi": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/jsbi/-/jsbi-3.1.2.tgz", + "integrity": "sha512-5nDXo1X9QVaXK/Cpb5VECV9ss1QPbjUuk1qSruHB1PK/g39Sd414K4nci99ElFDZv0vzxDEnKn3o49/Tn9Yagw==" + }, + "jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" + }, + "json-schema": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", + "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" + }, + "json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + }, + "json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" + }, + "jsprim": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", + "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "requires": { + "assert-plus": "1.0.0", + "extsprintf": "1.3.0", + "json-schema": "0.2.3", + "verror": "1.10.0" + } + }, + "jwa": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", + "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", + "requires": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "jws": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz", + "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==", + "requires": { + "jwa": "^1.4.1", + "safe-buffer": "^5.0.1" + } + }, + "mime-db": { + "version": "1.43.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz", + "integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ==" + }, + "mime-types": { + "version": "2.1.26", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz", + "integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==", + "requires": { + "mime-db": "1.43.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "native-duplexpair": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/native-duplexpair/-/native-duplexpair-1.0.0.tgz", + "integrity": "sha1-eJkHjmS/PIo9cyYBs9QP8F21j6A=" + }, + "oauth-sign": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", + "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==" + }, + "performance-now": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", + "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" + }, + "psl": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", + "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==" + }, + "punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" + }, + "qs": { + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", + "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "request": { + "version": "2.88.2", + "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", + "integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==", + "requires": { + "aws-sign2": "~0.7.0", + "aws4": "^1.8.0", + "caseless": "~0.12.0", + "combined-stream": "~1.0.6", + "extend": "~3.0.2", + "forever-agent": "~0.6.1", + "form-data": "~2.3.2", + "har-validator": "~5.1.3", + "http-signature": "~1.2.0", + "is-typedarray": "~1.0.0", + "isstream": "~0.1.2", + "json-stringify-safe": "~5.0.1", + "mime-types": "~2.1.19", + "oauth-sign": "~0.9.0", + "performance-now": "^2.1.0", + "qs": "~6.5.2", + "safe-buffer": "^5.1.2", + "tough-cookie": "~2.5.0", + "tunnel-agent": "^0.6.0", + "uuid": "^3.3.2" + }, + "dependencies": { + "form-data": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", + "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + } + } + } + }, + "safe-buffer": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", + "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + }, + "sprintf-js": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz", + "integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==" + }, + "sshpk": { + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", + "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", + "requires": { + "asn1": "~0.2.3", + "assert-plus": "^1.0.0", + "bcrypt-pbkdf": "^1.0.0", + "dashdash": "^1.12.0", + "ecc-jsbn": "~0.1.1", + "getpass": "^0.1.1", + "jsbn": "~0.1.0", + "safer-buffer": "^2.0.2", + "tweetnacl": "~0.14.0" + } + }, + "string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "requires": { + "safe-buffer": "~5.2.0" + } + }, + "tedious": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/tedious/-/tedious-8.2.0.tgz", + "integrity": "sha512-ODSlW1GVzylMsn5ELoMsmhSCfYL4DPLB8JEevGFM8sAkW4hb4Ywwsa/IOU6H5MqAvqymn+g43+VGrZr5xPUH0w==", + "requires": { + "@azure/ms-rest-nodeauth": "2.0.2", + "@js-joda/core": "^2.0.0", + "bl": "^3.0.0", + "depd": "^2.0.0", + "iconv-lite": "^0.5.0", + "jsbi": "^3.1.1", + "native-duplexpair": "^1.0.0", + "punycode": "^2.1.0", + "readable-stream": "^3.6.0", + "sprintf-js": "^1.1.2" + } + }, + "tough-cookie": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", + "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", + "requires": { + "psl": "^1.1.28", + "punycode": "^2.1.1" + } + }, + "tslib": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz", + "integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==" + }, + "tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==" + }, + "tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", + "requires": { + "safe-buffer": "^5.0.1" + } + }, + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" + }, + "underscore": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.10.2.tgz", + "integrity": "sha512-N4P+Q/BuyuEKFJ43B9gYuOj4TQUHXX+j2FqguVOpjkssLUUrnJofCcBccJSCoeturDoZU6GorDTHSvUDlSQbTg==" + }, + "uri-js": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", + "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", + "requires": { + "punycode": "^2.1.0" + } + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "uuid": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" + }, + "verror": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", + "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", + "requires": { + "assert-plus": "^1.0.0", + "core-util-is": "1.0.2", + "extsprintf": "^1.2.0" + } + }, + "xml2js": { + "version": "0.4.23", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", + "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==", + "requires": { + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" + } + }, + "xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==" + }, + "xmldom": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.3.0.tgz", + "integrity": "sha512-z9s6k3wxE+aZHgXYxSTpGDo7BYOUfJsIRyoZiX6HTjwpwfS2wpQBQKa2fD+ShLyPkqDYo5ud7KitmLZ2Cd6r0g==" + }, + "xpath.js": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/xpath.js/-/xpath.js-1.1.0.tgz", + "integrity": "sha512-jg+qkfS4K8E7965sqaUl8mRngXiKb3WZGfONgE18pr03FUQiuSV6G+Ej4tS55B+rIQSFEIw3phdVAQ4pPqNWfQ==" + } + } +} diff --git a/aunt-leahs-functions-admin/package.json b/aunt-leahs-functions-admin/package.json new file mode 100644 index 0000000..efc446c --- /dev/null +++ b/aunt-leahs-functions-admin/package.json @@ -0,0 +1,13 @@ +{ + "name": "aunt-leahs-admin", + "version": "1.0.0", + "description": "", + "scripts": { + "start": "func start", + "test": "echo \"No tests yet...\"" + }, + "dependencies": { + "tedious": "^8.2.0" + }, + "devDependencies": {} +} diff --git a/aunt-leahs-functions-admin/proxies.json b/aunt-leahs-functions-admin/proxies.json new file mode 100644 index 0000000..b385252 --- /dev/null +++ b/aunt-leahs-functions-admin/proxies.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/proxies", + "proxies": {} +} diff --git a/aunt-leahs-functions-admin/volunteers/function.json b/aunt-leahs-functions-admin/volunteers/function.json new file mode 100644 index 0000000..7eb1f8f --- /dev/null +++ b/aunt-leahs-functions-admin/volunteers/function.json @@ -0,0 +1,19 @@ +{ + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "post" + ] + }, + { + "type": "http", + "direction": "out", + "name": "res" + } + ] +} diff --git a/aunt-leahs-functions-admin/volunteers/index.js b/aunt-leahs-functions-admin/volunteers/index.js new file mode 100644 index 0000000..dc7ab1f --- /dev/null +++ b/aunt-leahs-functions-admin/volunteers/index.js @@ -0,0 +1,126 @@ +var Connection = require('tedious').Connection; +var Request = require('tedious').Request; +const config = require('../config'); + +module.exports = function (context, req) { + var volunteers = []; + var connection = new Connection(config); + + connection.on('connect', (error) => { + if (error) { + context.log('Error: ', error); + context.done(); + } + else { + context.log('Connected'); + if (req.method == 'GET') { + context.log("GET /volunteers"); + getVolunteers(); + } + else if (req.method == 'PUT') { // soft delete + context.log("PUT /volunteers"); + deleteVolunteers(); + } + } + }); + + function getVolunteers() { + var queryString = 'SELECT [firstName], [lastName], [email], [address], [postalCode], [mailingList] FROM [dbo].[Volunteer];'; + request = new Request( + queryString, + function(err) { + if (err) { + context.log(err); + context.done(); + } + }); + + request.on('row', function (columns) { + var volunteer = {}; + columns.forEach(function(column) { + volunteer[column.metadata.colName] = column.value; + }); + volunteers.push(volunteer); + }); + + request.on('doneProc', function (rowCount, more, returnStatus, rows) { + context.res = { + body: JSON.stringify(volunteers) + }; + + context.done(); + }); + + connection.execSql(request); + } + + function postVolunteers() { + const formInput = req.body; + + // Should be refactored to use JSON destructing, I think + const firstName = formInput.firstName; + const lastName = formInput.lastName; + const email = formInput.email; + const streetAddress = formInput.streetAddress; + const postalCode = formInput.postalCode; + const mailingList = formInput.mailingList; + const contactEmail = formInput.contactEmail; + + var queryString = `INSERT INTO Volunteer (firstName, lastName, email, address, postalCode, mailingList, emergencyContact) \nVALUES ('${firstName}','${lastName}','${email}','${streetAddress}','${postalCode}','${mailingList}','${contactEmail}')` + + request = new Request( + queryString, + function(err) { + if (err) { + context.log(err); + context.done(); + } + }); + + connection.execSql(request); + } + + function postEmergencyContact() { + const formInput = req.body; + + // Same comment as above, refactor to use restructuring + const firstName = formInput.contactFirstName; + const lastName = formInput.contactLastName; + const phoneNumber = formInput.contactPhoneNumber; + const relationship = formInput.contactRelationship; + const contactEmail = formInput.contactEmail; + + var queryString = `INSERT INTO EmergencyContact (firstName, lastName, phoneNumber, relationship, email) \nVALUES ('${firstName}','${lastName}','${phoneNumber}','${relationship}','${contactEmail}');` + + context.log(queryString); + request = new Request( + queryString, + function(err) { + if (err) { + context.log(err); + context.done(); + } + }); + + request.on('requestCompleted', function () { + postVolunteers(); + }); + + connection.execSql(request); + } + + // Not working, but roughly how I expect the end product to look + function deleteVolunteers() { + var queryString = 'UPDATE Volunteer SET isDeleted = 1;'; + request = new Request( + queryString, + function(err) { + if (err) { + context.log(err); + context.done(); + } + }); + + connection.execSql(request); + } +}; \ No newline at end of file diff --git a/aunt-leahs-functions-admin/volunteers/sample.dat b/aunt-leahs-functions-admin/volunteers/sample.dat new file mode 100644 index 0000000..26aac46 --- /dev/null +++ b/aunt-leahs-functions-admin/volunteers/sample.dat @@ -0,0 +1,3 @@ +{ + "name": "Azure" +} \ No newline at end of file From 92db0f366829ac7ed283578cd47996d8d5c199f0 Mon Sep 17 00:00:00 2001 From: Thai Ngoc Nguyen Date: Sat, 4 Apr 2020 00:54:35 -0700 Subject: [PATCH 2/9] ALP-108 Added vscode settings to support multi function app project --- .vscode/extensions.json | 5 - .vscode/launch.json | 12 --- .vscode/settings.json | 8 -- .vscode/tasks.json | 98 ------------------- alp.code-workspace | 28 ++++++ .../.vscode/extensions.json | 5 + .../.vscode/launch.json | 13 +++ .../.vscode/settings.json | 11 +++ aunt-leahs-functions-admin/.vscode/tasks.json | 12 +++ aunt-leahs-functions/.vscode/extensions.json | 5 + aunt-leahs-functions/.vscode/launch.json | 13 +++ aunt-leahs-functions/.vscode/settings.json | 12 +++ aunt-leahs-functions/.vscode/tasks.json | 12 +++ 13 files changed, 111 insertions(+), 123 deletions(-) delete mode 100644 .vscode/extensions.json delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/settings.json delete mode 100644 .vscode/tasks.json create mode 100644 alp.code-workspace create mode 100644 aunt-leahs-functions-admin/.vscode/extensions.json create mode 100644 aunt-leahs-functions-admin/.vscode/launch.json create mode 100644 aunt-leahs-functions-admin/.vscode/settings.json create mode 100644 aunt-leahs-functions-admin/.vscode/tasks.json create mode 100644 aunt-leahs-functions/.vscode/extensions.json create mode 100644 aunt-leahs-functions/.vscode/launch.json create mode 100644 aunt-leahs-functions/.vscode/settings.json create mode 100644 aunt-leahs-functions/.vscode/tasks.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 26786f9..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "recommendations": [ - "ms-azuretools.vscode-azurefunctions" - ] -} diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 9306c8a..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Attach to Node Functions", - "type": "node", - "request": "attach", - "port": 9229, - "preLaunchTask": "func: host start" - } - ] -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 5792253..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "azureFunctions.deploySubpath": "aunt-leahs-functions-admin", - "azureFunctions.projectLanguage": "JavaScript", - "azureFunctions.projectRuntime": "~3", - "debug.internalConsoleOptions": "neverOpen", - "azureFunctions.preDeployTask": "npm prune", - "azureFunctions.projectSubpath": "aunt-leahs-functions-admin" -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index f2723e7..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "clean", - "command": "dotnet", - "args": [ - "clean", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "type": "process", - "problemMatcher": "$msCompile", - "options": { - "cwd": "${workspaceFolder}/aunt-leahs-functions" - } - }, - { - "label": "build", - "command": "dotnet", - "args": [ - "build", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "type": "process", - "dependsOn": "clean", - "group": { - "kind": "build", - "isDefault": true - }, - "problemMatcher": "$msCompile", - "options": { - "cwd": "${workspaceFolder}/aunt-leahs-functions" - } - }, - { - "label": "clean release", - "command": "dotnet", - "args": [ - "clean", - "--configuration", - "Release", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "type": "process", - "problemMatcher": "$msCompile", - "options": { - "cwd": "${workspaceFolder}/aunt-leahs-functions" - } - }, - { - "label": "publish", - "command": "dotnet", - "args": [ - "publish", - "--configuration", - "Release", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "type": "process", - "dependsOn": "clean release", - "problemMatcher": "$msCompile", - "options": { - "cwd": "${workspaceFolder}/aunt-leahs-functions" - } - }, - { - "type": "func", - "command": "host start", - "problemMatcher": "$func-watch", - "isBackground": true, - "dependsOn": "npm install", - "options": { - "cwd": "${workspaceFolder}/aunt-leahs-functions" - } - }, - { - "type": "shell", - "label": "npm install", - "command": "npm install", - "options": { - "cwd": "${workspaceFolder}/aunt-leahs-functions" - } - }, - { - "type": "shell", - "label": "npm prune", - "command": "npm prune --production", - "problemMatcher": [], - "options": { - "cwd": "${workspaceFolder}/aunt-leahs-functions" - } - } - ] -} \ No newline at end of file diff --git a/alp.code-workspace b/alp.code-workspace new file mode 100644 index 0000000..d5bd614 --- /dev/null +++ b/alp.code-workspace @@ -0,0 +1,28 @@ +{ + "folders": [ + { + "path": "aunt-leahs-functions" + }, + { + "path": "aunt-leahs-functions-admin" + }, + { + "path": "aunt-leahs-app" + } + ], + "settings": { + "debug.internalConsoleOptions": "neverOpen" + }, + "launch": { + "configurations": [], + "compounds": [ + { + "name": "Attach to both function apps", + "configurations": [ + "Attach to app1", + "Attach to app2" + ] + } + ] + } +} \ No newline at end of file diff --git a/aunt-leahs-functions-admin/.vscode/extensions.json b/aunt-leahs-functions-admin/.vscode/extensions.json new file mode 100644 index 0000000..dde673d --- /dev/null +++ b/aunt-leahs-functions-admin/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "ms-azuretools.vscode-azurefunctions" + ] +} \ No newline at end of file diff --git a/aunt-leahs-functions-admin/.vscode/launch.json b/aunt-leahs-functions-admin/.vscode/launch.json new file mode 100644 index 0000000..58205f3 --- /dev/null +++ b/aunt-leahs-functions-admin/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to app2", + "type": "node", + "request": "attach", + "port": 9228, + "preLaunchTask": "func: host start --port 7072" + } + ] + } + \ No newline at end of file diff --git a/aunt-leahs-functions-admin/.vscode/settings.json b/aunt-leahs-functions-admin/.vscode/settings.json new file mode 100644 index 0000000..b4d6b1d --- /dev/null +++ b/aunt-leahs-functions-admin/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "azureFunctions.projectRuntime": "~2", + "azureFunctions.projectLanguage": "JavaScript", + "azureFunctions.deploySubpath": ".", + "azureFunctions.preDeployTask": "func: extensions install", + "files.exclude": { + "obj": true, + "bin": true + }, + "debug.internalConsoleOptions": "neverOpen" +} \ No newline at end of file diff --git a/aunt-leahs-functions-admin/.vscode/tasks.json b/aunt-leahs-functions-admin/.vscode/tasks.json new file mode 100644 index 0000000..6599643 --- /dev/null +++ b/aunt-leahs-functions-admin/.vscode/tasks.json @@ -0,0 +1,12 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "func", + "command": "host start --port 7072", + "problemMatcher": "$func-watch", + "dependsOn": "func: extensions install", + "isBackground": true + } + ] + } \ No newline at end of file diff --git a/aunt-leahs-functions/.vscode/extensions.json b/aunt-leahs-functions/.vscode/extensions.json new file mode 100644 index 0000000..dde673d --- /dev/null +++ b/aunt-leahs-functions/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "ms-azuretools.vscode-azurefunctions" + ] +} \ No newline at end of file diff --git a/aunt-leahs-functions/.vscode/launch.json b/aunt-leahs-functions/.vscode/launch.json new file mode 100644 index 0000000..e99113f --- /dev/null +++ b/aunt-leahs-functions/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to app1", + "type": "node", + "request": "attach", + "port": 9229, + "preLaunchTask": "func: host start" + } + ] + } + \ No newline at end of file diff --git a/aunt-leahs-functions/.vscode/settings.json b/aunt-leahs-functions/.vscode/settings.json new file mode 100644 index 0000000..0396123 --- /dev/null +++ b/aunt-leahs-functions/.vscode/settings.json @@ -0,0 +1,12 @@ + +{ + "azureFunctions.projectRuntime": "~3", + "azureFunctions.projectLanguage": "JavaScript", + "azureFunctions.deploySubpath": ".", + "azureFunctions.preDeployTask": "func: extensions install", + "files.exclude": { + "obj": true, + "bin": true + }, + "debug.internalConsoleOptions": "neverOpen" + } \ No newline at end of file diff --git a/aunt-leahs-functions/.vscode/tasks.json b/aunt-leahs-functions/.vscode/tasks.json new file mode 100644 index 0000000..d0f705d --- /dev/null +++ b/aunt-leahs-functions/.vscode/tasks.json @@ -0,0 +1,12 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "func", + "command": "host start", + "problemMatcher": "$func-watch", + "dependsOn": "func: extensions install", + "isBackground": true + } + ] +} \ No newline at end of file From 182c4982af6e4b35a5aa5f3da9e18d596528ff75 Mon Sep 17 00:00:00 2001 From: Thai Ngoc Nguyen Date: Sat, 4 Apr 2020 00:57:59 -0700 Subject: [PATCH 3/9] ALP-108 Migrated shifts functions --- .../shifts/function.json | 19 +++++ aunt-leahs-functions-admin/shifts/index.js | 84 +++++++++++++++++++ aunt-leahs-functions-admin/shifts/sample.dat | 3 + aunt-leahs-functions/shifts/function.json | 2 - aunt-leahs-functions/shifts/index.js | 68 +-------------- 5 files changed, 108 insertions(+), 68 deletions(-) create mode 100644 aunt-leahs-functions-admin/shifts/function.json create mode 100644 aunt-leahs-functions-admin/shifts/index.js create mode 100644 aunt-leahs-functions-admin/shifts/sample.dat diff --git a/aunt-leahs-functions-admin/shifts/function.json b/aunt-leahs-functions-admin/shifts/function.json new file mode 100644 index 0000000..0dc389e --- /dev/null +++ b/aunt-leahs-functions-admin/shifts/function.json @@ -0,0 +1,19 @@ +{ + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "put" + ] + }, + { + "type": "http", + "direction": "out", + "name": "res" + } + ] +} diff --git a/aunt-leahs-functions-admin/shifts/index.js b/aunt-leahs-functions-admin/shifts/index.js new file mode 100644 index 0000000..38fd3a1 --- /dev/null +++ b/aunt-leahs-functions-admin/shifts/index.js @@ -0,0 +1,84 @@ +var Connection = require('tedious').Connection; +var Request = require('tedious').Request; +var config = require('../config'); +var TYPES = require('tedious').TYPES; + +module.exports = function (context, req) { + var shifts = []; + + var connection = new Connection(config); + + connection.on('connect', (err) => { + if (err) { + context.log('Error: ', err); + context.done(err); + } else { + if (req.method === 'GET') { + getShifts(); + } else if (req.method == 'PUT') { + deleteShifts(); + } + } + }); + + function getShifts() { + var queryString = + 'SELECT shift.id, volunteer.firstName, volunteer.lastName, shift.startTime, shift.duration \ + FROM Shift shift \ + JOIN Volunteer volunteer ON shift.volunteerId = volunteer.id \ + JOIN Location location ON shift.locationId = location.id \ + WHERE shift.isDeleted = 0;'; + + request = new Request(queryString, function (err) { + if (err) { + context.log(err); + context.done(err); + } + }); + + request.on('row', function (columns) { + var shift = {}; + columns.forEach(function (column) { + shift[column.metadata.colName] = column.value; + }); + shifts.push(shift); + }); + + request.on('doneProc', function (rowCount, more, returnStatus, rows) { + context.res = { + body: JSON.stringify(shifts), + }; + + context.done(); + }); + + connection.execSql(request); + } + + function deleteShifts() { + var queryString = 'UPDATE Shift SET isDeleted = 1;'; + + request = new Request(queryString, function (err) { + if (err) { + context.log(err); + + context.res = { + body: 'Error occurred deleting shifts from the database ' + err, + }; + + context.done(err); + } + }); + + request.on('doneProc', function (rowCount, more, rows) { + context.res = { + body: { message: 'Successfully deleted shifts from the database' }, + }; + + context.done(); + }); + + connection.execSql(request); + } + +}; diff --git a/aunt-leahs-functions-admin/shifts/sample.dat b/aunt-leahs-functions-admin/shifts/sample.dat new file mode 100644 index 0000000..26aac46 --- /dev/null +++ b/aunt-leahs-functions-admin/shifts/sample.dat @@ -0,0 +1,3 @@ +{ + "name": "Azure" +} \ No newline at end of file diff --git a/aunt-leahs-functions/shifts/function.json b/aunt-leahs-functions/shifts/function.json index 3a4a8d0..97e43d4 100644 --- a/aunt-leahs-functions/shifts/function.json +++ b/aunt-leahs-functions/shifts/function.json @@ -6,8 +6,6 @@ "direction": "in", "name": "req", "methods": [ - "get", - "put", "post" ] }, diff --git a/aunt-leahs-functions/shifts/index.js b/aunt-leahs-functions/shifts/index.js index 2f5cd7a..82ac16c 100644 --- a/aunt-leahs-functions/shifts/index.js +++ b/aunt-leahs-functions/shifts/index.js @@ -11,78 +11,14 @@ module.exports = function (context, req) { connection.on('connect', (err) => { if (err) { context.log('Error: ', err); - context.done(); + context.done(err); } else { - if (req.method === 'GET') { - getShifts(); - } else if (req.method == 'PUT') { - deleteShifts(); - } else if (req.method == 'POST') { + if (req.method == 'POST') { postShifts(req.body.shiftData); } } }); - function getShifts() { - var queryString = - 'SELECT shift.id, volunteer.firstName, volunteer.lastName, shift.startTime, shift.duration \ - FROM Shift shift \ - JOIN Volunteer volunteer ON shift.volunteerId = volunteer.id \ - JOIN Location location ON shift.locationId = location.id \ - WHERE shift.isDeleted = 0;'; - - request = new Request(queryString, function (err) { - if (err) { - context.log(err); - context.done(err); - } - }); - - request.on('row', function (columns) { - var shift = {}; - columns.forEach(function (column) { - shift[column.metadata.colName] = column.value; - }); - shifts.push(shift); - }); - - request.on('doneProc', function (rowCount, more, returnStatus, rows) { - context.res = { - body: JSON.stringify(shifts), - }; - - context.done(); - }); - - connection.execSql(request); - } - - function deleteShifts() { - var queryString = 'UPDATE Shift SET isDeleted = 1;'; - - request = new Request(queryString, function (err) { - if (err) { - context.log(err); - - context.res = { - body: 'Error occurred deleting shifts from the database ' + err, - }; - - context.done(err); - } - }); - - request.on('doneProc', function (rowCount, more, rows) { - context.res = { - body: { message: 'Successfully deleted shifts from the database' }, - }; - - context.done(); - }); - - connection.execSql(request); - } - function postShifts(shiftData) { var queryString = 'INSERT INTO Shift (locationId, volunteerId, startTime, duration, isDeleted) \ From 8696f321caaf75417e7fd6973acf3a6683a0d5a6 Mon Sep 17 00:00:00 2001 From: Thai Ngoc Nguyen Date: Sat, 4 Apr 2020 01:00:57 -0700 Subject: [PATCH 4/9] ALP-108 Modify migrated volunteer endpoints --- .../volunteers/function.json | 4 +- .../volunteers/index.js | 124 ++++++---------- aunt-leahs-functions/volunteers/function.json | 4 +- aunt-leahs-functions/volunteers/index.js | 137 +++++------------- 4 files changed, 80 insertions(+), 189 deletions(-) diff --git a/aunt-leahs-functions-admin/volunteers/function.json b/aunt-leahs-functions-admin/volunteers/function.json index 7eb1f8f..9e11994 100644 --- a/aunt-leahs-functions-admin/volunteers/function.json +++ b/aunt-leahs-functions-admin/volunteers/function.json @@ -6,8 +6,8 @@ "direction": "in", "name": "req", "methods": [ - "get", - "post" + "GET", + "PUT" ] }, { diff --git a/aunt-leahs-functions-admin/volunteers/index.js b/aunt-leahs-functions-admin/volunteers/index.js index dc7ab1f..2a8f5be 100644 --- a/aunt-leahs-functions-admin/volunteers/index.js +++ b/aunt-leahs-functions-admin/volunteers/index.js @@ -1,51 +1,53 @@ var Connection = require('tedious').Connection; var Request = require('tedious').Request; const config = require('../config'); +var TYPES = require('tedious').TYPES; module.exports = function (context, req) { var volunteers = []; var connection = new Connection(config); - connection.on('connect', (error) => { - if (error) { - context.log('Error: ', error); - context.done(); + connection.on('connect', (err) => { + if (err) { + context.log('Error: ', err); + context.done(err); } else { - context.log('Connected'); if (req.method == 'GET') { - context.log("GET /volunteers"); getVolunteers(); } else if (req.method == 'PUT') { // soft delete - context.log("PUT /volunteers"); - deleteVolunteers(); + putVolunteers(); } } }); function getVolunteers() { - var queryString = 'SELECT [firstName], [lastName], [email], [address], [postalCode], [mailingList] FROM [dbo].[Volunteer];'; + var queryString = 'SELECT volunteer.id, volunteer.firstName, volunteer.lastName, volunteer.email, volunteer.address, volunteer.postalCode, volunteer.mailingList \ + FROM Volunteer volunteer \ + WHERE volunteer.isDeleted = 0;'; + + request = new Request( queryString, - function(err) { + function (err) { if (err) { context.log(err); - context.done(); + context.done(err); } }); - request.on('row', function (columns) { - var volunteer = {}; - columns.forEach(function(column) { - volunteer[column.metadata.colName] = column.value; - }); - volunteers.push(volunteer); + request.on('row', function (columns) { + var volunteer = {}; + columns.forEach(function (column) { + volunteer[column.metadata.colName] = column.value; }); + volunteers.push(volunteer); + }); request.on('doneProc', function (rowCount, more, returnStatus, rows) { context.res = { - body: JSON.stringify(volunteers) + body: volunteers }; context.done(); @@ -54,73 +56,31 @@ module.exports = function (context, req) { connection.execSql(request); } - function postVolunteers() { - const formInput = req.body; + function putVolunteers() { + var queryString = `UPDATE Volunteer SET isDeleted = 1 \ + WHERE volunteer.isDeleted = 0;`; - // Should be refactored to use JSON destructing, I think - const firstName = formInput.firstName; - const lastName = formInput.lastName; - const email = formInput.email; - const streetAddress = formInput.streetAddress; - const postalCode = formInput.postalCode; - const mailingList = formInput.mailingList; - const contactEmail = formInput.contactEmail; - - var queryString = `INSERT INTO Volunteer (firstName, lastName, email, address, postalCode, mailingList, emergencyContact) \nVALUES ('${firstName}','${lastName}','${email}','${streetAddress}','${postalCode}','${mailingList}','${contactEmail}')` - - request = new Request( - queryString, - function(err) { - if (err) { - context.log(err); - context.done(); - } - }); + request = new Request(queryString, function (err) { + if (err) { + context.log(err); - connection.execSql(request); - } + context.res = { + body: + 'Error occurred deleting volunteers from the database: \n' + err, + }; - function postEmergencyContact() { - const formInput = req.body; + context.done(); + } + }); - // Same comment as above, refactor to use restructuring - const firstName = formInput.contactFirstName; - const lastName = formInput.contactLastName; - const phoneNumber = formInput.contactPhoneNumber; - const relationship = formInput.contactRelationship; - const contactEmail = formInput.contactEmail; + request.on('doneProc', function (rowCount, more, rows) { + context.res = { + body: { message: 'Successfully deleted volunteers from the database' }, + }; - var queryString = `INSERT INTO EmergencyContact (firstName, lastName, phoneNumber, relationship, email) \nVALUES ('${firstName}','${lastName}','${phoneNumber}','${relationship}','${contactEmail}');` + context.done(); + }); - context.log(queryString); - request = new Request( - queryString, - function(err) { - if (err) { - context.log(err); - context.done(); - } - }); - - request.on('requestCompleted', function () { - postVolunteers(); - }); - - connection.execSql(request); - } - - // Not working, but roughly how I expect the end product to look - function deleteVolunteers() { - var queryString = 'UPDATE Volunteer SET isDeleted = 1;'; - request = new Request( - queryString, - function(err) { - if (err) { - context.log(err); - context.done(); - } - }); - - connection.execSql(request); - } -}; \ No newline at end of file + connection.execSql(request); + } +}; diff --git a/aunt-leahs-functions/volunteers/function.json b/aunt-leahs-functions/volunteers/function.json index a6f7c90..39c7837 100644 --- a/aunt-leahs-functions/volunteers/function.json +++ b/aunt-leahs-functions/volunteers/function.json @@ -6,9 +6,7 @@ "direction": "in", "name": "req", "methods": [ - "GET", - "POST", - "PUT" + "POST" ] }, { diff --git a/aunt-leahs-functions/volunteers/index.js b/aunt-leahs-functions/volunteers/index.js index 8d4f01f..fa076a2 100644 --- a/aunt-leahs-functions/volunteers/index.js +++ b/aunt-leahs-functions/volunteers/index.js @@ -4,95 +4,20 @@ const config = require('../config'); var TYPES = require('tedious').TYPES; module.exports = function (context, req) { - var volunteers = []; - var connection = new Connection(config); - - connection.on('connect', (err) => { - if (err) { - context.log('Error: ', err); - context.done(); - } - else { - if (req.method == 'GET') { - getVolunteers(); - } - else if (req.method == 'POST') { - postEmergencyContact(); - } - else if (req.method == 'PUT') { // soft delete - putVolunteers(); - } - } - }); - - function getVolunteers() { - var queryString = 'SELECT volunteer.id, volunteer.firstName, volunteer.lastName, volunteer.email, volunteer.address, volunteer.postalCode, volunteer.mailingList \ - FROM Volunteer volunteer \ - WHERE volunteer.isDeleted = 0;'; - - - request = new Request( - queryString, - function (err) { - if (err) { - context.log(err); - context.done(err); - } - }); - - request.on('row', function (columns) { - var volunteer = {}; - columns.forEach(function (column) { - volunteer[column.metadata.colName] = column.value; - }); - volunteers.push(volunteer); - }); - - request.on('doneProc', function (rowCount, more, returnStatus, rows) { - context.res = { - body: volunteers - }; - - context.done(); - }); - - connection.execSql(request); - } - - function postVolunteers(emergencyContactId) { - const formInput = req.body; - - const { firstName, lastName, email, phone, streetAddress, postalCode, mailingList } = formInput; - - var queryString = 'INSERT INTO Volunteer (firstName, lastName, phoneNumber, email, address, postalCode, mailingList, emergencyContactId, isDeleted) \ - VALUES (@firstName, @lastName, @phoneNumber, @email, @streetAddress, @postalCode, @mailingList, @emergencyContactId, @isDeleted)'; - - request = new Request(queryString, function (err) { - if (err) { - context.log(err); - context.done(err); - } - }); - - request.addParameter('firstName', TYPES.NVarChar, firstName); - request.addParameter('lastName', TYPES.NVarChar, lastName); - request.addParameter('phoneNumber', TYPES.NVarChar, phone); - request.addParameter('email', TYPES.NVarChar, email); - request.addParameter('streetAddress', TYPES.NVarChar, streetAddress); - request.addParameter('postalCode', TYPES.NVarChar, postalCode); - request.addParameter('mailingList', TYPES.Bit, mailingList); - request.addParameter('emergencyContactId', TYPES.Int, emergencyContactId); - request.addParameter('isDeleted', TYPES.Bit, 0); - - request.on('doneProc', function (rowCount, more, returnStatus, rows) { - if (returnStatus != 0) { - context.done('Error occurred: ' + returnStatus); + var volunteers = []; + var connection = new Connection(config); + + connection.on('connect', (err) => { + if (err) { + context.log('Error: ', err); + context.done(err); + } + else { + if (req.method == 'POST') { + postEmergencyContact(); } - context.done(); - }); - - connection.execSql(request); - } + } + }); function postEmergencyContact() { const formInput = req.body; @@ -136,31 +61,39 @@ module.exports = function (context, req) { connection.execSql(request); } - function putVolunteers() { - var queryString = `UPDATE Volunteer SET isDeleted = 1 \ - WHERE volunteer.isDeleted = 0;`; + function postVolunteers(emergencyContactId) { + const formInput = req.body; + + const { firstName, lastName, email, phone, streetAddress, postalCode, mailingList } = formInput; + + var queryString = 'INSERT INTO Volunteer (firstName, lastName, phoneNumber, email, address, postalCode, mailingList, emergencyContactId, isDeleted) \ + VALUES (@firstName, @lastName, @phoneNumber, @email, @streetAddress, @postalCode, @mailingList, @emergencyContactId, @isDeleted)'; request = new Request(queryString, function (err) { if (err) { context.log(err); - - context.res = { - body: - 'Error occurred deleting volunteers from the database: \n' + err, - }; - - context.done(); + context.done(err); } }); - request.on('doneProc', function (rowCount, more, rows) { - context.res = { - body: { message: 'Successfully deleted volunteers from the database' }, - }; + request.addParameter('firstName', TYPES.NVarChar, firstName); + request.addParameter('lastName', TYPES.NVarChar, lastName); + request.addParameter('phoneNumber', TYPES.NVarChar, phone); + request.addParameter('email', TYPES.NVarChar, email); + request.addParameter('streetAddress', TYPES.NVarChar, streetAddress); + request.addParameter('postalCode', TYPES.NVarChar, postalCode); + request.addParameter('mailingList', TYPES.Bit, mailingList); + request.addParameter('emergencyContactId', TYPES.Int, emergencyContactId); + request.addParameter('isDeleted', TYPES.Bit, 0); + request.on('doneProc', function (rowCount, more, returnStatus, rows) { + if (returnStatus != 0) { + context.done('Error occurred: ' + returnStatus); + } context.done(); }); connection.execSql(request); } + }; From b9e43c8ce420d5261e1f6be4c586ad0b1df1957a Mon Sep 17 00:00:00 2001 From: Thai Ngoc Nguyen Date: Sat, 4 Apr 2020 01:03:01 -0700 Subject: [PATCH 5/9] ALP-108 Migrated history endpoint to admin app --- .../history/function.json | 7 +++++-- .../history/index.js | 1 - .../history/sample.dat | 0 3 files changed, 5 insertions(+), 3 deletions(-) rename {aunt-leahs-functions => aunt-leahs-functions-admin}/history/function.json (80%) rename {aunt-leahs-functions => aunt-leahs-functions-admin}/history/index.js (99%) rename {aunt-leahs-functions => aunt-leahs-functions-admin}/history/sample.dat (100%) diff --git a/aunt-leahs-functions/history/function.json b/aunt-leahs-functions-admin/history/function.json similarity index 80% rename from aunt-leahs-functions/history/function.json rename to aunt-leahs-functions-admin/history/function.json index 791385b..e8dee02 100644 --- a/aunt-leahs-functions/history/function.json +++ b/aunt-leahs-functions-admin/history/function.json @@ -5,7 +5,10 @@ "type": "httpTrigger", "direction": "in", "name": "req", - "methods": [ "get", "put" ], + "methods": [ + "get", + "put" + ], "route": "history" }, { @@ -14,4 +17,4 @@ "name": "res" } ] -} +} \ No newline at end of file diff --git a/aunt-leahs-functions/history/index.js b/aunt-leahs-functions-admin/history/index.js similarity index 99% rename from aunt-leahs-functions/history/index.js rename to aunt-leahs-functions-admin/history/index.js index 2255897..1c3a369 100644 --- a/aunt-leahs-functions/history/index.js +++ b/aunt-leahs-functions-admin/history/index.js @@ -92,4 +92,3 @@ module.exports = function (context, req) { connection.execSql(request); } }; - diff --git a/aunt-leahs-functions/history/sample.dat b/aunt-leahs-functions-admin/history/sample.dat similarity index 100% rename from aunt-leahs-functions/history/sample.dat rename to aunt-leahs-functions-admin/history/sample.dat From a0a8721b2ea10dc62703a692d28cb5e9b8d6b547 Mon Sep 17 00:00:00 2001 From: Thai Ngoc Nguyen Date: Sat, 4 Apr 2020 01:06:14 -0700 Subject: [PATCH 6/9] ALP-108 Migrate location endpoint --- .../location/function.json | 19 ++++++ aunt-leahs-functions-admin/location/index.js | 63 +++++++++++++++++++ .../location/sample.dat | 3 + aunt-leahs-functions/location/function.json | 6 +- aunt-leahs-functions/location/index.js | 54 ++-------------- aunt-leahs-functions/volunteerNames/index.js | 4 +- 6 files changed, 95 insertions(+), 54 deletions(-) create mode 100644 aunt-leahs-functions-admin/location/function.json create mode 100644 aunt-leahs-functions-admin/location/index.js create mode 100644 aunt-leahs-functions-admin/location/sample.dat diff --git a/aunt-leahs-functions-admin/location/function.json b/aunt-leahs-functions-admin/location/function.json new file mode 100644 index 0000000..4c2c1aa --- /dev/null +++ b/aunt-leahs-functions-admin/location/function.json @@ -0,0 +1,19 @@ +{ + "bindings": [ + { + "authLevel": "function", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "post", + "put" + ] + }, + { + "type": "http", + "direction": "out", + "name": "res" + } + ] +} \ No newline at end of file diff --git a/aunt-leahs-functions-admin/location/index.js b/aunt-leahs-functions-admin/location/index.js new file mode 100644 index 0000000..50f1b88 --- /dev/null +++ b/aunt-leahs-functions-admin/location/index.js @@ -0,0 +1,63 @@ +var Connection = require('tedious').Connection; +var Request = require('tedious').Request; +var config = require('../config'); +var TYPES = require('tedious').TYPES; + +module.exports = function(context, req) { + var connection = new Connection(config); + connection.on('connect', (err) => { + if (err) { + context.log('Error: ', err); + context.done(err); + } else { + if (req.method === 'POST') { + insertLocation(req.body.locations); + context.done(); + } else if (req.method === 'PUT') { + updateLocation(req.body.updatedLocation); + context.done(); + } + } + }); + + function updateLocation(newLocation) { + // Update the employee record requested + const { id, name, isDeleted } = newLocation; + request = new Request(`UPDATE dbo.Location SET name=@name, isDeleted=@isDeleted WHERE id = @id;`, function( + err, + rowCount, + rows + ) { + if (err) { + console.error(err); + context.done(err); + } else { + console.log(rowCount + ' row(s) updated'); + } + }); + request.addParameter('name', TYPES.NVarChar, name); + request.addParameter('id', TYPES.Int, id); + request.addParameter('isDeleted', TYPES.Bit, isDeleted); + // Execute SQL statement + connection.execSql(request); + } + + function insertLocation(locations) { + var options = { keepNulls: true }; + // instantiate - provide the table where you'll be inserting to, options and a callback + var bulkLoad = connection.newBulkLoad('Location', options, function(error, rowCount) { + console.log('inserted %d rows', rowCount); + }); + // setup your columns - always indicate whether the column is nullable + bulkLoad.addColumn('name', TYPES.NVarChar, { length: 50, nullable: false }); + bulkLoad.addColumn('isDeleted', TYPES.Bit, { nullable: false }); + + // add rows + locations.map((loc) => { + bulkLoad.addRow({ name: loc.name, isDeleted: 0 }); + }); + // execute + connection.execBulkLoad(bulkLoad); + } + +}; diff --git a/aunt-leahs-functions-admin/location/sample.dat b/aunt-leahs-functions-admin/location/sample.dat new file mode 100644 index 0000000..26aac46 --- /dev/null +++ b/aunt-leahs-functions-admin/location/sample.dat @@ -0,0 +1,3 @@ +{ + "name": "Azure" +} \ No newline at end of file diff --git a/aunt-leahs-functions/location/function.json b/aunt-leahs-functions/location/function.json index 24bb7df..eba49cf 100644 --- a/aunt-leahs-functions/location/function.json +++ b/aunt-leahs-functions/location/function.json @@ -5,7 +5,9 @@ "type": "httpTrigger", "direction": "in", "name": "req", - "methods": [ "get", "post", "put" ] + "methods": [ + "get" + ] }, { "type": "http", @@ -13,4 +15,4 @@ "name": "res" } ] -} +} \ No newline at end of file diff --git a/aunt-leahs-functions/location/index.js b/aunt-leahs-functions/location/index.js index d36d68c..e6604b4 100644 --- a/aunt-leahs-functions/location/index.js +++ b/aunt-leahs-functions/location/index.js @@ -3,7 +3,7 @@ var Request = require('tedious').Request; var config = require('../config'); var TYPES = require('tedious').TYPES; -module.exports = function(context, req) { +module.exports = function (context, req) { var connection = new Connection(config); connection.on('connect', (err) => { if (err) { @@ -12,58 +12,12 @@ module.exports = function(context, req) { } else { if (req.method === 'GET') { getLocations(); - } else if (req.method === 'POST') { - insertLocation(req.body.locations); - context.done(); - } else if (req.method === 'PUT') { - updateLocation(req.body.updatedLocation); - context.done(); } } }); - function updateLocation(newLocation) { - // Update the employee record requested - const { id, name, isDeleted } = newLocation; - request = new Request(`UPDATE dbo.Location SET name=@name, isDeleted=@isDeleted WHERE id = @id;`, function( - err, - rowCount, - rows - ) { - if (err) { - console.error(err); - context.done(err); - } else { - console.log(rowCount + ' row(s) updated'); - } - }); - request.addParameter('name', TYPES.NVarChar, name); - request.addParameter('id', TYPES.Int, id); - request.addParameter('isDeleted', TYPES.Bit, isDeleted); - // Execute SQL statement - connection.execSql(request); - } - - function insertLocation(locations) { - var options = { keepNulls: true }; - // instantiate - provide the table where you'll be inserting to, options and a callback - var bulkLoad = connection.newBulkLoad('Location', options, function(error, rowCount) { - console.log('inserted %d rows', rowCount); - }); - // setup your columns - always indicate whether the column is nullable - bulkLoad.addColumn('name', TYPES.NVarChar, { length: 50, nullable: false }); - bulkLoad.addColumn('isDeleted', TYPES.Bit, { nullable: false }); - - // add rows - locations.map((loc) => { - bulkLoad.addRow({ name: loc.name, isDeleted: 0 }); - }); - // execute - connection.execBulkLoad(bulkLoad); - } - function getLocations() { - request = new Request('SELECT [name],[id],[isDeleted] FROM [dbo].[Location] WHERE isDeleted = 0;', function(err) { + request = new Request('SELECT [name],[id],[isDeleted] FROM [dbo].[Location] WHERE isDeleted = 0;', function (err) { if (err) { context.log(err); context.done(err); @@ -71,9 +25,9 @@ module.exports = function(context, req) { }); let locations = []; - request.on('row', function(columns) { + request.on('row', function (columns) { let location = {}; - columns.forEach(function(column) { + columns.forEach(function (column) { location[column.metadata.colName] = column.value; }); locations.push(location); diff --git a/aunt-leahs-functions/volunteerNames/index.js b/aunt-leahs-functions/volunteerNames/index.js index 8f16a36..984c37e 100644 --- a/aunt-leahs-functions/volunteerNames/index.js +++ b/aunt-leahs-functions/volunteerNames/index.js @@ -10,7 +10,7 @@ module.exports = function (context, req) { connection.on('connect', (err) => { if (err) { context.log('Error: ', err); - context.done(); + context.done(err); } else { getVolunteerNames(); @@ -23,7 +23,7 @@ module.exports = function (context, req) { function(err) { if (err) { context.log(err); - context.done(); + context.done(err); } }); From 540c16108e47419ee21e7d5861ec6108890f65ba Mon Sep 17 00:00:00 2001 From: Thai Ngoc Nguyen Date: Sat, 4 Apr 2020 01:13:25 -0700 Subject: [PATCH 7/9] ALP-108 Fix settings --- aunt-leahs-functions-admin/.vscode/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aunt-leahs-functions-admin/.vscode/settings.json b/aunt-leahs-functions-admin/.vscode/settings.json index b4d6b1d..1bc725a 100644 --- a/aunt-leahs-functions-admin/.vscode/settings.json +++ b/aunt-leahs-functions-admin/.vscode/settings.json @@ -1,5 +1,5 @@ { - "azureFunctions.projectRuntime": "~2", + "azureFunctions.projectRuntime": "~3", "azureFunctions.projectLanguage": "JavaScript", "azureFunctions.deploySubpath": ".", "azureFunctions.preDeployTask": "func: extensions install", From af456a5a675e8ee9cb4e3d680e0bbd88aaa2d581 Mon Sep 17 00:00:00 2001 From: Thai Ngoc Nguyen Date: Sat, 4 Apr 2020 13:48:11 -0700 Subject: [PATCH 8/9] ALP-108 add tedious --- aunt-leahs-functions-admin/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aunt-leahs-functions-admin/package-lock.json b/aunt-leahs-functions-admin/package-lock.json index 3891d1e..8cd8d1d 100644 --- a/aunt-leahs-functions-admin/package-lock.json +++ b/aunt-leahs-functions-admin/package-lock.json @@ -40,9 +40,9 @@ "integrity": "sha512-OWm/xa9O9e4ugzNHoRT3IsXZZYfaV6Ia1aRwctOmCQ2GYWMnhKBzMC1WomqCh/oGxEZKNtPy5xv5//VIAOgMqw==" }, "@types/node": { - "version": "13.9.8", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.9.8.tgz", - "integrity": "sha512-1WgO8hsyHynlx7nhP1kr0OFzsgKz5XDQL+Lfc3b1Q3qIln/n8cKD4m09NJ0+P1Rq7Zgnc7N0+SsMnoD1rEb0kA==" + "version": "13.11.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.11.0.tgz", + "integrity": "sha512-uM4mnmsIIPK/yeO+42F2RQhGUIs39K2RFmugcJANppXe6J1nvH87PvzPZYpza7Xhhs8Yn9yIAVdLZ84z61+0xQ==" }, "@types/tunnel": { "version": "0.0.0", From 8a1d1f3923a2a6220914af2fa351cf3e6618ed02 Mon Sep 17 00:00:00 2001 From: Thai Ngoc Nguyen Date: Sat, 4 Apr 2020 14:25:31 -0700 Subject: [PATCH 9/9] ALP-108 Modify function auth level --- aunt-leahs-functions-admin/location/function.json | 2 +- aunt-leahs-functions/location/function.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aunt-leahs-functions-admin/location/function.json b/aunt-leahs-functions-admin/location/function.json index 4c2c1aa..e23aaf6 100644 --- a/aunt-leahs-functions-admin/location/function.json +++ b/aunt-leahs-functions-admin/location/function.json @@ -1,7 +1,7 @@ { "bindings": [ { - "authLevel": "function", + "authLevel": "anonymous", "type": "httpTrigger", "direction": "in", "name": "req", diff --git a/aunt-leahs-functions/location/function.json b/aunt-leahs-functions/location/function.json index eba49cf..db2fc37 100644 --- a/aunt-leahs-functions/location/function.json +++ b/aunt-leahs-functions/location/function.json @@ -1,7 +1,7 @@ { "bindings": [ { - "authLevel": "function", + "authLevel": "anonymous", "type": "httpTrigger", "direction": "in", "name": "req",