-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: admin to upload Media for Mobile App
- Loading branch information
1 parent
56a99ce
commit e048cbe
Showing
7 changed files
with
59 additions
and
28 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 |
---|---|---|
@@ -1,24 +1,45 @@ | ||
const Media = require("../models/mediaModel"); | ||
const { internalServerError } = require("../utils/errorHandler"); | ||
const { internalServerError, handleError } = require("../utils/errorHandler"); | ||
|
||
const uploadMedia = async (request, response) => { | ||
const { title, description, duration, url } = request.body; | ||
const { mediaUrl, title } = request.body; | ||
|
||
try { | ||
|
||
// check if the required fields are being sent | ||
|
||
|
||
|
||
if (!mediaUrl) { | ||
return response | ||
.status(422) | ||
.json( | ||
handleError( | ||
422, | ||
"Media URL is Required", | ||
"the client did not send the media url" | ||
) | ||
); | ||
} | ||
|
||
await Media.create({ mediaUrl, title }); | ||
|
||
response | ||
.status(200) | ||
.json({ status: true, message: "Media Uploaded Successfully" }); | ||
} catch (error) { | ||
console.log(error); | ||
response.status(500).json(internalServerError(error)); | ||
} | ||
}; | ||
|
||
const getAllMedia = async (request, response) => { | ||
try { | ||
const videos = await Media.find().sort({ createdAt: -1 }); | ||
|
||
|
||
response.status(200).json({ status: true, videos }); | ||
} catch (error) { | ||
console.log(error); | ||
response.status(500).json(internalServerError(error)); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
uploadMedia | ||
} | ||
uploadMedia, | ||
getAllMedia, | ||
}; |
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
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
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,12 @@ | ||
const express = require("express"); | ||
const authenticateAdmin = require("../../middlewares/adminAuthMiddleware"); | ||
const { | ||
uploadMedia, | ||
getAllMedia, | ||
} = require("../../controllers/mediaController"); | ||
const router = express.Router(); | ||
|
||
router.post("/upload", authenticateAdmin, uploadMedia); | ||
router.post("/get/all", authenticateAdmin, getAllMedia); | ||
|
||
module.exports = router; |