diff --git a/app/[locale]/share/proof-of-payment/[id]/route.tsx b/app/[locale]/share/proof-of-payment/[id]/route.tsx index f3122c6..ad3b76b 100644 --- a/app/[locale]/share/proof-of-payment/[id]/route.tsx +++ b/app/[locale]/share/proof-of-payment/[id]/route.tsx @@ -7,7 +7,11 @@ export async function GET(request: Request, { params:{ id } }: { params: { id:st const dbClient = await getDbClient(); const location = await dbClient.collection("lokacije") - .findOne({ _id: locationID }); + .findOne({ _id: locationID }, { + projection: { + utilBillsProofOfPaymentAttachment: 1, + } + }); if(!location?.utilBillsProofOfPaymentAttachment) { notFound(); diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index 3994865..b689453 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -381,24 +381,24 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu "yearMonth.year": year, }, }, - { - $addFields: { - bills: { - $map: { - input: "$bills", - as: "bill", - in: { - _id: "$$bill._id", - name: "$$bill.name", - paid: "$$bill.paid", - billedTo: "$$bill.billedTo", - payedAmount: "$$bill.payedAmount", - hasAttachment: { $ne: ["$$bill.attachment", null] }, - }, - }, - }, - }, - }, + // DUPLICATION of block below ... probably added by AI { + // DUPLICATION of block below ... probably added by AI $addFields: { + // DUPLICATION of block below ... probably added by AI bills: { + // DUPLICATION of block below ... probably added by AI $map: { + // DUPLICATION of block below ... probably added by AI input: "$bills", + // DUPLICATION of block below ... probably added by AI as: "bill", + // DUPLICATION of block below ... probably added by AI in: { + // DUPLICATION of block below ... probably added by AI _id: "$$bill._id", + // DUPLICATION of block below ... probably added by AI name: "$$bill.name", + // DUPLICATION of block below ... probably added by AI paid: "$$bill.paid", + // DUPLICATION of block below ... probably added by AI billedTo: "$$bill.billedTo", + // DUPLICATION of block below ... probably added by AI payedAmount: "$$bill.payedAmount", + // DUPLICATION of block below ... probably added by AI hasAttachment: { $ne: ["$$bill.attachment", null] }, + // DUPLICATION of block below ... probably added by AI }, + // DUPLICATION of block below ... probably added by AI }, + // DUPLICATION of block below ... probably added by AI }, + // DUPLICATION of block below ... probably added by AI }, + // DUPLICATION of block below ... probably added by AI }, { $addFields: { _id: { $toString: "$_id" }, @@ -412,10 +412,10 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu paid: "$$bill.paid", billedTo: "$$bill.billedTo", payedAmount: "$$bill.payedAmount", - hasAttachment: "$$bill.hasAttachment", + hasAttachment: { $ne: ["$$bill.attachment", null] }, }, }, - }, + } } }, { @@ -433,6 +433,9 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu // "bills.attachment": 0, // "bills.notes": 0, // "bills.hub3aText": 1, + // project only file name - leave out file content so that + // less data is transferred to the client + "utilBillsProofOfPaymentAttachment.fileName": 1, }, }, { @@ -494,6 +497,7 @@ export const fetchLocationById = async (locationID:string) => { projection: { // don't include the attachment binary data in the response "bills.attachment.fileContentsBase64": 0, + "utilBillsProofOfPaymentAttachment.fileContentsBase64": 0, }, } ); diff --git a/app/lib/actions/monthActions.ts b/app/lib/actions/monthActions.ts index 8e4157d..2fcde2d 100644 --- a/app/lib/actions/monthActions.ts +++ b/app/lib/actions/monthActions.ts @@ -39,6 +39,9 @@ export const addMonth = withUser(async (user:AuthenticatedUser, { year, month }: return({ // copy all the properties from the previous location ...prevLocation, + // clear properties specific to the month + seenByTenant: undefined, + utilBillsProofOfPaymentAttachment: undefined, // assign a new ID _id: (new ObjectId()).toHexString(), yearMonth: { diff --git a/app/lib/actions/printActions.ts b/app/lib/actions/printActions.ts index a44d3c4..7c8c04f 100644 --- a/app/lib/actions/printActions.ts +++ b/app/lib/actions/printActions.ts @@ -38,6 +38,15 @@ export const fetchBarcodeDataForPrint = withUser(async (user: AuthenticatedUser, 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 + } }) .toArray();