Guest User

Untitled

a guest
Jan 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import { Document, Schema, Model, model } from "mongoose";
  2.  
  3. export interface VehicleDocument extends Document {
  4. year: number;
  5. name: string;
  6. createdDate: Date;
  7. }
  8.  
  9. export interface VehicleModel extends VehicleDocument {}
  10.  
  11. export const VehicleSchema: Schema = new Schema(
  12. {
  13. year: Number,
  14. name: String,
  15. createdDate: Date
  16. },
  17. { collection: "vehicles" }
  18. );
  19.  
  20. VehicleSchema.pre<VehicleDocument>("save", async function() {
  21. this.createdDate = new Date();
  22. });
  23.  
  24. export const Vehicle: Model<VehicleModel> = model<VehicleModel>(
  25. "Vehicle",
  26. VehicleSchema
  27. );
Add Comment
Please, Sign In to add comment