adding new billing location completed

This commit is contained in:
2024-01-05 15:13:15 +01:00
parent 3f7b681ab9
commit 94fee6f775
6 changed files with 24 additions and 14 deletions

View File

@@ -30,7 +30,7 @@ const UpdateLocation = FormSchema.omit({ _id: true });
* @param formData form data
* @returns
*/
export async function updateOrAddLocation(locationId?: string, prevState:State, formData: FormData) {
export async function updateOrAddLocation(locationId?: string, yearMonth?: string, prevState:State, formData: FormData) {
const validatedFields = UpdateLocation.safeParse({
locationName: formData.get('locationName'),
@@ -65,12 +65,12 @@ export async function updateOrAddLocation(locationId?: string, prevState:State,
notes: locationNotes,
}
});
} else {
} else if(yearMonth) {
await db.collection<BillingLocation>("lokacije").insertOne({
_id: (new ObjectId()).toHexString(),
name: locationName,
notes: locationNotes,
yearMonth: 202101, // ToDo: get the current year and month
yearMonth: parseInt(yearMonth), // ToDo: get the current year and month
bills: [],
});
}