Merge branch 'release/1.10.0'

This commit is contained in:
2024-02-08 15:16:28 +01:00
4 changed files with 39 additions and 9 deletions

View File

@@ -4,7 +4,7 @@ import { notFound } from 'next/navigation';
export async function GET(request: Request, { params:{ id } }: { params: { id:string } }) { export async function GET(request: Request, { params:{ id } }: { params: { id:string } }) {
const [locationID, billID] = id.split('-'); const [locationID, billID] = id.split('-');
const [location, bill] = await fetchBillById(locationID, billID) ?? []; const [location, bill] = await fetchBillById(locationID, billID, true) ?? [];
if(!bill?.attachment) { if(!bill?.attachment) {
notFound(); notFound();

View File

@@ -196,14 +196,27 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
} }
}) })
export const fetchBillById = withUser(async (user:AuthenticatedUser, locationID:string, billID:string) => { export const fetchBillById = withUser(async (user:AuthenticatedUser, locationID:string, billID:string, includeAttachmentBinary:boolean = false) => {
const { id: userId } = user; const { id: userId } = user;
const dbClient = await getDbClient(); const dbClient = await getDbClient();
// don't include the attachment binary data in the response
// if the attachment binary data is not needed
const projection = includeAttachmentBinary ? {} : {
"bills.attachment.fileContentsBase64": 0,
};
// find a location with the given locationID // find a location with the given locationID
const billLocation = await dbClient.collection<BillingLocation>("lokacije").findOne({ _id: locationID, userId }) const billLocation = await dbClient.collection<BillingLocation>("lokacije").findOne(
{
_id: locationID,
userId
},
{
projection
})
if(!billLocation) { if(!billLocation) {
console.log(`Location ${locationID} not found`); console.log(`Location ${locationID} not found`);

View File

@@ -105,10 +105,18 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu
// fetch all locations for the given year // fetch all locations for the given year
const locations = await dbClient.collection<BillingLocation>("lokacije") const locations = await dbClient.collection<BillingLocation>("lokacije")
.find({ .find(
userId, {
"yearMonth.year": year, userId,
}) "yearMonth.year": year,
},
{
projection: {
// don't include the attachment binary data in the response
"bill.attachment.fileContentsBase64": 0,
},
}
)
.sort({ .sort({
"yearMonth.year": -1, "yearMonth.year": -1,
"yearMonth.month": -1, "yearMonth.month": -1,
@@ -130,7 +138,16 @@ export const fetchLocationById = withUser(async (user:AuthenticatedUser, locatio
const { id: userId } = user; const { id: userId } = user;
// find a location with the given locationID // find a location with the given locationID
const billLocation = await dbClient.collection<BillingLocation>("lokacije").findOne({ _id: locationID, userId}); const billLocation = await dbClient.collection<BillingLocation>("lokacije")
.findOne(
{ _id: locationID, userId },
{
projection: {
// don't include the attachment binary data in the response
"bill.attachment.fileContentsBase64": 0,
},
}
);
if(!billLocation) { if(!billLocation) {
console.log(`Location ${locationID} not found`); console.log(`Location ${locationID} not found`);

View File

@@ -9,7 +9,7 @@ networks:
services: services:
web-app: web-app:
image: utility-bills-tracker:1.9.1 image: utility-bills-tracker:1.10.0
networks: networks:
- traefik-network - traefik-network
- mongo-network - mongo-network