-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #490 from AyushSharma72/addshows
added add shows api
- Loading branch information
Showing
4 changed files
with
288 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const ShowsModal = require("../models/Shows"); | ||
|
||
const express = require("express"); | ||
const router = express.Router(); | ||
|
||
router.post("/Addshows", async function AddShow(req, resp) { | ||
try { | ||
const { title, description, venue, startDate, endDate, email, website } = | ||
req.body; | ||
if ( | ||
!title || | ||
!description || | ||
!venue || | ||
!startDate || | ||
!endDate || | ||
!email || | ||
!website | ||
) { | ||
return resp.status(400).send({ | ||
message: "All fields are required", | ||
}); | ||
} | ||
|
||
const newShow = new ShowsModal({ | ||
title, | ||
description, | ||
venue, | ||
startDate, | ||
endDate, | ||
email, | ||
website, | ||
}); | ||
|
||
const savedShow = await newShow.save(); | ||
|
||
resp.status(201).send({ | ||
message: "Show added successfully", | ||
data: savedShow, | ||
}); | ||
} catch (error) { | ||
resp.status(500).send({ | ||
message: "An error occurred while adding the show", | ||
error: error.message, | ||
}); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const mongoose = require("mongoose"); | ||
|
||
const ShowsSchema = mongoose.Schema( | ||
{ | ||
title: { | ||
type: String, | ||
required: true, | ||
}, | ||
description: { | ||
type: String, | ||
required: true, | ||
}, | ||
venue: { | ||
type: String, | ||
required: true, | ||
}, | ||
startDate: { | ||
type: Date, | ||
required: true, | ||
}, | ||
endDate: { | ||
type: Date, | ||
required: true, | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
}, | ||
website: { | ||
type: String, | ||
}, | ||
}, | ||
{ timestamps: true } | ||
); | ||
|
||
module.exports = mongoose.model("shows", ShowsSchema); |
Oops, something went wrong.