Skip to content

Commit 4c9f536

Browse files
committed
fix: ordering of segments
1 parent fb55cc8 commit 4c9f536

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

packages/platform/src/services/GameService.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,12 @@ export async function activateNextPeriod(
564564
},
565565
})
566566

567+
// reset player readiness
568+
await tx.player.updateMany({
569+
where: { game: { id: gameId } },
570+
data: { isReady: false },
571+
})
572+
567573
for (const extra of extras) {
568574
await extra
569575
}
@@ -676,6 +682,12 @@ export async function activateNextPeriod(
676682
include: { results: true },
677683
})
678684

685+
// reset player readiness
686+
await tx.player.updateMany({
687+
where: { game: { id: gameId } },
688+
data: { isReady: false },
689+
})
690+
679691
for (const extra of extras) {
680692
await extra
681693
}
@@ -760,6 +772,12 @@ export async function activateNextPeriod(
760772
},
761773
}),
762774

775+
// reset player readiness
776+
ctx.prisma.player.updateMany({
777+
where: { game: { id: gameId } },
778+
data: { isReady: false },
779+
}),
780+
763781
...extras,
764782
])
765783

@@ -818,7 +836,7 @@ export async function activateNextSegment(
818836
include: {
819837
activePeriod: {
820838
include: {
821-
segments: { include: { nextSegment: true } },
839+
segments: { orderBy: { index: 'asc' }, include: { nextSegment: true } },
822840
results: { include: { player: true } },
823841
activeSegment: {
824842
include: {
@@ -914,6 +932,12 @@ export async function activateNextSegment(
914932
},
915933
})
916934

935+
// reset player readiness
936+
await tx.player.updateMany({
937+
where: { game: { id: gameId } },
938+
data: { isReady: false },
939+
})
940+
917941
for (const extra of extras) {
918942
await extra
919943
}

packages/platform/src/services/PlayService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ export async function getPlayerResult(args: GetPlayerResultArgs, ctx: Context) {
326326
},
327327
},
328328
segments: {
329+
orderBy: { index: 'asc' },
329330
include: {
330331
learningElements: true,
331332
storyElements: true,
@@ -337,6 +338,7 @@ export async function getPlayerResult(args: GetPlayerResultArgs, ctx: Context) {
337338
orderBy: { createdAt: 'asc' },
338339
include: {
339340
segments: {
341+
orderBy: { index: 'asc' },
340342
include: {
341343
learningElements: true,
342344
storyElements: true,
@@ -359,12 +361,12 @@ export async function getPlayerResult(args: GetPlayerResultArgs, ctx: Context) {
359361
// should not be visible to the user
360362
const activePeriodIx = currentGame.activePeriodIx
361363
currentGame.periods = currentGame.periods.filter(
362-
(_, ix) => ix <= activePeriodIx
364+
(period) => period.index <= activePeriodIx
363365
)
364366
const activeSegmentIx = currentGame.activePeriod.activeSegmentIx
365367

366368
currentGame.activePeriod.segments = currentGame.activePeriod.segments.filter(
367-
(_, ix) => ix <= activeSegmentIx
369+
(segment) => segment.index <= activeSegmentIx
368370
)
369371

370372
currentGame.periods[activePeriodIx]!.segments =

0 commit comments

Comments
 (0)