added post-listening rating
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { db } from '$lib/server/db/index.js';
|
||||
import { inviteLink, participant, audioFile, rating } from '$lib/server/db/schema.js';
|
||||
import { inviteLink, participant, audioFile, rating, overallRating } from '$lib/server/db/schema.js';
|
||||
import { eq, isNull, and, inArray } from 'drizzle-orm';
|
||||
import { parseStoredTags, matchesInviteTags } from '$lib/server/tag-utils.js';
|
||||
import { env } from '$env/dynamic/private';
|
||||
|
||||
export async function load({ url, cookies }) {
|
||||
const token = url.searchParams.get('token');
|
||||
@@ -97,31 +98,47 @@ export async function load({ url, cookies }) {
|
||||
|
||||
const allowedAudioIds = filteredAudio.map((file) => file.id);
|
||||
|
||||
// Get completed ratings for this participant (only active, non-deleted ratings for active audio files)
|
||||
const displayContinuousRating = env.DISPLAY_CONT_RATING !== 'false';
|
||||
let completedRatings = [];
|
||||
if (allowedAudioIds.length > 0) {
|
||||
completedRatings = await db
|
||||
.select({
|
||||
audioFileId: rating.audioFileId
|
||||
})
|
||||
.from(rating)
|
||||
.innerJoin(audioFile, and(
|
||||
eq(rating.audioFileId, audioFile.id),
|
||||
isNull(audioFile.deletedAt) // Only count ratings for active audio files
|
||||
))
|
||||
.where(
|
||||
and(
|
||||
eq(rating.participantId, participantId),
|
||||
eq(rating.isCompleted, true),
|
||||
isNull(rating.deletedAt), // Only count active ratings
|
||||
inArray(rating.audioFileId, allowedAudioIds)
|
||||
)
|
||||
);
|
||||
if (displayContinuousRating) {
|
||||
completedRatings = await db
|
||||
.select({
|
||||
audioFileId: rating.audioFileId
|
||||
})
|
||||
.from(rating)
|
||||
.innerJoin(audioFile, and(
|
||||
eq(rating.audioFileId, audioFile.id),
|
||||
isNull(audioFile.deletedAt)
|
||||
))
|
||||
.where(
|
||||
and(
|
||||
eq(rating.participantId, participantId),
|
||||
eq(rating.isCompleted, true),
|
||||
isNull(rating.deletedAt),
|
||||
inArray(rating.audioFileId, allowedAudioIds)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
completedRatings = await db
|
||||
.select({ audioFileId: overallRating.audioFileId })
|
||||
.from(overallRating)
|
||||
.innerJoin(audioFile, and(
|
||||
eq(overallRating.audioFileId, audioFile.id),
|
||||
isNull(audioFile.deletedAt)
|
||||
))
|
||||
.where(
|
||||
and(
|
||||
eq(overallRating.participantId, participantId),
|
||||
isNull(overallRating.deletedAt),
|
||||
inArray(overallRating.audioFileId, allowedAudioIds)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const completedAudioIds = new Set(completedRatings.map(r => r.audioFileId));
|
||||
const completedAudioIds = new Set(completedRatings.map((r) => r.audioFileId));
|
||||
|
||||
// Add completion status to audio files
|
||||
const audioFilesWithStatus = filteredAudio.map(file => ({
|
||||
...file,
|
||||
isCompleted: completedAudioIds.has(file.id)
|
||||
@@ -133,6 +150,7 @@ export async function load({ url, cookies }) {
|
||||
audioFiles: audioFilesWithStatus,
|
||||
token,
|
||||
completedCount: completedRatings.length,
|
||||
totalCount: filteredAudio.length
|
||||
totalCount: filteredAudio.length,
|
||||
displayContinuousRating
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user