Skip to content

Commit

Permalink
feat(users router): write to both but only fail RDS
Browse files Browse the repository at this point in the history
  • Loading branch information
MinhxNguyen7 committed Dec 7, 2024
1 parent 7d87792 commit 97153af
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions apps/backend/src/routers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { mangleDupliateScheduleNames } from 'src/lib/formatting';
import { RDS } from 'src/lib/rds';
import { TRPCError } from '@trpc/server';
import { procedure, router } from '../trpc';
import { ddbClient } from '$db/ddb';


const userInputSchema = type([{ userId: 'string' }, '|', { googleId: 'string' }]);

Expand Down Expand Up @@ -52,8 +54,17 @@ const usersRouter = router({
// Mangle duplicate schedule names
data.userData.schedules = mangleDupliateScheduleNames(data.userData.schedules);

await RDS.upsertGuestUserData(db, data)
.catch((error) => console.error('Failed to upsert user data:', error));
// Await both, but only throw if RDS save fails.
const results = await Promise.allSettled([
ddbClient.insertItem(data)
.catch((error) => console.error('DDB Failed to save user data:', error)),
RDS.upsertGuestUserData(db, data)
.catch((error) => console.error('RDS Failed to upsert user data:', error))
]);

if (results[1].status === 'rejected') {
throw results[1].reason;
}
}
),
});
Expand Down

0 comments on commit 97153af

Please sign in to comment.