post.model.ts 656 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
export interface PostType {
  title: string;
Yoon, Daeki's avatar
Yoon, Daeki committed
5
  text: string;
Lee Soobeom's avatar
Lee Soobeom committed
6
7
  theme: string;
  city: string;
Yoon, Daeki's avatar
Yoon, Daeki committed
8
9
  user: Types.ObjectId | string;
  date: Date;
Lee Soobeom's avatar
Lee Soobeom committed
10
  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
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,
Yoon, Daeki's avatar
Yoon, Daeki committed
38
    default: 0,
Lee Soobeom's avatar
Lee Soobeom committed
39
  },
Kim, MinGyu's avatar
Kim, MinGyu committed
40
41
});

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