From 32818b7492d5d851c5ac36f60be8959339589b04 Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Tue, 10 Sep 2024 22:44:25 +0200 Subject: [PATCH] update mongoose to 5.8.3 (lots of types changes) --- components/bookingTable.tsx | 6 +- context/book.tsx | 6 +- db/bill.ts | 17 ++-- db/booking.ts | 57 ++++++------- db/index.ts | 40 ++++----- helpers/array.test.ts | 13 --- helpers/bill.ts | 12 +-- helpers/date.test.ts | 12 --- helpers/ical.ts | 8 +- helpers/mail.ts | 20 ++--- helpers/storage.ts | 6 +- lib/googlecalendar.ts | 21 ++--- next.config.mjs | 10 +-- package-lock.json | 113 ++++---------------------- package.json | 2 +- pages/admin/bookings/[uuid]/bill.tsx | 6 +- pages/admin/bookings/[uuid]/index.tsx | 4 +- pages/api/bookings/[uuid]/bill.ts | 6 +- pages/api/bookings/[uuid]/index.ts | 12 +-- pages/api/bookings/index.ts | 4 +- pages/bookings/[uuid]/index.tsx | 6 +- pages/bookings/[uuid]/stored.tsx | 6 +- 22 files changed, 136 insertions(+), 251 deletions(-) delete mode 100644 helpers/array.test.ts delete mode 100644 helpers/date.test.ts diff --git a/components/bookingTable.tsx b/components/bookingTable.tsx index 0377026..ae723c0 100644 --- a/components/bookingTable.tsx +++ b/components/bookingTable.tsx @@ -2,12 +2,12 @@ import React from 'react' import Link from 'next/link' import { daysFormatFrontend } from '../helpers/date' -import { BookingDocument } from '../db/booking' +import { IBooking } from '../db/booking' export default function BookingTable({ booking, }: { - booking: BookingDocument + booking: IBooking }) { const data = [ { name: 'Status', value: booking.status }, @@ -51,7 +51,7 @@ export default function BookingTable({

Created{' '} - {new Date(booking.createdAt as string).toLocaleString( + {new Date(booking.createdAt).toLocaleString( new Intl.Locale('de') )}

diff --git a/context/book.tsx b/context/book.tsx index be9ab89..1db54a4 100644 --- a/context/book.tsx +++ b/context/book.tsx @@ -4,9 +4,9 @@ import { clearBookingData, loadBookingData } from '../helpers/storage' import { log } from '../helpers/log' import { createBooking } from '../helpers/booking' -import { Booking } from '../db/booking' +import { IBooking } from '../db/booking' -export type BookFormData = Omit +export type BookFormData = Omit type BookingProviderState = { postData?: boolean @@ -14,7 +14,7 @@ type BookingProviderState = { postDataSuccess?: boolean formData: BookFormData formDataChanged: string[] - booking?: Booking + booking?: IBooking dataStored: boolean dataStoredLoaded: boolean } diff --git a/db/bill.ts b/db/bill.ts index 2a91f19..f0a0abe 100644 --- a/db/bill.ts +++ b/db/bill.ts @@ -2,27 +2,30 @@ import * as mongoose from 'mongoose' import { BILL_STATUS, MILAGE_TARIFS } from './enums' import { getBillTotal } from '../helpers/bill' -export type AdditionalCost = { +export interface IAdditionalCost { name: string value: number } -export type Bill = { +export interface IBill { milageStart: number milageEnd: number milage?: number tarif: MILAGE_TARIFS status: BILL_STATUS - additionalCosts: AdditionalCost[] + additionalCosts: IAdditionalCost[] + + createdAt?: string + updatedAt?: string } -export type BillDocument = Bill & +export type BillDocument = IBill & mongoose.SchemaTimestampsConfig & mongoose.Document -export type BillModel = mongoose.Model +export type BillModel = mongoose.Model -const BillSchema = new mongoose.Schema( +const BillSchema = new mongoose.Schema( { milageStart: { type: Number, @@ -88,4 +91,4 @@ BillSchema.virtual('total').get(function (): number { }) export default (mongoose.models.Bill || - mongoose.model('Bill', BillSchema)) as BillModel + mongoose.model('Bill', BillSchema)) as BillModel \ No newline at end of file diff --git a/db/booking.ts b/db/booking.ts index eaa60fc..ec7bb26 100644 --- a/db/booking.ts +++ b/db/booking.ts @@ -8,10 +8,10 @@ import { } from '../helpers/date' import { createCalendarEvent, deleteCalendarEvent } from '../lib/googlecalendar' -import { Bill } from './bill' +import { IBill } from './bill' import { BOOKING_STATUS, VALIDATION_ERRORS } from './enums' -export type Booking = { +export interface IBooking { uuid: string name: string email: string @@ -19,7 +19,7 @@ export type Booking = { street: string zip: string city: string - bill?: Bill + bill?: IBill // format YYYY-MM-DD startDate: string // format YYYY-MM-DD @@ -30,17 +30,17 @@ export type Booking = { destination?: string days?: string[] calendarEventId: string + + createdAt?: string + updatedAt?: string + toJSON?: () => IBooking } -export type BookingDocument = Booking & - mongoose.Document & - mongoose.SchemaTimestampsConfig - -export type BookingModel = mongoose.Model & { +export type BookingModel = mongoose.Model & { findBookedDays(uuidsToIngore?: string[]): Promise } -const BookingSchema = new mongoose.Schema( +const BookingSchema = new mongoose.Schema( { // need a seperate uuid to be able to target a booking anonimously uuid: { @@ -78,7 +78,7 @@ const BookingSchema = new mongoose.Schema( required: true, validate: { validator: async function (days: string[]): Promise { - const booking = this as Booking + const booking = this const uuid = booking.uuid && [booking.uuid] const bookedDays = await BookingModel.findBookedDays(uuid) @@ -111,7 +111,7 @@ const BookingSchema = new mongoose.Schema( ) BookingSchema.pre('validate', function (next: () => void): void { - const booking = this as BookingDocument + const booking = this booking.days = getDays({ startDate: new Date(booking.startDate), endDate: new Date(booking.endDate), @@ -120,16 +120,16 @@ BookingSchema.pre('validate', function (next: () => void): void { }) BookingSchema.pre('save', async function (next: () => void): Promise { - const booking = this as BookingDocument + const booking = this if (!booking.calendarEventId) { // create calendar event before saving to database - await createCalendarEvent(booking) + await createCalendarEvent(booking.toJSON()) } else if ( [BOOKING_STATUS.CANCELED, BOOKING_STATUS.REJECTED].includes(booking.status) ) { // event has been canceled or rejected, delete calendar event again to free up the slot - await deleteCalendarEvent(booking) + await deleteCalendarEvent(booking.toJSON()) } next() @@ -138,31 +138,26 @@ BookingSchema.pre('save', async function (next: () => void): Promise { BookingSchema.static( 'findBookedDays', async function (uuidsToIngore: string[] = []): Promise { - const model = this as BookingModel + const booking = this const now = nowInTz() - const bookedDays = await model - .find( - { - status: { $in: [BOOKING_STATUS.REQUESTED, BOOKING_STATUS.CONFIRMED] }, - uuid: { $nin: uuidsToIngore }, - // dateFormatBackend uses YYYY-MM-DD, which is startOfDay anyway - endDate: { $gt: dateFormatBackend(now) }, - }, - 'days' - ) - .exec() + const bookedDays = await booking.find( + { + status: { $in: [BOOKING_STATUS.REQUESTED, BOOKING_STATUS.CONFIRMED] }, + uuid: { $nin: uuidsToIngore }, + // dateFormatBackend uses YYYY-MM-DD, which is startOfDay anyway + endDate: { $gt: dateFormatBackend(now) }, + }, + 'days' + ) return bookedDays - .map((b) => b.days) + .map((b: { days: any }) => b.days) .flat() .sort() } ) const BookingModel = (mongoose.models.Booking || - mongoose.model( - 'Booking', - BookingSchema - )) as BookingModel + mongoose.model('Booking', BookingSchema)) as BookingModel export default BookingModel diff --git a/db/index.ts b/db/index.ts index 8ea344c..2c9d01b 100644 --- a/db/index.ts +++ b/db/index.ts @@ -1,6 +1,6 @@ import * as mongoose from 'mongoose' -import BookingModel, { Booking, BookingDocument } from './booking' -import BillModel, { Bill } from './bill' +import BookingModel, { IBooking } from './booking' +import BillModel, { IBill } from './bill' import { getBookedDays as calendarGetBookedDays } from '../lib/googlecalendar' import { BOOKING_STATUS } from './enums' import { uniqueFilter } from '../helpers/array' @@ -9,7 +9,7 @@ export const MONGO_URI = process.env.MONGO_URI mongoose.set('strictQuery', false); -mongoose.connect(process.env.MONGO_URI, { +mongoose.connect(MONGO_URI, { serverSelectionTimeoutMS: 3000, }) @@ -23,7 +23,7 @@ export async function getBookedDays( return [...bookedInDatabase, ...bookedInCalendar].filter(uniqueFilter).sort() } -export async function getBookingByUUID(uuid: string): Promise { +export async function getBookingByUUID(uuid: string): Promise> { return BookingModel.findOne({ uuid }) } @@ -31,7 +31,7 @@ export async function getBookings({ status = [BOOKING_STATUS.CONFIRMED, BOOKING_STATUS.REQUESTED], startDateGreaterThan = '2000-01-01T00:00:00Z', }: { status?: BOOKING_STATUS[]; startDateGreaterThan?: string } = {}): Promise< - BookingDocument[] + IBooking[] > { return await BookingModel.find({ status: { $in: status }, @@ -53,7 +53,7 @@ export async function createBooking({ street, zip, city, -}: Booking): Promise { +}: IBooking): Promise> { const booking = new BookingModel({ startDate, endDate, @@ -69,25 +69,25 @@ export async function createBooking({ }) await booking.save() - return booking.toJSON() + return booking.toJSON() } export async function patchBooking( bookingUUID: string, - bookingData: Booking -): Promise<{ current: Booking; previous: Booking }> { + bookingData: IBooking +): Promise<{ current: IBooking; previous: IBooking }> { const booking = await getBookingByUUID(bookingUUID) - const oldBooking = booking.toJSON() + const oldBooking = booking.toJSON() booking.set(bookingData) await booking.save() - return { current: booking.toJSON(), previous: oldBooking } + return { current: booking.toJSON(), previous: oldBooking } } export async function createBill( bookingUUID: string, - billData: Bill -): Promise { + billData: IBill +): Promise { const booking = await getBookingByUUID(bookingUUID) const bill = new BillModel() @@ -95,16 +95,16 @@ export async function createBill( await bill.save() - booking.bill = bill._id + booking.bill = bill await booking.save() - return bill.toJSON() + return bill.toJSON() } export async function patchBill( bookingUUID: string, - billData: Bill -): Promise { + billData: IBill +): Promise { const booking = await getBookingByUUID(bookingUUID) const bill = (booking.bill && (await BillModel.findById(booking.bill))) || @@ -113,12 +113,12 @@ export async function patchBill( bill.set(billData) await bill.save() - if (booking.bill !== bill._id) { - booking.bill = bill._id + if (booking.bill !== bill) { + booking.bill = bill await booking.save() } - return bill.toJSON() + return bill.toJSON() } export async function getMilageMax(): Promise { diff --git a/helpers/array.test.ts b/helpers/array.test.ts deleted file mode 100644 index a42b5d4..0000000 --- a/helpers/array.test.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { getNextSmaller, getNextBigger } from './array' - -test('getPreviousInOrder', () => { - const result = getNextSmaller([3, 1, 2, 0, 8, 9, 10], 5) - - expect(result).toEqual(3) -}) - -test('getNextInOrder', () => { - const result = getNextBigger([7, 8, 9, 3, 1, 2], 4) - - expect(result).toEqual(7) -}) diff --git a/helpers/bill.ts b/helpers/bill.ts index 7fce605..ecd1c2d 100644 --- a/helpers/bill.ts +++ b/helpers/bill.ts @@ -1,5 +1,5 @@ import { MILAGE_TARIFS } from '../db/enums' -import { AdditionalCost, Bill } from '../db/bill' +import { IAdditionalCost, IBill } from '../db/bill' import fetch from './fetch' function roundToCent(amount: number): number { @@ -61,7 +61,7 @@ export function getBillTotal({ }: { tarif: MILAGE_TARIFS milage?: number - additionalCosts: AdditionalCost[] + additionalCosts: IAdditionalCost[] }): number { const milageCosts = getMilageCosts({ tarif, km: milage }) const additionalCostsSum = additionalCosts @@ -73,8 +73,8 @@ export function getBillTotal({ export async function createBill( bookingUuid: string, - bill: Bill -): Promise { + bill: IBill +): Promise { return fetch(`/api/bookings/${bookingUuid}/bill`, { method: 'POST', body: bill, @@ -83,8 +83,8 @@ export async function createBill( export async function patchBill( bookingUuid: string, - bill: Bill -): Promise { + bill: IBill +): Promise { return fetch(`/api/bookings/${bookingUuid}/bill`, { method: 'POST', body: bill, diff --git a/helpers/date.test.ts b/helpers/date.test.ts deleted file mode 100644 index 85af6ea..0000000 --- a/helpers/date.test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { daysFormatFrontend } from './date' - -test('daysFormatFrontend', () => { - expect(daysFormatFrontend([])).toEqual('') - expect(daysFormatFrontend(['2020-01-01'])).toEqual('01.01.2020') - expect(daysFormatFrontend(['2020-01-01', '2020-01-02'])).toEqual( - '01.01.2020-02.01.2020' - ) - expect( - daysFormatFrontend(['2020-01-01', '2020-01-02', '2020-01-05']) - ).toEqual('01.01.2020-05.01.2020') -}) diff --git a/helpers/ical.ts b/helpers/ical.ts index 637b91c..36c0522 100644 --- a/helpers/ical.ts +++ b/helpers/ical.ts @@ -1,5 +1,5 @@ import { createEvents, createEvent, EventStatus } from 'ics' -import { Booking } from '../db/booking' +import { IBooking } from '../db/booking' import { BOOKING_STATUS } from '../db/enums' import { getBaseURL } from './url' import { daysFormatFrontend } from './date' @@ -12,7 +12,7 @@ function convertDay(value: string): [number, number, number] { return [Number(parts[0]), Number(parts[1]), Number(parts[2])] } -export function generateCalendarEntry(booking: Booking): string { +export function generateCalendarEntry(booking: IBooking): string { const { error, value } = createEvent({ productId: 'app.vercel.pfadi-bussle/ics', title: `Pfadi-Bussle Buchung`, @@ -38,7 +38,7 @@ Buchungs-Link: ${getBaseURL()}/bookings/${booking.uuid} return value } -export function generateBookedCalendar(bookings: Booking[]): string { +export function generateBookedCalendar(bookings: IBooking[]): string { const events = bookings.map( ( booking @@ -80,4 +80,4 @@ Link: ${getBaseURL()}/admin/bookings/${booking.uuid} } return value -} +} \ No newline at end of file diff --git a/helpers/mail.ts b/helpers/mail.ts index 1344264..66da6c8 100644 --- a/helpers/mail.ts +++ b/helpers/mail.ts @@ -1,4 +1,4 @@ -import { Booking } from '../db/booking' +import { IBooking } from '../db/booking' import { getBaseURL } from '../helpers/url' import { daysFormatFrontend } from './date' import { generateCalendarEntry } from './ical' @@ -49,7 +49,7 @@ Tel. 0151/212 253 62 ${getBaseURL()} ` -function getReceivedBookingBookerText(booking: Booking): string { +function getReceivedBookingBookerText(booking: IBooking): string { return `Hallo liebe/r ${booking.name}, Vielen Dank für Deine Buchungsanfrage zum ${daysFormatFrontend(booking.days)}! @@ -66,7 +66,7 @@ ${footer} ` } -function getBookingConfirmedText(booking: Booking): string { +function getBookingConfirmedText(booking: IBooking): string { return `Hallo liebe/r ${booking.name}, deine Buchunganfrage zum ${daysFormatFrontend( @@ -83,7 +83,7 @@ ${footer} ` } -function getBookingRejectedText(booking: Booking): string { +function getBookingRejectedText(booking: IBooking): string { return `Hallo liebe/r ${booking.name}, es tut uns leid, aber deine Buchungsanfrage zum ${daysFormatFrontend( @@ -97,7 +97,7 @@ ${footer} ` } -function getBookingCanceledText(booking: Booking): string { +function getBookingCanceledText(booking: IBooking): string { return `Hallo liebe/r ${booking.name}, deine Buchungsanfrage zum ${daysFormatFrontend(booking.days)} wurde storniert. @@ -118,7 +118,7 @@ MfG` } export async function sendReceivedBookingAdminMail( - booking: Booking + booking: IBooking ): Promise { await sendMail({ to: [{ address: adminEmail, name: 'Pfadi-Bussle Wart' }], @@ -129,7 +129,7 @@ export async function sendReceivedBookingAdminMail( } export async function sendReceivedBookingBookerMail( - booking: Booking + booking: IBooking ): Promise { await sendMail({ to: [{ address: booking.email, name: booking.name }], @@ -139,7 +139,7 @@ export async function sendReceivedBookingBookerMail( }) } -export async function sendBookingConfirmed(booking: Booking): Promise { +export async function sendBookingConfirmed(booking: IBooking): Promise { await sendMail({ to: [{ address: booking.email, name: booking.name }], from: { address: fromEmail, name: 'Pfadi-Bussle Wart' }, @@ -157,7 +157,7 @@ export async function sendBookingConfirmed(booking: Booking): Promise { }) } -export async function sendBookingRejected(booking: Booking): Promise { +export async function sendBookingRejected(booking: IBooking): Promise { await sendMail({ to: [{ address: booking.email, name: booking.name }], from: { address: fromEmail, name: 'Pfadi-Bussle Wart' }, @@ -166,7 +166,7 @@ export async function sendBookingRejected(booking: Booking): Promise { }) } -export async function sendBookingCanceled(booking: Booking): Promise { +export async function sendBookingCanceled(booking: IBooking): Promise { await sendMail({ to: [{ address: booking.email, name: booking.name }], from: { address: fromEmail, name: 'Pfadi-Bussle Wart' }, diff --git a/helpers/storage.ts b/helpers/storage.ts index 2992922..88e8579 100644 --- a/helpers/storage.ts +++ b/helpers/storage.ts @@ -1,4 +1,4 @@ -import { Booking } from '../db/booking' +import { IBooking } from '../db/booking' import { log } from '../helpers/log' const BOOKING_DATA_KEY = 'pfadiBussleBookingData' @@ -7,7 +7,7 @@ function getStorage() { return localStorage } -export function storeBookingData(booking: Booking) { +export function storeBookingData(booking: IBooking) { const { name, email, street, zip, city, org } = booking getStorage().setItem( @@ -30,4 +30,4 @@ export function loadBookingData() { } return result -} +} \ No newline at end of file diff --git a/lib/googlecalendar.ts b/lib/googlecalendar.ts index 8c5641a..769d9c8 100644 --- a/lib/googlecalendar.ts +++ b/lib/googlecalendar.ts @@ -1,6 +1,6 @@ import { google } from 'googleapis' import { getBaseURL } from '../helpers/url' -import { Booking } from '../db/booking' +import { IBooking } from '../db/booking' import { getDays, getNextDay, dateFormatBackend } from '../helpers/date' import { log } from '../helpers/log' @@ -47,7 +47,7 @@ export async function getBookedDays() { ) } -function getSummary(booking: Partial): string { +function getSummary(booking: Partial): string { let summary = '' if (booking.org) { @@ -59,13 +59,15 @@ function getSummary(booking: Partial): string { return summary } -function getDescription(booking: Booking): string { +function getDescription(booking: IBooking): string { const bookingUrl = `${getBaseURL()}/admin/bookings/${booking.uuid}` return `Managelink ${bookingUrl}` } -export async function createCalendarEvent(booking: Booking): Promise { +export async function createCalendarEvent( + booking: IBooking +): Promise { const exclusiveEndDate = dateFormatBackend( getNextDay(new Date(booking.endDate)) ) @@ -85,7 +87,7 @@ export async function createCalendarEvent(booking: Booking): Promise { return booking } -export async function deleteCalendarEvent(booking: Booking) { +export async function deleteCalendarEvent(booking: IBooking) { await calendar.events.delete({ calendarId, eventId: booking.calendarEventId, @@ -95,12 +97,3 @@ export async function deleteCalendarEvent(booking: Booking) { booking.calendarEventId = null } - -//export async function patchCalendarEvent(booking: { calendarEventId: string } & Partial ) : Promise { -// const response = await calendar.events.patch({ -// calendarId, -// eventId: booking.calendarEventId, -// }); -// -// return booking; -//} \ No newline at end of file diff --git a/next.config.mjs b/next.config.mjs index 9bfa2d6..4b993ee 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -9,11 +9,11 @@ const nextConfig = { // Optionally, add any other Next.js config below async redirects() { return [ - { - source: '/admin', - destination: '/nope', - permanent: true, - }, + // { + // source: '/admin', + // destination: '/nope', + // permanent: true, + // }, ] }, } diff --git a/package-lock.json b/package-lock.json index d58ddfe..73f0b6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "date-fns-tz": "2.0.1", "googleapis": "142.0.0", "ics": "3.7.6", - "mongoose": "8.3.5", + "mongoose": "^8.5.4", "next": "^14.0.1", "next-auth": "4.24.7", "next-axiom": "^1.1.0", @@ -4987,19 +4987,6 @@ "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==", "peer": true }, - "node_modules/abort-controller": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", - "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", - "optional": true, - "peer": true, - "dependencies": { - "event-target-shim": "^5.0.0" - }, - "engines": { - "node": ">=6.5" - } - }, "node_modules/acorn": { "version": "8.11.3", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", @@ -5028,19 +5015,6 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, - "node_modules/agent-base": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", - "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", - "optional": true, - "peer": true, - "dependencies": { - "debug": "4" - }, - "engines": { - "node": ">= 6.0.0" - } - }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -7195,16 +7169,6 @@ "node": ">=0.10.0" } }, - "node_modules/event-target-shim": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", - "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", - "optional": true, - "peer": true, - "engines": { - "node": ">=6" - } - }, "node_modules/events": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", @@ -7564,37 +7528,6 @@ "node": ">= 14" } }, - "node_modules/gcp-metadata": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-5.3.0.tgz", - "integrity": "sha512-FNTkdNEnBdlqF2oatizolQqNANMrcqJt6AAYt99B3y1aLLC8Hc5IOBb+ZnnzllodEEf6xMBp6wRcBbc16fa65w==", - "optional": true, - "peer": true, - "dependencies": { - "gaxios": "^5.0.0", - "json-bigint": "^1.0.0" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/gcp-metadata/node_modules/gaxios": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-5.0.0.tgz", - "integrity": "sha512-VD/yc5ln6XU8Ch1hyYY6kRMBE0Yc2np3fPyeJeYHhrPs1i8rgnsApPMWyrugkl7LLoSqpOJVBWlQIa87OAvt8Q==", - "optional": true, - "peer": true, - "dependencies": { - "abort-controller": "^3.0.0", - "extend": "^3.0.2", - "https-proxy-agent": "^5.0.0", - "is-stream": "^2.0.0", - "node-fetch": "^2.6.7" - }, - "engines": { - "node": ">=12" - } - }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -8044,20 +7977,6 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, - "node_modules/https-proxy-agent": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", - "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", - "optional": true, - "peer": true, - "dependencies": { - "agent-base": "6", - "debug": "4" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -10532,13 +10451,13 @@ } }, "node_modules/mongoose": { - "version": "8.3.5", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.3.5.tgz", - "integrity": "sha512-2zqeAjHjCqT1o5HeUCvkE9tUHsXwemnwEZ2SKnUxsaP8p1a+UcSQSNbnSuOzUVePMwLETrsvLIRdFLjsNfCgWA==", + "version": "8.5.4", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.5.4.tgz", + "integrity": "sha512-nG3eehhWf9l1q80WuHvp5DV+4xDNFpDWLE5ZgcFD5tslUV2USJ56ogun8gaZ62MKAocJnoStjAdno08b8U57hg==", "dependencies": { - "bson": "^6.5.0", + "bson": "^6.7.0", "kareem": "2.6.3", - "mongodb": "6.5.0", + "mongodb": "6.7.0", "mpath": "0.9.0", "mquery": "5.0.0", "ms": "2.1.3", @@ -10553,28 +10472,28 @@ } }, "node_modules/mongoose/node_modules/@types/whatwg-url": { - "version": "11.0.4", - "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.4.tgz", - "integrity": "sha512-lXCmTWSHJvf0TRSO58nm978b8HJ/EdsSsEKLd3ODHFjo+3VGAyyTp4v50nWvwtzBxSMQrVOK7tcuN0zGPLICMw==", + "version": "11.0.5", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.5.tgz", + "integrity": "sha512-coYR071JRaHa+xoEvvYqvnIHaVqaYrLPbsufM9BF63HkwI5Lgmy2QR8Q5K/lYDYo5AK82wOvSOS0UsLTpTG7uQ==", "dependencies": { "@types/webidl-conversions": "*" } }, "node_modules/mongoose/node_modules/bson": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/bson/-/bson-6.7.0.tgz", - "integrity": "sha512-w2IquM5mYzYZv6rs3uN2DZTOBe2a0zXLj53TGDqwF4l6Sz/XsISrisXOJihArF9+BZ6Cq/GjVht7Sjfmri7ytQ==", + "version": "6.8.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-6.8.0.tgz", + "integrity": "sha512-iOJg8pr7wq2tg/zSlCCHMi3hMm5JTOxLTagf3zxhcenHsFp+c6uOs6K7W5UE7A4QIJGtqh/ZovFNMP4mOPJynQ==", "engines": { "node": ">=16.20.1" } }, "node_modules/mongoose/node_modules/mongodb": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.5.0.tgz", - "integrity": "sha512-Fozq68InT+JKABGLqctgtb8P56pRrJFkbhW0ux+x1mdHeyinor8oNzJqwLjV/t5X5nJGfTlluxfyMnOXNggIUA==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.7.0.tgz", + "integrity": "sha512-TMKyHdtMcO0fYBNORiYdmM25ijsHs+Njs963r4Tro4OQZzqYigAzYQouwWRg4OIaiLRUEGUh/1UAcH5lxdSLIA==", "dependencies": { "@mongodb-js/saslprep": "^1.1.5", - "bson": "^6.4.0", + "bson": "^6.7.0", "mongodb-connection-string-url": "^3.0.0" }, "engines": { diff --git a/package.json b/package.json index ee1d5f6..5f7ebf4 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "date-fns-tz": "2.0.1", "googleapis": "142.0.0", "ics": "3.7.6", - "mongoose": "8.3.5", + "mongoose": "^8.5.4", "next": "^14.0.1", "next-auth": "4.24.7", "next-axiom": "^1.1.0", diff --git a/pages/admin/bookings/[uuid]/bill.tsx b/pages/admin/bookings/[uuid]/bill.tsx index fc2e7f0..669f545 100644 --- a/pages/admin/bookings/[uuid]/bill.tsx +++ b/pages/admin/bookings/[uuid]/bill.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react' import Input from '../../../../components/input' import Select from '../../../../components/select' -import { Booking } from '../../../../db/booking' +import { IBooking } from '../../../../db/booking' import { BILL_STATUS, MILAGE_TARIFS } from '../../../../db/enums' import { getMilageMax } from '../../../../db/index' import { daysFormatFrontend } from '../../../../helpers/date' @@ -67,7 +67,7 @@ function BookingBillPage({ booking: bookingProp, milageMax, }: { - booking: Booking + booking: IBooking milageMax: number }) { const [booking, setBooking] = useState(bookingProp) @@ -262,4 +262,4 @@ function BookingBillPage({ BookingBillPage.authenticationRequired = true -export default BookingBillPage +export default BookingBillPage \ No newline at end of file diff --git a/pages/admin/bookings/[uuid]/index.tsx b/pages/admin/bookings/[uuid]/index.tsx index a2a189b..b9b510b 100644 --- a/pages/admin/bookings/[uuid]/index.tsx +++ b/pages/admin/bookings/[uuid]/index.tsx @@ -3,7 +3,7 @@ import { useRouter } from 'next/router' import Link from 'next/link' import Calendar from '../../../../components/calendar' import { getServerSideBooking } from '../../../../lib/getServerSideProps' -import { BookingDocument } from '../../../../db/booking' +import { IBooking } from '../../../../db/booking' import { patchBooking } from '../../../../helpers/booking' import { log } from '../../../../helpers/log' import { BOOKING_STATUS } from '../../../../db/enums' @@ -11,7 +11,7 @@ import BookingTable from '../../../../components/bookingTable' export const getServerSideProps = getServerSideBooking -function ShowBookingAdmin({ booking: bookingProp }: { booking: BookingDocument }) { +function ShowBookingAdmin({ booking: bookingProp }: { booking: IBooking }) { const router = useRouter() const [booking, setBooking] = useState(bookingProp) const [storingBooking, setStoringBooking] = useState(false) diff --git a/pages/api/bookings/[uuid]/bill.ts b/pages/api/bookings/[uuid]/bill.ts index abe0f0e..3e77dc9 100644 --- a/pages/api/bookings/[uuid]/bill.ts +++ b/pages/api/bookings/[uuid]/bill.ts @@ -1,5 +1,5 @@ import { NextApiRequest, NextApiResponse } from 'next' -import { Bill } from '../../../../db/bill' +import { IBill } from '../../../../db/bill' import { createBill, patchBill } from '../../../../db/index' import { log } from '../../../../helpers/log' @@ -13,7 +13,7 @@ export default async function billHandler( } = req const bookingUUID = Array.isArray(uuids) ? uuids[0] : uuids - let bill: Bill + let bill: IBill switch (method) { case 'POST': @@ -40,4 +40,4 @@ export default async function billHandler( res.setHeader('Allow', ['POST', 'PATCH']) res.status(405).end(`Method ${method} Not Allowed`) } -} +} \ No newline at end of file diff --git a/pages/api/bookings/[uuid]/index.ts b/pages/api/bookings/[uuid]/index.ts index d5e4da9..8b25d0f 100644 --- a/pages/api/bookings/[uuid]/index.ts +++ b/pages/api/bookings/[uuid]/index.ts @@ -1,5 +1,5 @@ import { NextApiRequest, NextApiResponse } from 'next' -import { Booking } from '../../../../db/booking' +import { IBooking } from '../../../../db/booking' import { BOOKING_STATUS } from '../../../../db/enums' import { patchBooking } from '../../../../db/index' import { @@ -10,8 +10,8 @@ import { import { log } from '../../../../helpers/log' function changedStatus( - previous: Booking, - current: Partial, + previous: IBooking, + current: Partial, status: BOOKING_STATUS ): boolean { return ( @@ -19,15 +19,15 @@ function changedStatus( current.status === status ) } -function wasRejected(previous: Booking, current: Partial): boolean { +function wasRejected(previous: IBooking, current: Partial): boolean { return changedStatus(previous, current, BOOKING_STATUS.REJECTED) } -function wasConfirmed(previous: Booking, current: Partial): boolean { +function wasConfirmed(previous: IBooking, current: Partial): boolean { return changedStatus(previous, current, BOOKING_STATUS.CONFIRMED) } -function wasCanceled(previous: Booking, current: Partial): boolean { +function wasCanceled(previous: IBooking, current: Partial): boolean { return ( [BOOKING_STATUS.REQUESTED, BOOKING_STATUS.CONFIRMED].includes( previous.status diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index f3cb082..92fe543 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -1,6 +1,6 @@ import { Error } from 'mongoose' import { NextApiRequest, NextApiResponse } from 'next' -import { Booking } from '../../../db/booking' +import { IBooking } from '../../../db/booking' import { createBooking } from '../../../db/index' import { log } from '../../../helpers/log' import { @@ -14,7 +14,7 @@ export default async function userHandler( ): Promise { const { method } = req - let booking: Booking + let booking: IBooking switch (method) { case 'POST': diff --git a/pages/bookings/[uuid]/index.tsx b/pages/bookings/[uuid]/index.tsx index 9c700ec..4e3609f 100644 --- a/pages/bookings/[uuid]/index.tsx +++ b/pages/bookings/[uuid]/index.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react' import { getServerSideBooking } from '../../../lib/getServerSideProps' -import { Booking } from '../../../db/booking' +import { IBooking } from '../../../db/booking' import { BOOKING_STATUS } from '../../../db/enums' import { daysFormatFrontend } from '../../../helpers/date' import { log } from '../../../helpers/log' @@ -11,7 +11,7 @@ export const getServerSideProps = getServerSideBooking export default function ShowBooking({ booking: bookingProp, }: { - booking: Booking + booking: IBooking }) { const [booking, setBooking] = useState(bookingProp) const [storingBooking, setStoringBooking] = useState(false) @@ -65,4 +65,4 @@ export default function ShowBooking({ )} ) -} +} \ No newline at end of file diff --git a/pages/bookings/[uuid]/stored.tsx b/pages/bookings/[uuid]/stored.tsx index 7cddd1d..e00e803 100644 --- a/pages/bookings/[uuid]/stored.tsx +++ b/pages/bookings/[uuid]/stored.tsx @@ -1,12 +1,12 @@ import React, { useEffect, useState } from 'react' import Link from 'next/link' -import { Booking } from '../../../db/booking' +import { IBooking } from '../../../db/booking' import { loadBookingData, storeBookingData } from '../../../helpers/storage' import { getServerSideBooking } from '../../../lib/getServerSideProps' export const getServerSideProps = getServerSideBooking -export default function ShowBookingStored({ booking }: { booking: Booking }) { +export default function ShowBookingStored({ booking }: { booking: IBooking }) { const [storedBookingData, setStoredBookingData] = useState(null) const [bookingDataStored, setBookingDataStored] = useState(false) @@ -53,4 +53,4 @@ export default function ShowBookingStored({ booking }: { booking: Booking }) { )} ) -} +} \ No newline at end of file