further typing improvements

This commit is contained in:
Thomas Ruoff
2020-08-28 23:20:18 +02:00
committed by Thomas Ruoff
parent 90ac05a907
commit 52a68e9989
17 changed files with 94 additions and 71 deletions

View File

@@ -1,6 +1,16 @@
import * as mongoose from 'mongoose'
const BookerSchema = new mongoose.Schema(
export interface Booker
extends mongoose.SchemaTimestampsConfig,
mongoose.Document {
name: string
email: string
street: string
zip: string
city: string
}
const BookerSchema = new mongoose.Schema<Booker>(
{
name: { type: String, required: true },
email: { type: String, required: true, unique: true, minlength: 5 },
@@ -11,4 +21,6 @@ const BookerSchema = new mongoose.Schema(
{ timestamps: true, collation: { locale: 'de', strength: 1 } }
)
export default mongoose.models.Booker || mongoose.model('Booker', BookerSchema)
const Model: mongoose.Model<Booker> =
mongoose.models.Booker || mongoose.model('Booker', BookerSchema)
export default Model

View File

@@ -1,11 +1,24 @@
import { v4 as uuidv4 } from 'uuid'
import * as mongoose from 'mongoose'
import { getDays, dateFormatBackend } from '../helpers/date'
import { v4 as uuidv4 } from 'uuid'
import { dateFormatBackend, getDays } from '../helpers/date'
import { Booker } from './booker'
import { BOOKING_STATUS } from './bookingStatus'
const BookingSchema = new mongoose.Schema(
export interface Booking
extends mongoose.Document,
mongoose.SchemaTimestampsConfig {
uuid: string
booker: Booker
startDate: Date
endDate: Date
status: string
purpose: string
org: string
destination: string
days?: string[]
}
const BookingSchema = new mongoose.Schema<Booking>(
{
// need a seperate uuid to be able to target a booking anonimously
uuid: {
@@ -51,7 +64,7 @@ BookingSchema.virtual('days').get(function () {
return getDays({ startDate: this.startDate, endDate: this.endDate })
})
BookingSchema.virtual('hash').get(function () {})
const Model: mongoose.Model<Booking> =
mongoose.models.Booking || mongoose.model('Booking', BookingSchema)
export default mongoose.models.Booking ||
mongoose.model('Booking', BookingSchema)
export default Model

View File

@@ -1,5 +1,4 @@
import * as mongoose from 'mongoose'
import Booker from './booker'
import Booking from './booking'
import { BOOKING_STATUS } from './bookingStatus'