Additional drizzle cleanup. Move scrub transformation to server side.
This commit is contained in:
93
REFACTORING_NOTES.md
Normal file
93
REFACTORING_NOTES.md
Normal file
@@ -0,0 +1,93 @@
|
||||
# Refactoring Summary: Server-Side Transformation
|
||||
|
||||
## Overview
|
||||
Moved the job transformation logic from the Electron app to the Lambda function to enable server-side processing and sharing of types between codebases.
|
||||
|
||||
## Changes Made
|
||||
|
||||
### 1. Shared Types Directory (`/shared/types/`)
|
||||
Created a shared types directory that both the Electron app and serverless Lambda can use:
|
||||
|
||||
- **`raw-job-data.interface.ts`** - Defines the `RawJobDataObject` interface with all fields from the decoded job data
|
||||
- **`es-job-object.interface.ts`** - Defines the `ESJobObject` interface for the transformed estimate scrubber format
|
||||
- **`index.ts`** - Exports all shared types for easy importing
|
||||
|
||||
### 2. Serverless Changes
|
||||
|
||||
#### `serverless/src/lib/transformEstimate.ts`
|
||||
- Moved transformation logic from `src/main/estimate-scrubber/es-transformer.ts`
|
||||
- Exports `transformJobForEstimateScrubber()` function
|
||||
- Imports shared types from `../../../shared/types`
|
||||
- Handles all field omissions and transformations server-side
|
||||
|
||||
#### `serverless/src/handlers/scrub.ts`
|
||||
- Updated to receive `rawJob` instead of pre-transformed `estimate`
|
||||
- Calls `transformJobForEstimateScrubber()` to transform on the server
|
||||
- Sets `v_type` using the existing `getVehicleType()` function
|
||||
- Updated TypeScript interfaces to use shared types
|
||||
|
||||
#### `serverless/package.json`
|
||||
- Added `lodash` dependency
|
||||
- Added `@types/lodash` dev dependency
|
||||
|
||||
#### `serverless/tsconfig.json`
|
||||
- Updated `include` to add `"../shared/**/*"` for shared types access
|
||||
|
||||
### 3. Electron App Changes
|
||||
|
||||
#### `src/main/estimate-scrubber/estimate-scrubber.ts`
|
||||
- Removed call to `TransformJobForEstimateScrubber()`
|
||||
- Now sends raw job object directly to Lambda as `rawJob`
|
||||
- Removed import of `es-transformer`
|
||||
- Transformation now happens server-side
|
||||
|
||||
#### `tsconfig.node.json`
|
||||
- Updated `include` array to add `"shared/**/*"` for shared types access
|
||||
|
||||
### 4. Files That Can Be Deprecated (Optional)
|
||||
- `src/main/estimate-scrubber/es-transformer.ts` - Logic moved to serverless
|
||||
- `src/main/estimate-scrubber/es-job-object.interface.ts` - Moved to shared types
|
||||
|
||||
## Benefits
|
||||
|
||||
1. **Single Source of Truth**: Types are defined once in `/shared/types/` and used by both codebases
|
||||
2. **Server-Side Processing**: Transformation logic runs on Lambda, reducing client-side processing
|
||||
3. **Easier Maintenance**: Updates to transformation logic or types only need to be made in one place
|
||||
4. **Type Safety**: Both Electron app and Lambda use the same TypeScript interfaces
|
||||
5. **Reduced Bundle Size**: Electron app no longer includes transformation logic
|
||||
|
||||
## API Contract Changes
|
||||
|
||||
### Before
|
||||
```typescript
|
||||
POST /scrub
|
||||
{
|
||||
esApiKey: string,
|
||||
estimate: ESJobObject, // Pre-transformed
|
||||
fileName: string
|
||||
}
|
||||
```
|
||||
|
||||
### After
|
||||
```typescript
|
||||
POST /scrub
|
||||
{
|
||||
esApiKey: string,
|
||||
rawJob: RawJobDataObject // Raw, untransformed
|
||||
}
|
||||
```
|
||||
|
||||
## Migration Notes
|
||||
|
||||
- The Lambda function now handles all transformation logic
|
||||
- Ensure both codebases have access to the `/shared/types/` directory
|
||||
- Run `npm install` in the serverless directory to get new dependencies
|
||||
- The `fileName` parameter is now generated server-side based on the raw job data
|
||||
|
||||
## Testing Recommendations
|
||||
|
||||
1. Test that raw job objects are correctly sent from Electron to Lambda
|
||||
2. Verify transformation logic produces identical output to previous version
|
||||
3. Ensure PDF generation and report URLs are working correctly
|
||||
4. Check that error handling still works as expected
|
||||
5. Validate that logs are being written correctly with transformed data
|
||||
Reference in New Issue
Block a user