text clean up
This commit is contained in:
@@ -10,13 +10,9 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
down: async (queryInterface, Sequelize) => {
|
down: async (queryInterface, Sequelize) => {
|
||||||
// Note: PostgreSQL does not support removing values from ENUMs directly.
|
|
||||||
// The 'requires_action' value will remain in the enum but can be unused.
|
|
||||||
// To fully remove it would require recreating the enum and column,
|
|
||||||
// which is complex and risky for production data.
|
|
||||||
console.log(
|
console.log(
|
||||||
"Note: PostgreSQL does not support removing ENUM values. " +
|
"Note: PostgreSQL does not support removing ENUM values. " +
|
||||||
"'requires_action' will remain in the enum but will not be used."
|
"'requires_action' will remain in the enum but will not be used.",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,10 +9,8 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
down: async (queryInterface, Sequelize) => {
|
down: async (queryInterface, Sequelize) => {
|
||||||
// Note: PostgreSQL doesn't support removing enum values directly
|
|
||||||
// This would require recreating the enum type
|
|
||||||
console.log(
|
console.log(
|
||||||
"Cannot remove enum value - manual intervention required if rollback needed"
|
"Cannot remove enum value - manual intervention required if rollback needed",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
process.env.NODE_ENV = 'test';
|
process.env.NODE_ENV = "test";
|
||||||
process.env.JWT_SECRET = 'test-secret';
|
process.env.JWT_SECRET = "test-secret";
|
||||||
process.env.DATABASE_URL = 'postgresql://test';
|
process.env.DATABASE_URL = "db://test";
|
||||||
process.env.GOOGLE_MAPS_API_KEY = 'test-key';
|
process.env.GOOGLE_MAPS_API_KEY = "test-key";
|
||||||
process.env.STRIPE_SECRET_KEY = 'sk_test_key';
|
process.env.STRIPE_SECRET_KEY = "sk_test_key";
|
||||||
process.env.CSRF_SECRET = 'test-csrf-secret-that-is-at-least-32-chars-long';
|
process.env.CSRF_SECRET = "test-csrf-secret-that-is-at-least-32-chars-long";
|
||||||
|
|
||||||
// Silence console
|
// Silence console
|
||||||
global.console = {
|
global.console = {
|
||||||
...console,
|
...console,
|
||||||
log: jest.fn(),
|
log: jest.fn(),
|
||||||
error: jest.fn(),
|
error: jest.fn(),
|
||||||
warn: jest.fn()
|
warn: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Sends email reminders to owners and renters to complete condition checks at key
|
|||||||
## Check Types
|
## Check Types
|
||||||
|
|
||||||
| Check Type | Recipient | Timing |
|
| Check Type | Recipient | Timing |
|
||||||
|------------|-----------|--------|
|
| --------------------- | --------- | ---------------------------- |
|
||||||
| `pre_rental_owner` | Owner | 24 hours before rental start |
|
| `pre_rental_owner` | Owner | 24 hours before rental start |
|
||||||
| `rental_start_renter` | Renter | At rental start |
|
| `rental_start_renter` | Renter | At rental start |
|
||||||
| `rental_end_renter` | Renter | At rental end |
|
| `rental_end_renter` | Renter | At rental end |
|
||||||
@@ -22,11 +22,6 @@ cd ../conditionCheckReminder && npm install
|
|||||||
|
|
||||||
### Set Up Environment
|
### Set Up Environment
|
||||||
|
|
||||||
```bash
|
|
||||||
cp .env.example .env.dev
|
|
||||||
# Edit .env.dev with your DATABASE_URL
|
|
||||||
```
|
|
||||||
|
|
||||||
### Run Locally
|
### Run Locally
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -36,18 +31,3 @@ npm run local
|
|||||||
# Specify rental ID and check type
|
# Specify rental ID and check type
|
||||||
node -r dotenv/config test-local.js dotenv_config_path=.env.dev 123 rental_start_renter
|
node -r dotenv/config test-local.js dotenv_config_path=.env.dev 123 rental_start_renter
|
||||||
```
|
```
|
||||||
|
|
||||||
## Environment Variables
|
|
||||||
|
|
||||||
| Variable | Description | Example |
|
|
||||||
|----------|-------------|---------|
|
|
||||||
| `DATABASE_URL` | PostgreSQL connection string | `postgresql://user:pass@localhost:5432/rentall` |
|
|
||||||
| `FRONTEND_URL` | Frontend URL for email links | `http://localhost:3000` |
|
|
||||||
| `SES_FROM_EMAIL` | Sender email address | `noreply@villageshare.app` |
|
|
||||||
| `EMAIL_ENABLED` | Enable/disable email sending | `false` |
|
|
||||||
| `SCHEDULE_GROUP_NAME` | EventBridge schedule group | `condition-check-reminders-dev` |
|
|
||||||
| `AWS_REGION` | AWS region | `us-east-1` |
|
|
||||||
|
|
||||||
## Deployment
|
|
||||||
|
|
||||||
See [infrastructure/cdk/README.md](../../infrastructure/cdk/README.md) for deployment instructions.
|
|
||||||
|
|||||||
@@ -1,41 +1,29 @@
|
|||||||
/**
|
/**
|
||||||
* Local test script for the condition check reminder lambda
|
* Local test script for the condition check reminder lambda
|
||||||
*
|
|
||||||
* Usage:
|
|
||||||
* 1. Set environment variables (or create a .env file)
|
|
||||||
* 2. Run: node test-local.js
|
|
||||||
*
|
|
||||||
* Required environment variables:
|
|
||||||
* - DATABASE_URL: PostgreSQL connection string
|
|
||||||
* - FRONTEND_URL: Frontend URL for email links
|
|
||||||
* - SES_FROM_EMAIL: Email sender address
|
|
||||||
* - EMAIL_ENABLED: Set to 'false' to skip actual email sending
|
|
||||||
* - SCHEDULE_GROUP_NAME: EventBridge schedule group name
|
|
||||||
* - AWS_REGION: AWS region
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { handler } = require('./index');
|
const { handler } = require("./index");
|
||||||
|
|
||||||
// Test event - modify these values as needed
|
// Test event - modify these values as needed
|
||||||
const testEvent = {
|
const testEvent = {
|
||||||
rentalId: parseInt(process.argv[2]) || 1, // Pass rental ID as CLI arg or default to 1
|
rentalId: parseInt(process.argv[2]) || 1, // Pass rental ID as CLI arg or default to 1
|
||||||
checkType: process.argv[3] || 'pre_rental_owner' // Options: pre_rental_owner, rental_start_renter, rental_end_renter, post_rental_owner
|
checkType: process.argv[3] || "pre_rental_owner", // Options: pre_rental_owner, rental_start_renter, rental_end_renter, post_rental_owner
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('Running condition check reminder lambda locally...');
|
console.log("Running condition check reminder lambda locally...");
|
||||||
console.log('Event:', JSON.stringify(testEvent, null, 2));
|
console.log("Event:", JSON.stringify(testEvent, null, 2));
|
||||||
console.log('---');
|
console.log("---");
|
||||||
|
|
||||||
handler(testEvent)
|
handler(testEvent)
|
||||||
.then(result => {
|
.then((result) => {
|
||||||
console.log('---');
|
console.log("---");
|
||||||
console.log('Success!');
|
console.log("Success!");
|
||||||
console.log('Result:', JSON.stringify(result, null, 2));
|
console.log("Result:", JSON.stringify(result, null, 2));
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
console.error('---');
|
console.error("---");
|
||||||
console.error('Error:', err.message);
|
console.error("Error:", err.message);
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,17 +20,6 @@ cd lambdas/shared && npm install
|
|||||||
cd ../imageProcessor && npm install
|
cd ../imageProcessor && npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
### Set Up Environment
|
|
||||||
|
|
||||||
## Environment Variables
|
|
||||||
|
|
||||||
| Variable | Description | Example |
|
|
||||||
| -------------- | ---------------------------- | ----------------------------------------------- |
|
|
||||||
| `DATABASE_URL` | PostgreSQL connection string | `postgresql://user:pass@localhost:5432/db-name` |
|
|
||||||
| `S3_BUCKET` | S3 bucket name | `bucket-name` |
|
|
||||||
| `AWS_REGION` | AWS region | `us-east-1` |
|
|
||||||
| `LOG_LEVEL` | Logging level | `debug`, `info`, `warn`, `error` |
|
|
||||||
|
|
||||||
### Run Locally
|
### Run Locally
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -2,12 +2,6 @@
|
|||||||
|
|
||||||
Retries failed Stripe payouts daily. Triggered by EventBridge Scheduler at 7 AM EST.
|
Retries failed Stripe payouts daily. Triggered by EventBridge Scheduler at 7 AM EST.
|
||||||
|
|
||||||
## Prerequisites
|
|
||||||
|
|
||||||
- Node.js 20.x
|
|
||||||
- PostgreSQL database with rentals data
|
|
||||||
- Stripe account with test API key (`sk_test_...`)
|
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
1. Install shared dependencies:
|
1. Install shared dependencies:
|
||||||
@@ -23,17 +17,6 @@ Retries failed Stripe payouts daily. Triggered by EventBridge Scheduler at 7 AM
|
|||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
## Environment Variables
|
|
||||||
|
|
||||||
| Variable | Description |
|
|
||||||
| ------------------- | ---------------------------------------------- |
|
|
||||||
| `DATABASE_URL` | PostgreSQL connection string |
|
|
||||||
| `STRIPE_SECRET_KEY` | Stripe API key (use `sk_test_...` for testing) |
|
|
||||||
| `FRONTEND_URL` | For email template links |
|
|
||||||
| `SES_FROM_EMAIL` | Sender email address |
|
|
||||||
| `SES_FROM_NAME` | Sender display name |
|
|
||||||
| `EMAIL_ENABLED` | Set to `true` to send emails |
|
|
||||||
|
|
||||||
## Local Testing
|
## Local Testing
|
||||||
|
|
||||||
Run the Lambda locally using your dev environment:
|
Run the Lambda locally using your dev environment:
|
||||||
@@ -94,7 +77,7 @@ EventBridge Scheduler (7 AM EST daily)
|
|||||||
v
|
v
|
||||||
Lambda Function
|
Lambda Function
|
||||||
|
|
|
|
||||||
+-- Query failed payouts from PostgreSQL
|
+-- Query failed payouts from database
|
||||||
|
|
|
|
||||||
+-- For each failed payout:
|
+-- For each failed payout:
|
||||||
| +-- Reset status to "pending"
|
| +-- Reset status to "pending"
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ let pool = null;
|
|||||||
* Uses connection pooling optimized for Lambda:
|
* Uses connection pooling optimized for Lambda:
|
||||||
* - Reuses connections across invocations (when container is warm)
|
* - Reuses connections across invocations (when container is warm)
|
||||||
* - Small pool size to avoid exhausting database connections
|
* - Small pool size to avoid exhausting database connections
|
||||||
*
|
|
||||||
* Expects DATABASE_URL environment variable in format:
|
|
||||||
* postgresql://user:password@host:port/database
|
|
||||||
*/
|
*/
|
||||||
function getPool() {
|
function getPool() {
|
||||||
if (!pool) {
|
if (!pool) {
|
||||||
@@ -51,22 +48,26 @@ async function query(text, params) {
|
|||||||
const result = await pool.query(text, params);
|
const result = await pool.query(text, params);
|
||||||
const duration = Date.now() - start;
|
const duration = Date.now() - start;
|
||||||
|
|
||||||
console.log(JSON.stringify({
|
console.log(
|
||||||
|
JSON.stringify({
|
||||||
level: "debug",
|
level: "debug",
|
||||||
message: "Executed query",
|
message: "Executed query",
|
||||||
query: text.substring(0, 100),
|
query: text.substring(0, 100),
|
||||||
duration,
|
duration,
|
||||||
rows: result.rowCount,
|
rows: result.rowCount,
|
||||||
}));
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(JSON.stringify({
|
console.error(
|
||||||
|
JSON.stringify({
|
||||||
level: "error",
|
level: "error",
|
||||||
message: "Query failed",
|
message: "Query failed",
|
||||||
query: text.substring(0, 100),
|
query: text.substring(0, 100),
|
||||||
error: error.message,
|
error: error.message,
|
||||||
}));
|
}),
|
||||||
|
);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user