another try to fix types for models

This commit is contained in:
Thomas Ruoff
2020-09-03 23:27:30 +02:00
committed by Thomas Ruoff
parent 82270e944c
commit 038e2b2420
5 changed files with 29 additions and 19 deletions

View File

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