post.db.ts 763 Bytes
Newer Older
Lee Soobeom's avatar
Lee Soobeom committed
1
import { Post, PostType } from "../models";
Lee Soobeom's avatar
Lee Soobeom committed
2

Lee Soobeom's avatar
Lee Soobeom committed
3
4
5
6
7
8
9
10
export const createPost = async (post: PostType) => {
  const newPosting = await Post.create({
    title: post.title,
    text: post.text,
    theme: post.theme,
    city: post.city,
    user: post.user,
    date: post.date,
Lee Soobeom's avatar
Lee Soobeom committed
11
    counts: 0,
Lee Soobeom's avatar
Lee Soobeom committed
12
13
14
  });
  return newPosting;
};
Lee Soobeom's avatar
Lee Soobeom committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

export const getPosts = async () => {
  const posts = await Post.find({});
  return posts;
};

export const addOneCount = async (_id: string, counts: number) => {
  const newCounts = await Post.findOneAndUpdate(
    { _id: _id },
    { counts: counts },
    { new: true }
  );

  // console.log(newCounts);

  return newCounts;
};

export const getPost = async (_id: string) => {
  const post = await Post.findOne({ _id: _id });
  return post;
};