mainimg.controller.ts 1013 Bytes
Newer Older
백승민's avatar
백승민 committed
1
2
3
4
5
6
7
8
9
10
11
12
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
39
40
41
42
43
import isLength from "validator/lib/isLength";
import { TypedRequestAuth } from "./auth.controller";
import { asyncWrap } from "../helpers";
import { mainimgDb } from "../db";

export const createMainimg = asyncWrap(async (reqExp, res, next) => {
  const req = reqExp as TypedRequestAuth<{ userId: string }>;

  const { theme, city, url, title} = req.body as {
    theme: string;
    city: string;
    url: string;
    title: string;
  };

  console.log("body", req.body);

    if (!isLength(url ?? "", { min: 1 })) {
      return res.status(422).send("이미지 url을 입력해주세요");
    }
 
  if (!isLength(title ?? "", { min: 1 })) {
    return res.status(422).send("이미지 제목을 입력해주세요");
  }

  const newMainimg = await mainimgDb.createMainimg({
    theme,
    city,
    url,
    title,
  });

  return res.json(newMainimg);
});

export const getMainimg = asyncWrap(async (req, res) => {
    const mainimgs = await mainimgDb.getMainimg();
    return res.json(mainimgs);
  });