remove *Document intefaces from FE code

This commit is contained in:
Thomas Ruoff
2020-11-06 23:37:04 +01:00
parent 71c16a289d
commit 195da65cd9
13 changed files with 84 additions and 60 deletions

View File

@@ -1,7 +1,7 @@
import * as mongoose from 'mongoose'
import Booker from './booker'
import Booking from './booking'
import Bill, { BillDocument } from './bill'
import BookerModel, { Booker } from './booker'
import BookingModel, { Booking } from './booking'
import BillModel, { Bill } from './bill'
import { dateFormatFrontend } from '../helpers/date'
import { BOOKING_STATUS } from './enums'
@@ -23,17 +23,17 @@ function connect() {
export async function getBookedDays() {
await connect()
return Booking.findBookedDays()
return BookingModel.findBookedDays()
}
export async function getBookingByUUID(uuid: string) {
await connect()
return Booking.findOne({ uuid })
return BookingModel.findOne({ uuid })
}
export async function getBookings() {
await connect()
return await Booking.find({
return await BookingModel.find({
status: { $in: [BOOKING_STATUS.REQUESTED, BOOKING_STATUS.CONFIRMED] },
})
.populate('booker')
@@ -51,9 +51,15 @@ export async function createBooking({
street,
zip,
city,
}) {
}: Booking & Booker): Promise<Booking> {
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 doubleBookedDays = booking.days.filter((day: string) =>
@@ -72,9 +78,9 @@ export async function createBooking({
throw error
}
let booker = await Booker.findOne({ email }).exec()
let booker = await BookerModel.findOne({ email }).exec()
if (!booker) {
booker = new Booker({ name, email, street, zip, city })
booker = new BookerModel({ name, email, street, zip, city })
await booker.save()
}
@@ -84,11 +90,14 @@ export async function createBooking({
return booking.toJSON()
}
export async function createBill(bookingUUID: string, billData: BillDocument) {
export async function createBill(
bookingUUID: string,
billData: Bill
): Promise<Bill> {
await connect()
const booking = await getBookingByUUID(bookingUUID)
const bill = new Bill()
const bill = new BillModel()
bill.set(billData)
await bill.save()
@@ -99,12 +108,15 @@ export async function createBill(bookingUUID: string, billData: BillDocument) {
return bill.toJSON()
}
export async function patchBill(bookingUUID: string, billData: BillDocument) {
export async function patchBill(
bookingUUID: string,
billData: Bill
): Promise<Bill> {
await connect()
const booking = await getBookingByUUID(bookingUUID)
const bill =
(booking.bill && (await Bill.findById(booking.bill))) ||
(await Bill.create())
(booking.bill && (await BillModel.findById(booking.bill))) ||
(await BillModel.create())
bill.set(billData)
await bill.save()
@@ -118,7 +130,7 @@ export async function patchBill(bookingUUID: string, billData: BillDocument) {
}
export async function getMilageMax(): Promise<number> {
const billMaxMilageEnd = await Bill.findOne({})
const billMaxMilageEnd = await BillModel.findOne({})
.sort('-milageEnd')
.select('milageEnd')
.exec()