/routes/goods.js
import express from 'express';
const router = express.Router();
import mongoose from 'mongoose';
import Goods from '../schemas/goods.js';
router.post('/goods', async(req, res)=>{
const {goodsId, name, thumbnailUrl, category, price} = req.body;
const goods = await Goods.find({goodsId: goodsId}).exec();
if(goods.length){
return res.status(400).json({errorMessage: '이미 존재하는 데이터입니다.'});
}
const createdGoods = await Goods.create({
goodsId: goodsId,
name: name,
thumbnailUrl: thumbnailUrl,
category: category,
price: price,
});
return res.status(201).json({goods: createdGoods});
});
export default router;