implented adding year-month

This commit is contained in:
2024-01-05 15:56:04 +01:00
parent 2413ab9240
commit 0b85e74eb0
4 changed files with 126 additions and 6 deletions

View File

@@ -3,14 +3,18 @@ import { MonthTitle } from './ui/MonthTitle';
import { AddMonthButton } from './ui/AddMonthButton';
import { AddLocationButton } from './ui/AddLocationButton';
import clientPromise from './lib/mongodb';
import { Location } from './lib/db-types';
import { BillingLocation } from './lib/db-types';
const calcNextYearMonth = (yearMonth: number) => {
return(yearMonth % 100 === 12 ? yearMonth + 89 : yearMonth + 1);
}
export const Page = async () => {
const client = await clientPromise;
const db = client.db("rezije");
const locations = await db.collection<Location>("lokacije")
const locations = await db.collection<BillingLocation>("lokacije")
.find({})
.sort({ yearMonth: -1 }) // sort by yearMonth descending
.limit(20)
@@ -18,7 +22,7 @@ export const Page = async () => {
return (
<main className="flex min-h-screen flex-col p-6 bg-base-300">
<AddMonthButton />
<AddMonthButton yearMonth={calcNextYearMonth(locations[0].yearMonth)} />
{
locations.map((location, ix, array) => {