post.model.ts 643 Bytes
Newer Older
Yoon, Daeki's avatar
Yoon, Daeki committed
1
import { model, Schema, Types } from "mongoose";
Kim, MinGyu's avatar
Kim, MinGyu committed
2

Lee Soobeom's avatar
Lee Soobeom committed
3
4
5
6
7
8
9
10
export interface PostType {
  title: string;
  text?: string;
  theme: string;
  city: string;
  user?: Types.ObjectId | string;
  date?: Date;
  counts?: number;
Lee Soobeom's avatar
.    
Lee Soobeom committed
11
12
}

Lee Soobeom's avatar
Lee Soobeom committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const PostSchema = new Schema<PostType>({
  title: {
    type: String,
    required: true,
  },
  text: {
    type: String,
    required: true,
  },
  theme: {
    type: String,
  },
  city: {
    type: String,
  },
  user: {
    type: Schema.Types.ObjectId,
    ref: "User",
  },
  date: {
    type: Date,
    default: Date.now,
  },
  counts: {
    type: Number,
  },
Kim, MinGyu's avatar
Kim, MinGyu committed
39
40
});

Lee Soobeom's avatar
Lee Soobeom committed
41
export default model<PostType>("Post", PostSchema);