Skip to content

Instantly share code, notes, and snippets.

@mikeyakymenko
Created February 19, 2020 12:40
Show Gist options
  • Save mikeyakymenko/35ed82625d1157d8235264c551bead65 to your computer and use it in GitHub Desktop.
Save mikeyakymenko/35ed82625d1157d8235264c551bead65 to your computer and use it in GitHub Desktop.
Models
import * as mongoose from 'mongoose'
import {AdressDbModel} from './types'
const adressSchema = new mongoose.Schema({
country: {
type: String,
required: true
},
city: {
type: String,
required: true
},
streetAdress: {
type: String,
required: true
},
state: {
type: String,
required: true
},
postal: {
type: String,
required: true
},
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}
}, {
timestamps: true,
versionKey: false
})
const Adress = mongoose.model<AdressDbModel>('User', adressSchema)
export default Adress
import Document from 'mongoose'
import {UserDbModel} from 'controllers/users/types'
type AdressModel = {
сountry: string
city: string
streetAdress: string
state: string
postal: string
user: UserDbModel['_id']
}
type AdressDbModel = AdressModel & Document
export {AdressDbModel}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment