Skip to content

Commit

Permalink
Merge pull request #30 from passadis/dev
Browse files Browse the repository at this point in the history
Az Function
  • Loading branch information
passadis authored Nov 12, 2024
2 parents 3f7c86d + e3c0262 commit 959a382
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 0 deletions.
10 changes: 10 additions & 0 deletions AzureFunction/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.js.map
*.ts
.git*
.vscode
__azurite_db*__.json
__blobstorage__
__queuestorage__
local.settings.json
test
tsconfig.json
99 changes: 99 additions & 0 deletions AzureFunction/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# 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

# Azurite artifacts
__blobstorage__
__queuestorage__
__azurite_db*__.json
15 changes: 15 additions & 0 deletions AzureFunction/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
13 changes: 13 additions & 0 deletions AzureFunction/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions AzureFunction/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "functions2",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "func start",
"test": "echo \"No tests yet...\""
},
"dependencies": {},
"devDependencies": {}
}
24 changes: 24 additions & 0 deletions AzureFunction/recommendationsReady/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": ["post"],
"route": "update-recommendations"
},
{
"type": "sql",
"commandText": "dbo.Users",
"connectionStringSetting": "AzureSqlConnectionString",
"direction": "out",
"name": "outputSql"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
26 changes: 26 additions & 0 deletions AzureFunction/recommendationsReady/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = async function (context, req) {
const { userId } = req.body;

// Input validation
if (!userId) {
context.res = {
status: 400,
body: "User ID is required."
};
return;
}

// Prepare the object to be written to the database
const outputRecord = {
UserId: userId,
RecommendationsReady: true
};

// Assign the output to the SQL binding
context.bindings.outputSql = outputRecord;

context.res = {
status: 200,
body: `User ${userId}'s recommendations status updated to true`
};
};

0 comments on commit 959a382

Please sign in to comment.