fix: sync rest timer exercise/set indices across sessions
All checks were successful
CI / update (push) Successful in 2m2s
All checks were successful
CI / update (push) Successful in 2m2s
restExerciseIdx and restSetIdx were sent by the client but never persisted server-side, so other sessions couldn't display which exercise/set the rest timer belonged to.
This commit is contained in:
@@ -25,6 +25,8 @@ export interface IActiveWorkout {
|
||||
savedAt: number;
|
||||
restStartedAt: number | null;
|
||||
restTotal: number;
|
||||
restExerciseIdx: number;
|
||||
restSetIdx: number;
|
||||
updatedAt?: Date;
|
||||
}
|
||||
|
||||
@@ -87,6 +89,14 @@ const ActiveWorkoutSchema = new mongoose.Schema(
|
||||
restTotal: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
restExerciseIdx: {
|
||||
type: Number,
|
||||
default: -1
|
||||
},
|
||||
restSetIdx: {
|
||||
type: Number,
|
||||
default: -1
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ export const PUT: RequestHandler = async ({ request, locals }) => {
|
||||
try {
|
||||
await dbConnect();
|
||||
const data = await request.json();
|
||||
const { name, templateId, exercises, paused, elapsed, savedAt, expectedVersion, restStartedAt, restTotal } = data;
|
||||
const { name, templateId, exercises, paused, elapsed, savedAt, expectedVersion, restStartedAt, restTotal, restExerciseIdx, restSetIdx } = data;
|
||||
|
||||
if (!name) {
|
||||
return json({ error: 'Name is required' }, { status: 400 });
|
||||
@@ -65,6 +65,8 @@ export const PUT: RequestHandler = async ({ request, locals }) => {
|
||||
savedAt: savedAt ?? Date.now(),
|
||||
restStartedAt: restStartedAt ?? null,
|
||||
restTotal: restTotal ?? 0,
|
||||
restExerciseIdx: restExerciseIdx ?? -1,
|
||||
restSetIdx: restSetIdx ?? -1,
|
||||
version: newVersion
|
||||
},
|
||||
$setOnInsert: { userId }
|
||||
|
||||
Reference in New Issue
Block a user