post.model.ts 786 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;
Lee Soobeom's avatar
Lee Soobeom committed
8
  date: Date | number;
Lee Soobeom's avatar
Lee Soobeom committed
9
  counts?: number;
Lee Soobeom's avatar
Lee Soobeom committed
10
  user?: Types.ObjectId | string;
Lee Soobeom's avatar
Lee Soobeom committed
11
  file?: Array<Types.ObjectId>;
Lee Soobeom's avatar
.    
Lee Soobeom committed
12
13
}

Lee Soobeom's avatar
Lee Soobeom committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
35
    default: Date.now(),
Lee Soobeom's avatar
Lee Soobeom committed
36
37
38
  },
  counts: {
    type: Number,
Yoon, Daeki's avatar
Yoon, Daeki committed
39
    default: 0,
Lee Soobeom's avatar
Lee Soobeom committed
40
  },
Lee Soobeom's avatar
Lee Soobeom committed
41
42
43
44
45
46
  file: [
    {
      type: Schema.Types.ObjectId,
      ref: "FileInfo",
    },
  ],
Kim, MinGyu's avatar
Kim, MinGyu committed
47
48
});

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