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;
|
savedAt: number;
|
||||||
restStartedAt: number | null;
|
restStartedAt: number | null;
|
||||||
restTotal: number;
|
restTotal: number;
|
||||||
|
restExerciseIdx: number;
|
||||||
|
restSetIdx: number;
|
||||||
updatedAt?: Date;
|
updatedAt?: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +89,14 @@ const ActiveWorkoutSchema = new mongoose.Schema(
|
|||||||
restTotal: {
|
restTotal: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0
|
default: 0
|
||||||
|
},
|
||||||
|
restExerciseIdx: {
|
||||||
|
type: Number,
|
||||||
|
default: -1
|
||||||
|
},
|
||||||
|
restSetIdx: {
|
||||||
|
type: Number,
|
||||||
|
default: -1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export const PUT: RequestHandler = async ({ request, locals }) => {
|
|||||||
try {
|
try {
|
||||||
await dbConnect();
|
await dbConnect();
|
||||||
const data = await request.json();
|
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) {
|
if (!name) {
|
||||||
return json({ error: 'Name is required' }, { status: 400 });
|
return json({ error: 'Name is required' }, { status: 400 });
|
||||||
@@ -65,6 +65,8 @@ export const PUT: RequestHandler = async ({ request, locals }) => {
|
|||||||
savedAt: savedAt ?? Date.now(),
|
savedAt: savedAt ?? Date.now(),
|
||||||
restStartedAt: restStartedAt ?? null,
|
restStartedAt: restStartedAt ?? null,
|
||||||
restTotal: restTotal ?? 0,
|
restTotal: restTotal ?? 0,
|
||||||
|
restExerciseIdx: restExerciseIdx ?? -1,
|
||||||
|
restSetIdx: restSetIdx ?? -1,
|
||||||
version: newVersion
|
version: newVersion
|
||||||
},
|
},
|
||||||
$setOnInsert: { userId }
|
$setOnInsert: { userId }
|
||||||
|
|||||||
Reference in New Issue
Block a user