yearMonth split into year + month
This commit is contained in:
@@ -33,7 +33,7 @@ const UpdateLocation = FormSchema.omit({ _id: true });
|
||||
* @param formData form data
|
||||
* @returns
|
||||
*/
|
||||
export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locationId?: string, yearMonth?: string, prevState:State, formData: FormData) => {
|
||||
export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locationId?: string, year?: string, month?: string, prevState:State, formData: FormData) => {
|
||||
|
||||
const validatedFields = UpdateLocation.safeParse({
|
||||
locationName: formData.get('locationName'),
|
||||
@@ -70,14 +70,15 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
notes: locationNotes,
|
||||
}
|
||||
});
|
||||
} else if(yearMonth) {
|
||||
} else if(year && month) {
|
||||
await dbClient.collection<BillingLocation>("lokacije").insertOne({
|
||||
_id: (new ObjectId()).toHexString(),
|
||||
userId,
|
||||
userEmail,
|
||||
name: locationName,
|
||||
notes: locationNotes,
|
||||
yearMonth: parseInt(yearMonth), // ToDo: get the current year and month
|
||||
year: parseInt(year), // ToDo: get the current year and month
|
||||
month: parseInt(month), // ToDo: get the current year and month
|
||||
bills: [],
|
||||
});
|
||||
}
|
||||
@@ -98,7 +99,7 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, pageIx:
|
||||
// fetch `pageSize` locations for the given page index
|
||||
const locations = await dbClient.collection<BillingLocation>("lokacije")
|
||||
.find({ userId })
|
||||
.sort({ yearMonth: -1, name: 1 })
|
||||
.sort({ year: -1, month: -1, name: 1 })
|
||||
.skip(pageIx * pageSize)
|
||||
.limit(pageSize)
|
||||
.toArray();
|
||||
|
||||
Reference in New Issue
Block a user