mainimg.db.ts 760 Bytes
Newer Older
Kim, MinGyu's avatar
Kim, MinGyu committed
1
import { ObjectId } from "mongoose";
Kim, MinGyu's avatar
Kim, MinGyu committed
2
import { FileInfo, IFileInfo, Mainimg, MainimgType } from "../models";
Kim, MinGyu's avatar
Kim, MinGyu committed
3

Kim, MinGyu's avatar
Kim, MinGyu committed
4
5
export const createMainimg = async (mainimg: MainimgType, pic: IFileInfo) => {
  const newPic = await FileInfo.create({
Kim, MinGyu's avatar
Kim, MinGyu committed
6
7
8
9
    originalfilename: pic.originalfilename,
    newfilename: pic.newfilename,
    pictureauth: pic.picturepath,
  });
백승민's avatar
백승민 committed
10
11
12
13

  const newMainimg = await Mainimg.create({
    theme: mainimg.theme,
    city: mainimg.city,
Kim, MinGyu's avatar
Kim, MinGyu committed
14
    pic: newPic._id,
백승민's avatar
백승민 committed
15
16
17
18
19
20
    title: mainimg.title,
  });
  return newMainimg;
};

export const getMainimg = async () => {
Kim, MinGyu's avatar
Kim, MinGyu committed
21
22
23
24
  const img = await Mainimg.find({}).populate("pic");

  return img;
};
백승민's avatar
백승민 committed
25
26
27
28
29

export const deleteOneMainimg = async (_id: string) => {
  const res = await Mainimg.deleteOne({ _id: _id });
  return res;
};