post.model.ts 667 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
  user: Types.ObjectId | string;
Lee Soobeom's avatar
Lee Soobeom committed
9
  date: Date | number;
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
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,
Lee Soobeom's avatar
Lee Soobeom committed
34
    default: Date.now(),
Lee Soobeom's avatar
Lee Soobeom committed
35
36
37
  },
  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);