feat(journal): add per-user mood journal module (task 86)
Ship journal entries with mood tracking, insights, and Recharts charts. Adds v1 API endpoints per ADR 0005 and migration 0020_journal_entries.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
export type MoodDefinition = {
|
||||
id: string;
|
||||
label: string;
|
||||
emoji: string;
|
||||
color: string;
|
||||
score: number;
|
||||
};
|
||||
|
||||
export const MOOD_CATALOG: MoodDefinition[] = [
|
||||
{ id: "happy", label: "Happy", emoji: "😊", color: "#f4b740", score: 5 },
|
||||
{ id: "excited", label: "Excited", emoji: "🤩", color: "#ff8c42", score: 5 },
|
||||
{ id: "grateful", label: "Grateful", emoji: "🙏", color: "#7cb342", score: 4 },
|
||||
{ id: "calm", label: "Calm", emoji: "😌", color: "#64b5f6", score: 4 },
|
||||
{ id: "neutral", label: "Neutral", emoji: "😐", color: "#90a4ae", score: 3 },
|
||||
{ id: "tired", label: "Tired", emoji: "😴", color: "#8d6e63", score: 2 },
|
||||
{ id: "anxious", label: "Anxious", emoji: "😰", color: "#ab47bc", score: 2 },
|
||||
{ id: "stressed", label: "Stressed", emoji: "😣", color: "#e57373", score: 1 },
|
||||
{ id: "sad", label: "Sad", emoji: "😢", color: "#5c6bc0", score: 1 },
|
||||
{ id: "angry", label: "Angry", emoji: "😠", color: "#d84315", score: 2 },
|
||||
];
|
||||
|
||||
const moodById = new Map(MOOD_CATALOG.map((mood) => [mood.id, mood]));
|
||||
|
||||
export function getMoodById(id: string): MoodDefinition | undefined {
|
||||
return moodById.get(id);
|
||||
}
|
||||
|
||||
export function averageMoodScore(moodIds: string[]): number | null {
|
||||
if (moodIds.length === 0) return null;
|
||||
const scores = moodIds
|
||||
.map((id) => moodById.get(id)?.score)
|
||||
.filter((score): score is number => typeof score === "number");
|
||||
if (scores.length === 0) return null;
|
||||
return scores.reduce((sum, score) => sum + score, 0) / scores.length;
|
||||
}
|
||||
|
||||
export function validateMoodIds(moodIds: string[]): string[] {
|
||||
return moodIds.filter((id) => moodById.has(id));
|
||||
}
|
||||
Reference in New Issue
Block a user