mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
remove *Document intefaces from FE code
This commit is contained in:
@@ -7,9 +7,7 @@ export interface AdditionalCost {
|
|||||||
value: number
|
value: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BillDocument
|
export interface Bill {
|
||||||
extends mongoose.SchemaTimestampsConfig,
|
|
||||||
mongoose.Document {
|
|
||||||
milageStart: number
|
milageStart: number
|
||||||
milageEnd: number
|
milageEnd: number
|
||||||
milage?: number
|
milage?: number
|
||||||
@@ -18,6 +16,11 @@ export interface BillDocument
|
|||||||
additionalCosts: AdditionalCost[]
|
additionalCosts: AdditionalCost[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BillDocument
|
||||||
|
extends Bill,
|
||||||
|
mongoose.SchemaTimestampsConfig,
|
||||||
|
mongoose.Document {}
|
||||||
|
|
||||||
export interface BillModel extends mongoose.Model<BillDocument> {}
|
export interface BillModel extends mongoose.Model<BillDocument> {}
|
||||||
|
|
||||||
const BillSchema = new mongoose.Schema<BillDocument>(
|
const BillSchema = new mongoose.Schema<BillDocument>(
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import * as mongoose from 'mongoose'
|
import * as mongoose from 'mongoose'
|
||||||
|
|
||||||
export interface BookerDocument
|
export interface Booker {
|
||||||
extends mongoose.SchemaTimestampsConfig,
|
|
||||||
mongoose.Document {
|
|
||||||
name: string
|
name: string
|
||||||
email: string
|
email: string
|
||||||
street: string
|
street: string
|
||||||
@@ -10,6 +8,11 @@ export interface BookerDocument
|
|||||||
city: string
|
city: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BookerDocument
|
||||||
|
extends Booker,
|
||||||
|
mongoose.SchemaTimestampsConfig,
|
||||||
|
mongoose.Document {}
|
||||||
|
|
||||||
export interface BookerModel extends mongoose.Model<BookerDocument> {}
|
export interface BookerModel extends mongoose.Model<BookerDocument> {}
|
||||||
|
|
||||||
const BookerSchema = new mongoose.Schema<BookerDocument>(
|
const BookerSchema = new mongoose.Schema<BookerDocument>(
|
||||||
|
|||||||
@@ -2,16 +2,14 @@ import * as mongoose from 'mongoose'
|
|||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
import { startOfDay } from 'date-fns'
|
import { startOfDay } from 'date-fns'
|
||||||
import { dateFormatBackend, getDays } from '../helpers/date'
|
import { dateFormatBackend, getDays } from '../helpers/date'
|
||||||
import { BillDocument } from './bill'
|
import { Bill } from './bill'
|
||||||
import { BookerDocument } from './booker'
|
import { Booker } from './booker'
|
||||||
import { BOOKING_STATUS } from './enums'
|
import { BOOKING_STATUS } from './enums'
|
||||||
|
|
||||||
export interface BookingDocument
|
export interface Booking {
|
||||||
extends mongoose.Document,
|
|
||||||
mongoose.SchemaTimestampsConfig {
|
|
||||||
uuid: string
|
uuid: string
|
||||||
booker: BookerDocument
|
booker: Booker
|
||||||
bill: BillDocument
|
bill: Bill
|
||||||
startDate: Date
|
startDate: Date
|
||||||
endDate: Date
|
endDate: Date
|
||||||
status: BOOKING_STATUS
|
status: BOOKING_STATUS
|
||||||
@@ -21,6 +19,11 @@ export interface BookingDocument
|
|||||||
days?: string[]
|
days?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BookingDocument
|
||||||
|
extends Booking,
|
||||||
|
mongoose.Document,
|
||||||
|
mongoose.SchemaTimestampsConfig {}
|
||||||
|
|
||||||
export interface BookingModel extends mongoose.Model<BookingDocument> {
|
export interface BookingModel extends mongoose.Model<BookingDocument> {
|
||||||
findBookedDays(): Promise<string[]>
|
findBookedDays(): Promise<string[]>
|
||||||
}
|
}
|
||||||
|
|||||||
44
db/index.ts
44
db/index.ts
@@ -1,7 +1,7 @@
|
|||||||
import * as mongoose from 'mongoose'
|
import * as mongoose from 'mongoose'
|
||||||
import Booker from './booker'
|
import BookerModel, { Booker } from './booker'
|
||||||
import Booking from './booking'
|
import BookingModel, { Booking } from './booking'
|
||||||
import Bill, { BillDocument } from './bill'
|
import BillModel, { Bill } from './bill'
|
||||||
import { dateFormatFrontend } from '../helpers/date'
|
import { dateFormatFrontend } from '../helpers/date'
|
||||||
import { BOOKING_STATUS } from './enums'
|
import { BOOKING_STATUS } from './enums'
|
||||||
|
|
||||||
@@ -23,17 +23,17 @@ function connect() {
|
|||||||
|
|
||||||
export async function getBookedDays() {
|
export async function getBookedDays() {
|
||||||
await connect()
|
await connect()
|
||||||
return Booking.findBookedDays()
|
return BookingModel.findBookedDays()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getBookingByUUID(uuid: string) {
|
export async function getBookingByUUID(uuid: string) {
|
||||||
await connect()
|
await connect()
|
||||||
return Booking.findOne({ uuid })
|
return BookingModel.findOne({ uuid })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getBookings() {
|
export async function getBookings() {
|
||||||
await connect()
|
await connect()
|
||||||
return await Booking.find({
|
return await BookingModel.find({
|
||||||
status: { $in: [BOOKING_STATUS.REQUESTED, BOOKING_STATUS.CONFIRMED] },
|
status: { $in: [BOOKING_STATUS.REQUESTED, BOOKING_STATUS.CONFIRMED] },
|
||||||
})
|
})
|
||||||
.populate('booker')
|
.populate('booker')
|
||||||
@@ -51,9 +51,15 @@ export async function createBooking({
|
|||||||
street,
|
street,
|
||||||
zip,
|
zip,
|
||||||
city,
|
city,
|
||||||
}) {
|
}: Booking & Booker): Promise<Booking> {
|
||||||
await connect()
|
await connect()
|
||||||
const booking = new Booking({ startDate, endDate, purpose, org, destination })
|
const booking = new BookingModel({
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
purpose,
|
||||||
|
org,
|
||||||
|
destination,
|
||||||
|
})
|
||||||
const bookedDays = await getBookedDays()
|
const bookedDays = await getBookedDays()
|
||||||
|
|
||||||
const doubleBookedDays = booking.days.filter((day: string) =>
|
const doubleBookedDays = booking.days.filter((day: string) =>
|
||||||
@@ -72,9 +78,9 @@ export async function createBooking({
|
|||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
let booker = await Booker.findOne({ email }).exec()
|
let booker = await BookerModel.findOne({ email }).exec()
|
||||||
if (!booker) {
|
if (!booker) {
|
||||||
booker = new Booker({ name, email, street, zip, city })
|
booker = new BookerModel({ name, email, street, zip, city })
|
||||||
await booker.save()
|
await booker.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,11 +90,14 @@ export async function createBooking({
|
|||||||
return booking.toJSON()
|
return booking.toJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createBill(bookingUUID: string, billData: BillDocument) {
|
export async function createBill(
|
||||||
|
bookingUUID: string,
|
||||||
|
billData: Bill
|
||||||
|
): Promise<Bill> {
|
||||||
await connect()
|
await connect()
|
||||||
const booking = await getBookingByUUID(bookingUUID)
|
const booking = await getBookingByUUID(bookingUUID)
|
||||||
|
|
||||||
const bill = new Bill()
|
const bill = new BillModel()
|
||||||
bill.set(billData)
|
bill.set(billData)
|
||||||
|
|
||||||
await bill.save()
|
await bill.save()
|
||||||
@@ -99,12 +108,15 @@ export async function createBill(bookingUUID: string, billData: BillDocument) {
|
|||||||
return bill.toJSON()
|
return bill.toJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function patchBill(bookingUUID: string, billData: BillDocument) {
|
export async function patchBill(
|
||||||
|
bookingUUID: string,
|
||||||
|
billData: Bill
|
||||||
|
): Promise<Bill> {
|
||||||
await connect()
|
await connect()
|
||||||
const booking = await getBookingByUUID(bookingUUID)
|
const booking = await getBookingByUUID(bookingUUID)
|
||||||
const bill =
|
const bill =
|
||||||
(booking.bill && (await Bill.findById(booking.bill))) ||
|
(booking.bill && (await BillModel.findById(booking.bill))) ||
|
||||||
(await Bill.create())
|
(await BillModel.create())
|
||||||
|
|
||||||
bill.set(billData)
|
bill.set(billData)
|
||||||
await bill.save()
|
await bill.save()
|
||||||
@@ -118,7 +130,7 @@ export async function patchBill(bookingUUID: string, billData: BillDocument) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getMilageMax(): Promise<number> {
|
export async function getMilageMax(): Promise<number> {
|
||||||
const billMaxMilageEnd = await Bill.findOne({})
|
const billMaxMilageEnd = await BillModel.findOne({})
|
||||||
.sort('-milageEnd')
|
.sort('-milageEnd')
|
||||||
.select('milageEnd')
|
.select('milageEnd')
|
||||||
.exec()
|
.exec()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createEvents, EventStatus } from 'ics'
|
import { createEvents, EventStatus } from 'ics'
|
||||||
import { BookingDocument } from '../db/booking'
|
import { Booking } from '../db/booking'
|
||||||
import { BOOKING_STATUS } from '../db/enums'
|
import { BOOKING_STATUS } from '../db/enums'
|
||||||
import { getBaseURL } from './url'
|
import { getBaseURL } from './url'
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ function convertDay(value: string): [number, number, number] {
|
|||||||
return [Number(parts[0]), Number(parts[1]), Number(parts[2])]
|
return [Number(parts[0]), Number(parts[1]), Number(parts[2])]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateBookedCalendar(bookings: BookingDocument[]) {
|
export function generateBookedCalendar(bookings: Booking[]) {
|
||||||
const events = bookings.map((booking) => ({
|
const events = bookings.map((booking) => ({
|
||||||
calName: 'Pfadi-Bussle Buchungen',
|
calName: 'Pfadi-Bussle Buchungen',
|
||||||
start: convertDay(booking.days[0]),
|
start: convertDay(booking.days[0]),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { BookingDocument } from '../db/booking'
|
import { Booking } from '../db/booking'
|
||||||
import { getBaseURL } from '../helpers/url'
|
import { getBaseURL } from '../helpers/url'
|
||||||
|
|
||||||
const SENDGRID_API_KEY = process.env.SENDGRID_API_KEY
|
const SENDGRID_API_KEY = process.env.SENDGRID_API_KEY
|
||||||
@@ -28,7 +28,7 @@ Pfadi Bussle Wart
|
|||||||
Tel. 0151/212 253 62
|
Tel. 0151/212 253 62
|
||||||
`
|
`
|
||||||
|
|
||||||
function getReceivedBookingBookerText(booking: BookingDocument) {
|
function getReceivedBookingBookerText(booking: Booking) {
|
||||||
return `Hallo liebe/r ${booking.booker.name},
|
return `Hallo liebe/r ${booking.booker.name},
|
||||||
|
|
||||||
Vielen Dank für Deine Buchung. Nach Prüfung bestätigen wir die Buchung bald per E-Mail!
|
Vielen Dank für Deine Buchung. Nach Prüfung bestätigen wir die Buchung bald per E-Mail!
|
||||||
@@ -43,7 +43,7 @@ ${footer}
|
|||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBookingConfirmedText(booking: BookingDocument) {
|
function getBookingConfirmedText(booking: Booking) {
|
||||||
return `Hallo liebe/r ${booking.booker.name},
|
return `Hallo liebe/r ${booking.booker.name},
|
||||||
|
|
||||||
deine Buchung ist bestätigt!
|
deine Buchung ist bestätigt!
|
||||||
@@ -57,7 +57,7 @@ einsehen und stornieren.
|
|||||||
${footer}
|
${footer}
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
function getBookingRejectedText(booking: BookingDocument) {
|
function getBookingRejectedText(booking: Booking) {
|
||||||
return `Hallo liebe/r ${booking.booker.name},
|
return `Hallo liebe/r ${booking.booker.name},
|
||||||
|
|
||||||
es tut uns leid aber deine Buchung konnte leider nicht bestätigt werden.
|
es tut uns leid aber deine Buchung konnte leider nicht bestätigt werden.
|
||||||
@@ -77,7 +77,7 @@ es ging folgende Buchung ein: ${getBaseURL()}/admin/booking/${booking.uuid}
|
|||||||
MfG`
|
MfG`
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendReceivedBookingAdminMail(booking: BookingDocument) {
|
export async function sendReceivedBookingAdminMail(booking: Booking) {
|
||||||
try {
|
try {
|
||||||
await sendMail({
|
await sendMail({
|
||||||
to: [{ email: ADMIN_EMAIL }],
|
to: [{ email: ADMIN_EMAIL }],
|
||||||
@@ -90,7 +90,7 @@ export async function sendReceivedBookingAdminMail(booking: BookingDocument) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendReceivedBookingBookerMail(booking: BookingDocument) {
|
export async function sendReceivedBookingBookerMail(booking: Booking) {
|
||||||
try {
|
try {
|
||||||
await sendMail({
|
await sendMail({
|
||||||
to: [{ email: booking.booker.email, name: booking.booker.name }],
|
to: [{ email: booking.booker.email, name: booking.booker.name }],
|
||||||
@@ -103,7 +103,7 @@ export async function sendReceivedBookingBookerMail(booking: BookingDocument) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendBookingConfirmed(booking: BookingDocument) {
|
export async function sendBookingConfirmed(booking: Booking) {
|
||||||
try {
|
try {
|
||||||
await sendMail({
|
await sendMail({
|
||||||
to: [{ email: booking.booker.email, name: booking.booker.name }],
|
to: [{ email: booking.booker.email, name: booking.booker.name }],
|
||||||
@@ -116,7 +116,7 @@ export async function sendBookingConfirmed(booking: BookingDocument) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendBookingRejected(booking: BookingDocument) {
|
export async function sendBookingRejected(booking: Booking) {
|
||||||
try {
|
try {
|
||||||
await sendMail({
|
await sendMail({
|
||||||
to: [{ email: booking.booker.email, name: booking.booker.name }],
|
to: [{ email: booking.booker.email, name: booking.booker.name }],
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import Footer from '../../../../components/footer'
|
|||||||
import Header from '../../../../components/header'
|
import Header from '../../../../components/header'
|
||||||
import Input from '../../../../components/input'
|
import Input from '../../../../components/input'
|
||||||
import Select from '../../../../components/select'
|
import Select from '../../../../components/select'
|
||||||
import { AdditionalCost, BillDocument } from '../../../../db/bill'
|
import { AdditionalCost, Bill } from '../../../../db/bill'
|
||||||
import { BookingDocument } from '../../../../db/booking'
|
import { Booking } from '../../../../db/booking'
|
||||||
import { BILL_STATUS, MILAGE_TARIFS } from '../../../../db/enums'
|
import { BILL_STATUS, MILAGE_TARIFS } from '../../../../db/enums'
|
||||||
import { getMilageMax } from '../../../../db/index'
|
import { getMilageMax } from '../../../../db/index'
|
||||||
import { dateFormatFrontend } from '../../../../helpers/date'
|
import { dateFormatFrontend } from '../../../../helpers/date'
|
||||||
@@ -80,7 +80,7 @@ function getBillStatusLabel(status: BILL_STATUS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function saveBill(
|
async function saveBill(
|
||||||
booking: BookingDocument,
|
booking: Booking,
|
||||||
bill: {
|
bill: {
|
||||||
milageStart: number
|
milageStart: number
|
||||||
milageEnd: number
|
milageEnd: number
|
||||||
@@ -89,9 +89,9 @@ async function saveBill(
|
|||||||
additionalCosts: AdditionalCost[]
|
additionalCosts: AdditionalCost[]
|
||||||
status: BILL_STATUS
|
status: BILL_STATUS
|
||||||
}
|
}
|
||||||
): Promise<BillDocument> {
|
): Promise<Bill> {
|
||||||
const response = await fetch(`/api/admin/booking/${booking.uuid}/bill`, {
|
const response = await fetch(`/api/admin/booking/${booking.uuid}/bill`, {
|
||||||
method: booking.bill?._id ? 'PATCH' : 'POST',
|
method: !!booking.bill ? 'PATCH' : 'POST',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
credentials: 'same-origin',
|
credentials: 'same-origin',
|
||||||
@@ -108,7 +108,7 @@ export default function BookingBillPage({
|
|||||||
booking: bookingProp,
|
booking: bookingProp,
|
||||||
milageMax,
|
milageMax,
|
||||||
}: {
|
}: {
|
||||||
booking: BookingDocument
|
booking: Booking
|
||||||
milageMax: number
|
milageMax: number
|
||||||
}) {
|
}) {
|
||||||
const [booking, setBooking] = useState(bookingProp)
|
const [booking, setBooking] = useState(bookingProp)
|
||||||
@@ -300,7 +300,7 @@ export default function BookingBillPage({
|
|||||||
className="btn btn-blue mt-3"
|
className="btn btn-blue mt-3"
|
||||||
disabled={storingInProgress}
|
disabled={storingInProgress}
|
||||||
>
|
>
|
||||||
Rechnung {booking.bill?._id ? 'Updaten' : 'Erstellen'}
|
Rechnung {!!booking.bill ? 'Updaten' : 'Erstellen'}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import withSession, {
|
|||||||
redirectToLogin,
|
redirectToLogin,
|
||||||
} from '../../../../lib/session'
|
} from '../../../../lib/session'
|
||||||
import { getServerSideBooking } from '../../../../lib/getServerSideProps'
|
import { getServerSideBooking } from '../../../../lib/getServerSideProps'
|
||||||
import { BookingDocument } from '../../../../db/booking'
|
import { Booking } from '../../../../db/booking'
|
||||||
import { getBookingStatus } from '../../../../helpers/booking'
|
import { getBookingStatus } from '../../../../helpers/booking'
|
||||||
import { dateFormatFrontend } from '../../../../helpers/date'
|
import { dateFormatFrontend } from '../../../../helpers/date'
|
||||||
import { BOOKING_STATUS } from '../../../../db/enums'
|
import { BOOKING_STATUS } from '../../../../db/enums'
|
||||||
@@ -52,7 +52,7 @@ async function patchBooking(uuid: string, bookingData: any) {
|
|||||||
export default function ShowBookingAdmin({
|
export default function ShowBookingAdmin({
|
||||||
booking: bookingProp,
|
booking: bookingProp,
|
||||||
}: {
|
}: {
|
||||||
booking: BookingDocument
|
booking: Booking
|
||||||
}) {
|
}) {
|
||||||
const [booking, setBooking] = useState(bookingProp)
|
const [booking, setBooking] = useState(bookingProp)
|
||||||
const [storingBooking, setStoringBooking] = useState(false)
|
const [storingBooking, setStoringBooking] = useState(false)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { BillDocument } from '../../../../../db/bill'
|
import { Bill } from '../../../../../db/bill'
|
||||||
import { createBill, patchBill } from '../../../../../db/index'
|
import { createBill, patchBill } from '../../../../../db/index'
|
||||||
import withSession, { isAdminSession } from '../../../../../lib/session'
|
import withSession, { isAdminSession } from '../../../../../lib/session'
|
||||||
|
|
||||||
export default withSession(async function billHandler(req, res) {
|
export default withSession(async function billHandler(req, res) {
|
||||||
if (!isAdminSession(req, res)) {
|
if (!isAdminSession(req)) {
|
||||||
res.status(403).send({ message: 'Not Authorized' })
|
res.status(403).send({ message: 'Not Authorized' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@ export default withSession(async function billHandler(req, res) {
|
|||||||
} = req
|
} = req
|
||||||
const bookingUUID = Array.isArray(uuids) ? uuids[0] : uuids
|
const bookingUUID = Array.isArray(uuids) ? uuids[0] : uuids
|
||||||
|
|
||||||
let bill: BillDocument
|
let bill: Bill
|
||||||
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case 'POST':
|
case 'POST':
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
import { BOOKING_STATUS } from '../../../../../db/enums'
|
import { BOOKING_STATUS } from '../../../../../db/enums'
|
||||||
|
|
||||||
export default withSession(async function bookingHandler(req, res) {
|
export default withSession(async function bookingHandler(req, res) {
|
||||||
if (!isAdminSession(req, res)) {
|
if (!isAdminSession(req)) {
|
||||||
res.status(403).send({ message: 'Not Authorized' })
|
res.status(403).send({ message: 'Not Authorized' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import { Error } from 'mongoose'
|
import { Error } from 'mongoose'
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
import { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import { BookingDocument } from '../../../db/booking'
|
import { Booking } from '../../../db/booking'
|
||||||
import { createBooking } from '../../../db/index'
|
import { createBooking } from '../../../db/index'
|
||||||
import { sendReceivedBookingAdminMail, sendReceivedBookingBookerMail } from '../../../helpers/mail'
|
import {
|
||||||
|
sendReceivedBookingAdminMail,
|
||||||
|
sendReceivedBookingBookerMail,
|
||||||
|
} from '../../../helpers/mail'
|
||||||
|
|
||||||
export default async function userHandler(
|
export default async function userHandler(
|
||||||
req: NextApiRequest,
|
req: NextApiRequest,
|
||||||
@@ -10,7 +13,7 @@ export default async function userHandler(
|
|||||||
) {
|
) {
|
||||||
const { method } = req
|
const { method } = req
|
||||||
|
|
||||||
let booking: BookingDocument
|
let booking: Booking
|
||||||
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case 'POST':
|
case 'POST':
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ import React, { useEffect, useState } from 'react'
|
|||||||
import Footer from '../../../components/footer'
|
import Footer from '../../../components/footer'
|
||||||
import Header from '../../../components/header'
|
import Header from '../../../components/header'
|
||||||
import { getServerSideBooking } from '../../../lib/getServerSideProps'
|
import { getServerSideBooking } from '../../../lib/getServerSideProps'
|
||||||
import { BookingDocument } from '../../../db/booking'
|
import { Booking } from '../../../db/booking'
|
||||||
import { BOOKING_STATUS } from '../../../db/enums'
|
import { BOOKING_STATUS } from '../../../db/enums'
|
||||||
import { dateFormatFrontend } from '../../../helpers/date'
|
import { dateFormatFrontend } from '../../../helpers/date'
|
||||||
import { getBookingStatus } from '../../../helpers/booking'
|
import { getBookingStatus } from '../../../helpers/booking'
|
||||||
|
|
||||||
export const getServerSideProps = getServerSideBooking
|
export const getServerSideProps = getServerSideBooking
|
||||||
|
|
||||||
async function cancelBooking(booking: BookingDocument) {
|
async function cancelBooking(booking: Booking) {
|
||||||
const response = await fetch(`/api/booking/${booking.uuid}`, {
|
const response = await fetch(`/api/booking/${booking.uuid}`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
@@ -27,7 +27,7 @@ async function cancelBooking(booking: BookingDocument) {
|
|||||||
export default function ShowBooking({
|
export default function ShowBooking({
|
||||||
booking: bookingProp,
|
booking: bookingProp,
|
||||||
}: {
|
}: {
|
||||||
booking: BookingDocument
|
booking: Booking
|
||||||
}) {
|
}) {
|
||||||
const [booking, setBooking] = useState(bookingProp)
|
const [booking, setBooking] = useState(bookingProp)
|
||||||
const [storingBooking, setStoringBooking] = useState(false)
|
const [storingBooking, setStoringBooking] = useState(false)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'
|
|||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import Footer from '../../../components/footer'
|
import Footer from '../../../components/footer'
|
||||||
import Header from '../../../components/header'
|
import Header from '../../../components/header'
|
||||||
import { BookingDocument } from '../../../db/booking'
|
import { Booking } from '../../../db/booking'
|
||||||
import { loadBookingData, storeBookingData } from '../../../helpers/storage'
|
import { loadBookingData, storeBookingData } from '../../../helpers/storage'
|
||||||
import { getServerSideBooking } from '../../../lib/getServerSideProps'
|
import { getServerSideBooking } from '../../../lib/getServerSideProps'
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ export const getServerSideProps = getServerSideBooking
|
|||||||
export default function ShowBookingStored({
|
export default function ShowBookingStored({
|
||||||
booking: booking,
|
booking: booking,
|
||||||
}: {
|
}: {
|
||||||
booking: BookingDocument
|
booking: Booking
|
||||||
}) {
|
}) {
|
||||||
const [storedBookingData, setStoredBookingData] = useState(null)
|
const [storedBookingData, setStoredBookingData] = useState(null)
|
||||||
const [bookingDataStored, setBookingDataStored] = useState(false)
|
const [bookingDataStored, setBookingDataStored] = useState(false)
|
||||||
|
|||||||
Reference in New Issue
Block a user