Skip to content

Commit

Permalink
Norsk latest brew option
Browse files Browse the repository at this point in the history
  • Loading branch information
edalholt committed Dec 8, 2024
1 parent 51350d3 commit 06a2959
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions backend/controllers/latestBrew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Brew } from "../models/brew";

export async function getLatestBrew(req: Request, res: Response) {
const { textFormat } = req.body;
const { norsk } = req.query;

try {
const latest = await Brew.aggregate([
Expand All @@ -19,10 +20,20 @@ export async function getLatestBrew(req: Request, res: Response) {
const diffMs = Date.now() - new Date(latest[0].brewTime).getTime();
const diffHours = Math.floor(diffMs / (1000 * 60 * 60));
const diffMinutes = Math.floor((diffMs % (1000 * 60 * 60)) / (1000 * 60));
const hoursText = diffHours === 1 ? "hour" : "hours";
const minutesText = diffMinutes === 1 ? "minute" : "minutes";
const hoursText =
diffHours === 1 ? (norsk ? "time" : "hour") : norsk ? "timer" : "hours";
const minutesText =
diffMinutes === 1
? norsk
? "minutt"
: "minute"
: norsk
? "minutter"
: "minutes";

const timeSince = `${diffHours} ${hoursText} and ${diffMinutes} ${minutesText}`;
const timeSince = `${diffHours} ${hoursText} ${
norsk ? "og" : "and"
} ${diffMinutes} ${minutesText}`;

const { brewTime, liters } = latest[0];
const response = {
Expand Down

0 comments on commit 06a2959

Please sign in to comment.