Files
evidencija-rezija/web-app/app/lib/actions/printActions.ts
Knee Cola 57dcebd640 refactor: convert repository to monorepo with npm workspaces
Restructured the repository into a monorepo to better organize application code
and maintenance scripts.

## Workspace Structure
- web-app: Next.js application (all app code moved from root)
- housekeeping: Database backup and maintenance scripts

## Key Changes
- Moved all application code to web-app/ using git mv
- Moved database scripts to housekeeping/ workspace
- Updated Dockerfile for monorepo build process
- Updated docker-compose files (volume paths: ./web-app/etc/hosts/)
- Updated .gitignore for workspace-level node_modules
- Updated documentation (README.md, CLAUDE.md, CHANGELOG.md)

## Migration Impact
- Root package.json now manages workspaces
- Build commands delegate to web-app workspace
- All file history preserved via git mv
- Docker build process updated for workspace structure

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-25 12:13:04 +01:00

81 lines
2.6 KiB
TypeScript

'use server';
import { getDbClient } from '../dbClient';
import { BillingLocation } from '../db-types';
import { AuthenticatedUser } from '../types/next-auth';
import { withUser } from '../auth';
import { unstable_noStore as noStore } from 'next/cache';
export interface PrintBarcodeData {
locationName: string;
billName: string;
/**
* LEGACY SUPPORT ... untill all bills have been migrated
* @deprecated Use `hub3aText` instead.
*/
barcodeImage?: string;
hub3aText?: string;
payedAmount?: number | null;
}
/**
* Fetches all bills with barcode images for a specific month for printing
* @param year - Year to fetch data for
* @param month - Month to fetch data for (1-12)
* @returns Array of barcode data for printing
*/
export const fetchBarcodeDataForPrint = withUser(async (user: AuthenticatedUser, year: number, month: number): Promise<PrintBarcodeData[]> => {
noStore();
const { id: userId } = user;
const dbClient = await getDbClient();
const yearMonth = `${year}-${month.toString().padStart(2, '0')}`;
// Fetch all locations for the specific month
const locations = await dbClient.collection<BillingLocation>("lokacije")
.find({
userId, // ensure data belongs to authenticated user
"yearMonth.year": year,
"yearMonth.month": month
}, {
// project only necessary fields
projection: {
name: 1,
bills: 1,
barcodeImage: 1,
hub3aText: 1,
payedAmount: 1,
paid: 1
}
})
.toArray();
// Extract and flatten barcode data
const printData: PrintBarcodeData[] = [];
for (const location of locations) {
for (const bill of location.bills) {
// Only include bills that have barcode images and are NOT PAID
if ( ( bill.hub3aText && bill.hub3aText.trim() !== "" && !bill.paid) ) {
printData.push({
locationName: location.name,
billName: bill.name,
barcodeImage: bill.barcodeImage, // LEGACY SUPPORT ... untill all bills have been migrated
hub3aText: bill.hub3aText,
payedAmount: bill.payedAmount
});
}
}
}
// Sort by location name, then by bill name for consistent ordering
printData.sort((a, b) => {
if (a.locationName !== b.locationName) {
return a.locationName.localeCompare(b.locationName);
}
return a.billName.localeCompare(b.billName);
});
return printData;
});