Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pacific Power exclusion endpoint #315

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions backend/app/pacific_power_exclusion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const Response = require('/opt/nodejs/response.js')
const PacificPowerExclusion = require('/opt/nodejs/models/pacific_power_exclusion.js')

exports.get = async (event, context) => {
let response = new Response(event)
response.body = JSON.stringify(await new PacificPowerExclusion().get())
return response
}

exports.post = async (event, context) => {
let response = new Response(event)

const payload = JSON.parse(event.body)
const pwd = payload['pwd']
const meterID = payload['id']

if (pwd !== process.env.ACQUISUITE_PASS || !meterID) {
response.statusCode = 400
return response
}

try {
response.body = JSON.stringify(await new PacificPowerExclusion().add(meterID))
} catch (error) {
response.body = error.message
response.statusCode = 400
}
return response
}
19 changes: 19 additions & 0 deletions backend/dependencies/nodejs/models/pacific_power_exclusion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const DB = require('/opt/nodejs/sql-access.js')

class PacificPowerExclusion {
async get() {
await DB.connect()
return DB.query(`SELECT * FROM pacific_power_exclusion`)
}

async add(meterID) {
await DB.connect()
return DB.query(`INSERT INTO pacific_power_exclusion (pp_meter_id, status, date_added) VALUES (?, ?, ?)`, [
meterID,
'new',
new Date().toISOString()
])
}
}

module.exports = PacificPowerExclusion
90 changes: 60 additions & 30 deletions backend/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Globals:
# enable CORS; to make more specific, change the origin wildcard
# to a particular domain name, e.g. "'www.example.com'"
Cors:
AllowMethods: "'POST, GET'"
AllowHeaders: "'X-Forwarded-For'"
AllowOrigin: "'oregonstate.edu'"
MaxAge: "'600'"
AllowCredentials: True
AllowMethods: "'POST, GET'"
AllowHeaders: "'X-Forwarded-For'"
AllowOrigin: "'oregonstate.edu'"
MaxAge: "'600'"
AllowCredentials: True
BinaryMediaTypes:
- image~1gif
- image~1png
Expand All @@ -26,20 +26,20 @@ Globals:
- multipart/form-data
HttpApi:
CorsConfiguration:
AllowMethods:
- GET
- POST
AllowHeaders:
- "'X-Forwarded-For'"
AllowOrigins:
- "https://dashboard.sustainability.oregonstate.edu"
MaxAge: 600
AllowCredentials: True
AllowMethods:
- GET
- POST
AllowHeaders:
- "'X-Forwarded-For'"
AllowOrigins:
- 'https://dashboard.sustainability.oregonstate.edu'
MaxAge: 600
AllowCredentials: True
Parameters:
LambdaCommonLayer:
Type: String
Default: arn:aws:lambda:us-west-2:005937143026:layer:LambdaCommonLayer:97

Resources:
test:
Type: AWS::Serverless::Function
Expand Down Expand Up @@ -238,7 +238,7 @@ Resources:
Properties:
Timeout: 30
MemorySize: 256
CodeUri: app/
CodeUri: app/
Handler: meter.batchData
Layers:
- !Ref LambdaCommonLayer
Expand Down Expand Up @@ -718,18 +718,48 @@ Resources:
Properties:
Path: /admin/devices
Method: get
ppExclude:
Type: AWS::Serverless::Function
Properties:
MemorySize: 128
CodeUri: app/
Handler: pacific_power_exclusion.get
Layers:
- !Ref LambdaCommonLayer
- !Ref EnergyModelLayer
Events:
Building:
Type: Api
Properties:
Path: /ppexclude
Method: get
ppUpload:
Type: AWS::Serverless::Function
Properties:
MemorySize: 128
CodeUri: app/
Handler: pacific_power_exclusion.post
Layers:
- !Ref LambdaCommonLayer
- !Ref EnergyModelLayer
Events:
Building:
Type: Api
Properties:
Path: /ppupload
Method: post
EnergyModelLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: EnergyModelLayer
Description: DB Model Defs
ContentUri: dependencies/
CompatibleRuntimes:
- nodejs6.10
- nodejs8.10
- nodejs10.x
- nodejs12.x
- nodejs16.x
- nodejs18.x
LicenseInfo: 'MIT'
RetentionPolicy: Retain
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: EnergyModelLayer
Description: DB Model Defs
ContentUri: dependencies/
CompatibleRuntimes:
- nodejs6.10
- nodejs8.10
- nodejs10.x
- nodejs12.x
- nodejs16.x
- nodejs18.x
LicenseInfo: 'MIT'
RetentionPolicy: Retain
Loading