mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
remove all bill related stuff
This commit is contained in:
57
db/index.ts
57
db/index.ts
@@ -1,13 +1,12 @@
|
||||
import * as mongoose from 'mongoose'
|
||||
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'
|
||||
|
||||
export const MONGO_URI = process.env.MONGO_URI
|
||||
|
||||
mongoose.set('strictQuery', false);
|
||||
mongoose.set('strictQuery', false)
|
||||
|
||||
mongoose.connect(MONGO_URI, {
|
||||
serverSelectionTimeoutMS: 3000,
|
||||
@@ -23,7 +22,9 @@ export async function getBookedDays(
|
||||
return [...bookedInDatabase, ...bookedInCalendar].filter(uniqueFilter).sort()
|
||||
}
|
||||
|
||||
export async function getBookingByUUID(uuid: string): Promise<mongoose.HydratedDocument<IBooking>> {
|
||||
export async function getBookingByUUID(
|
||||
uuid: string
|
||||
): Promise<mongoose.HydratedDocument<IBooking>> {
|
||||
return BookingModel.findOne({ uuid })
|
||||
}
|
||||
|
||||
@@ -53,7 +54,9 @@ export async function createBooking({
|
||||
street,
|
||||
zip,
|
||||
city,
|
||||
}: IBooking): Promise<mongoose.FlattenMaps<IBooking & { _id: mongoose.Types.ObjectId }>> {
|
||||
}: IBooking): Promise<
|
||||
mongoose.FlattenMaps<IBooking & { _id: mongoose.Types.ObjectId }>
|
||||
> {
|
||||
const booking = new BookingModel({
|
||||
startDate,
|
||||
endDate,
|
||||
@@ -83,49 +86,3 @@ export async function patchBooking(
|
||||
|
||||
return { current: booking.toJSON(), previous: oldBooking }
|
||||
}
|
||||
|
||||
export async function createBill(
|
||||
bookingUUID: string,
|
||||
billData: IBill
|
||||
): Promise<IBill> {
|
||||
const booking = await getBookingByUUID(bookingUUID)
|
||||
|
||||
const bill = new BillModel()
|
||||
bill.set(billData)
|
||||
|
||||
await bill.save()
|
||||
|
||||
booking.bill = bill
|
||||
await booking.save()
|
||||
|
||||
return bill.toJSON()
|
||||
}
|
||||
|
||||
export async function patchBill(
|
||||
bookingUUID: string,
|
||||
billData: IBill
|
||||
): Promise<IBill> {
|
||||
const booking = await getBookingByUUID(bookingUUID)
|
||||
const bill =
|
||||
(booking.bill && (await BillModel.findById(booking.bill))) ||
|
||||
(await BillModel.create({}))
|
||||
|
||||
bill.set(billData)
|
||||
await bill.save()
|
||||
|
||||
if (booking.bill !== bill) {
|
||||
booking.bill = bill
|
||||
await booking.save()
|
||||
}
|
||||
|
||||
return bill.toJSON()
|
||||
}
|
||||
|
||||
export async function getMilageMax(): Promise<number> {
|
||||
const billMaxMilageEnd = await BillModel.findOne({})
|
||||
.sort('-milageEnd')
|
||||
.select('milageEnd')
|
||||
.exec()
|
||||
|
||||
return billMaxMilageEnd?.milageEnd || 0
|
||||
}
|
||||
Reference in New Issue
Block a user