Created
January 19, 2019 11:07
-
-
Save PavelPolyakov/e6fd6cde17d2a869612e7a58a9e4684b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Document, Schema, Model, model } from "mongoose"; | |
export interface VehicleDocument extends Document { | |
year: number; | |
name: string; | |
createdDate: Date; | |
} | |
export interface VehicleModel extends VehicleDocument {} | |
export const VehicleSchema: Schema = new Schema( | |
{ | |
year: Number, | |
name: String, | |
createdDate: Date | |
}, | |
{ collection: "vehicles" } | |
); | |
VehicleSchema.pre<VehicleDocument>("save", async function() { | |
this.createdDate = new Date(); | |
}); | |
export const Vehicle: Model<VehicleModel> = model<VehicleModel>( | |
"Vehicle", | |
VehicleSchema | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
refers to https://medium.com/car2godevs/fastify-with-typescript-production-ready-integration-2303318ecd9e