Add .gitignore file and include image URLs for albums and artists
This commit is contained in:
parent
b8a5323689
commit
fc5abc0432
|
@ -0,0 +1 @@
|
||||||
|
node_modules/
|
|
@ -1,6 +1,6 @@
|
||||||
const Artist = require('../models/artist.model');
|
const Artist = require('../models/artist.model');
|
||||||
|
|
||||||
// Create Artist
|
|
||||||
const createArtist = async (req, res) => {
|
const createArtist = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { ArtistName } = req.body;
|
const { ArtistName } = req.body;
|
||||||
|
@ -18,23 +18,30 @@ const createArtist = async (req, res) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (req.file) {
|
if (req.file) {
|
||||||
|
const baseUrl = `${req.protocol}://${req.get('host')}`;
|
||||||
|
const imagePath = `uploads/${req.file.filename}`;
|
||||||
|
const imageUrl = `${baseUrl}/${imagePath}`;
|
||||||
|
console.log("🚀 ~ createArtist ~ imageUrl:", imageUrl);
|
||||||
|
|
||||||
obj["image"] = {
|
obj["image"] = {
|
||||||
fileName: req.file.filename,
|
fileName: req.file.filename,
|
||||||
fileAddress: req.file.path
|
fileAddress: req.file.path
|
||||||
};
|
};
|
||||||
|
obj["imageUrl"] = imageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save 'obj' to the database
|
// Save 'obj' to the database
|
||||||
const newArtist = await Artist.create(obj);
|
const newArtist = await Artist.create(obj);
|
||||||
|
console.log("🚀 ~ createArtist ~ newArtist:", newArtist);
|
||||||
|
|
||||||
// Return a success response with the newly created Artist
|
// Return a success response with the newly created Artist
|
||||||
return res.status(201).send({
|
return res.status(201).send({
|
||||||
error_code: 200,
|
error_code: 201,
|
||||||
message: "Artist created",
|
message: "Artist created",
|
||||||
Artist: newArtist
|
Artist: newArtist
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Error inside createArtist Controller", err);
|
console.error("Error inside createArtist Controller", err);
|
||||||
return res.status(500).send({
|
return res.status(500).send({
|
||||||
error_code: 500,
|
error_code: 500,
|
||||||
message: "Internal Server Error"
|
message: "Internal Server Error"
|
||||||
|
@ -42,30 +49,48 @@ const createArtist = async (req, res) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update Artist
|
|
||||||
const updateArtist = async (req, res) => {
|
const updateArtist = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const artistId = req.params.id;
|
const artistId = req.params.id;
|
||||||
const updates = req.body;
|
const { ArtistName } = req.body;
|
||||||
|
|
||||||
// Update artist by ID
|
if (!ArtistName) {
|
||||||
|
return res.status(400).send({
|
||||||
|
error_code: 400,
|
||||||
|
message: "Artist name is required"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const updates = { ArtistName };
|
||||||
|
|
||||||
|
if (req.file) {
|
||||||
|
const baseUrl = `${req.protocol}://${req.get('host')}`;
|
||||||
|
const imagePath = `uploads/${req.file.filename}`;
|
||||||
|
const imageUrl = `${baseUrl}/${imagePath}`;
|
||||||
|
console.log("🚀 ~ updateArtist ~ imageUrl:", imageUrl);
|
||||||
|
|
||||||
|
updates.image = {
|
||||||
|
fileName: req.file.filename,
|
||||||
|
fileAddress: req.file.path
|
||||||
|
};
|
||||||
|
updates.imageUrl = imageUrl;
|
||||||
|
}
|
||||||
const updatedArtist = await Artist.findByIdAndUpdate(artistId, updates, { new: true });
|
const updatedArtist = await Artist.findByIdAndUpdate(artistId, updates, { new: true });
|
||||||
|
|
||||||
// Check if the artist exists
|
|
||||||
if (!updatedArtist) {
|
if (!updatedArtist) {
|
||||||
return res.status(404).send({
|
return res.status(404).send({
|
||||||
error_code: 404,
|
error_code: 404,
|
||||||
message: "Artist not found"
|
message: "Artist not found"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
error_code: 200,
|
error_code: 200,
|
||||||
message: "Artist updated successfully",
|
message: "Artist updated successfully",
|
||||||
Artist: updatedArtist
|
Artist: updatedArtist
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Error inside updateArtist Controller", err);
|
console.error("Error inside updateArtist Controller", err);
|
||||||
return res.status(500).send({
|
return res.status(500).send({
|
||||||
error_code: 500,
|
error_code: 500,
|
||||||
message: "Internal Server Error"
|
message: "Internal Server Error"
|
||||||
|
@ -73,6 +98,7 @@ const updateArtist = async (req, res) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Delete Artist
|
// Delete Artist
|
||||||
const deleteArtist = async (req, res) => {
|
const deleteArtist = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -238,31 +238,33 @@ const updateAlbum = async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle image upload and update imageUrl
|
// Handle image upload and update imageUrl
|
||||||
let imageUrl = album.image ? album.image.imageUrl : undefined;
|
let imageUrl = album.imageUrl;
|
||||||
if (req.file) {
|
if (req.file) {
|
||||||
const baseUrl = `${req.protocol}://${req.get('host')}`;
|
const baseUrl = `${req.protocol}://${req.get('host')}`;
|
||||||
const imagePath = `uploads/${req.file.filename}`;
|
const imagePath = `uploads/${req.file.filename}`;
|
||||||
imageUrl = `${baseUrl}/${imagePath}`;
|
imageUrl = `${baseUrl}/${imagePath}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update album fields
|
// Update album object with all fields
|
||||||
album.categoryId = categoryId;
|
const updatedAlbum = {
|
||||||
album.subcategoryId = subcategoryId;
|
categoryId: categoryId,
|
||||||
album.albumName = albumName;
|
subcategoryId: subcategoryId,
|
||||||
album.shortDescription = shortDescription;
|
albumName: albumName,
|
||||||
album.imageUrl = imageUrl;
|
shortDescription: shortDescription,
|
||||||
album.image = req.file ? {
|
imageUrl: imageUrl,
|
||||||
|
image: req.file ? {
|
||||||
fileName: req.file.filename,
|
fileName: req.file.filename,
|
||||||
fileAddress: req.file.path,
|
fileAddress: req.file.path,
|
||||||
} : album.image;
|
} : album.image
|
||||||
|
};
|
||||||
|
|
||||||
// Save the updated album
|
// Save the updated album
|
||||||
await album.save();
|
await Album.findByIdAndUpdate(id, updatedAlbum);
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
error_code: 200,
|
error_code: 200,
|
||||||
message: "Album updated successfully",
|
message: "Album updated successfully",
|
||||||
album: album
|
album: updatedAlbum
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error inside UpdateAlbum Controller", err);
|
console.error("Error inside UpdateAlbum Controller", err);
|
||||||
|
@ -273,6 +275,7 @@ const updateAlbum = async (req, res) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
||||||
const deleteAlbum = async (req, res) => {
|
const deleteAlbum = async (req, res) => {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const SubCategories = require('../models/subcategories.model'); // Import SubCategories model
|
const SubCategories = require('../models/subcategories.model'); // Import SubCategories model
|
||||||
const Categories = require('../models/categories.model')
|
const Categories = require('../models/categories.model');
|
||||||
|
const Artist = require('../models/artist.model');
|
||||||
|
|
||||||
// const createsubCategories = async (req, res) => {
|
// const createsubCategories = async (req, res) => {
|
||||||
// try {
|
// try {
|
||||||
|
@ -207,7 +208,7 @@ const updateSubCategories = async (req, res) => {
|
||||||
|
|
||||||
const deleteMany = async (req, res) => {
|
const deleteMany = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const deleted = await SubCategories.deleteMany({}); // Passing an empty filter object deletes all documents
|
const deleted = await Artist.deleteMany({}); // Passing an empty filter object deletes all documents
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
error_code: 200,
|
error_code: 200,
|
||||||
message: 'All categories deleted successfully',
|
message: 'All categories deleted successfully',
|
||||||
|
|
|
@ -11,6 +11,7 @@ const artistSchema = new mongoose.Schema({
|
||||||
fileName: String,
|
fileName: String,
|
||||||
fileAddress: String
|
fileAddress: String
|
||||||
},
|
},
|
||||||
|
imageUrl: { type: String },
|
||||||
status: {
|
status: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: ['activate', 'deactivate'],
|
enum: ['activate', 'deactivate'],
|
||||||
|
|
Loading…
Reference in New Issue