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');
|
||||
|
||||
// Create Artist
|
||||
|
||||
const createArtist = async (req, res) => {
|
||||
try {
|
||||
const { ArtistName } = req.body;
|
||||
|
@ -18,23 +18,30 @@ const createArtist = async (req, res) => {
|
|||
};
|
||||
|
||||
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"] = {
|
||||
fileName: req.file.filename,
|
||||
fileAddress: req.file.path
|
||||
};
|
||||
obj["imageUrl"] = imageUrl;
|
||||
}
|
||||
|
||||
// Save 'obj' to the database
|
||||
const newArtist = await Artist.create(obj);
|
||||
console.log("🚀 ~ createArtist ~ newArtist:", newArtist);
|
||||
|
||||
// Return a success response with the newly created Artist
|
||||
return res.status(201).send({
|
||||
error_code: 200,
|
||||
error_code: 201,
|
||||
message: "Artist created",
|
||||
Artist: newArtist
|
||||
});
|
||||
} catch (err) {
|
||||
console.log("Error inside createArtist Controller", err);
|
||||
console.error("Error inside createArtist Controller", err);
|
||||
return res.status(500).send({
|
||||
error_code: 500,
|
||||
message: "Internal Server Error"
|
||||
|
@ -42,30 +49,48 @@ const createArtist = async (req, res) => {
|
|||
}
|
||||
};
|
||||
|
||||
// Update Artist
|
||||
|
||||
const updateArtist = async (req, res) => {
|
||||
try {
|
||||
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 });
|
||||
|
||||
// Check if the artist exists
|
||||
if (!updatedArtist) {
|
||||
return res.status(404).send({
|
||||
error_code: 404,
|
||||
message: "Artist not found"
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(200).send({
|
||||
error_code: 200,
|
||||
message: "Artist updated successfully",
|
||||
Artist: updatedArtist
|
||||
});
|
||||
} catch (err) {
|
||||
console.log("Error inside updateArtist Controller", err);
|
||||
console.error("Error inside updateArtist Controller", err);
|
||||
return res.status(500).send({
|
||||
error_code: 500,
|
||||
message: "Internal Server Error"
|
||||
|
@ -73,6 +98,7 @@ const updateArtist = async (req, res) => {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
// Delete Artist
|
||||
const deleteArtist = async (req, res) => {
|
||||
try {
|
||||
|
@ -139,27 +165,27 @@ const changeArtistStatus = async (req, res) => {
|
|||
const { id } = req.params;
|
||||
const artistData = await Artist.findById(id);
|
||||
if (!artistData) {
|
||||
return res.status(400).send({
|
||||
error_code: 400,
|
||||
message: 'Ads not found'
|
||||
});
|
||||
return res.status(400).send({
|
||||
error_code: 400,
|
||||
message: 'Ads not found'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
artistData.status = artistData.status === 'activate' ? 'deactivate' : 'activate';
|
||||
|
||||
|
||||
await artistData.save();
|
||||
res.status(200).send({
|
||||
message: `ads status toggled successfully to ${artistData.status}`,
|
||||
artistData: artistData
|
||||
message: `ads status toggled successfully to ${artistData.status}`,
|
||||
artistData: artistData
|
||||
});
|
||||
} catch (err) {
|
||||
} catch (err) {
|
||||
console.error('Error inside update ', err);
|
||||
res.status(500).send({
|
||||
error_code: 500,
|
||||
message: 'Internal Server Error'
|
||||
|
||||
error_code: 500,
|
||||
message: 'Internal Server Error'
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const getAllArtist = async (req, res) => {
|
||||
|
@ -179,7 +205,7 @@ const getAllArtist = async (req, res) => {
|
|||
}
|
||||
|
||||
const artists = await artistsQuery.skip(skip).limit(limit);
|
||||
|
||||
|
||||
// Count total number of artists for pagination
|
||||
const totalCount = await Artist.countDocuments(artistsQuery.getQuery());
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ const createAlbum = async (req, res) => {
|
|||
subcategoryId: subcategoryId,
|
||||
albumName,
|
||||
shortDescription,
|
||||
imageUrl:imageUrl,
|
||||
imageUrl: imageUrl,
|
||||
image: {
|
||||
fileName: req.file.filename,
|
||||
fileAddress: req.file.path,
|
||||
|
@ -48,9 +48,9 @@ const createAlbum = async (req, res) => {
|
|||
};
|
||||
const deletMany = async (req, res) => {
|
||||
try {
|
||||
|
||||
|
||||
const albums = await Album.deleteMany({ });
|
||||
|
||||
const albums = await Album.deleteMany({});
|
||||
console.log("<22><><EFBFBD> ~ deletMany ~ albums:", albums);
|
||||
|
||||
return res.status(200).json({ error_code: 200, message: "Albums deleted successfully", albums: albums });
|
||||
|
@ -238,31 +238,33 @@ const updateAlbum = async (req, res) => {
|
|||
}
|
||||
|
||||
// Handle image upload and update imageUrl
|
||||
let imageUrl = album.image ? album.image.imageUrl : undefined;
|
||||
let imageUrl = album.imageUrl;
|
||||
if (req.file) {
|
||||
const baseUrl = `${req.protocol}://${req.get('host')}`;
|
||||
const imagePath = `uploads/${req.file.filename}`;
|
||||
imageUrl = `${baseUrl}/${imagePath}`;
|
||||
}
|
||||
|
||||
// Update album fields
|
||||
album.categoryId = categoryId;
|
||||
album.subcategoryId = subcategoryId;
|
||||
album.albumName = albumName;
|
||||
album.shortDescription = shortDescription;
|
||||
album.imageUrl = imageUrl;
|
||||
album.image = req.file ? {
|
||||
fileName: req.file.filename,
|
||||
fileAddress: req.file.path,
|
||||
} : album.image;
|
||||
// Update album object with all fields
|
||||
const updatedAlbum = {
|
||||
categoryId: categoryId,
|
||||
subcategoryId: subcategoryId,
|
||||
albumName: albumName,
|
||||
shortDescription: shortDescription,
|
||||
imageUrl: imageUrl,
|
||||
image: req.file ? {
|
||||
fileName: req.file.filename,
|
||||
fileAddress: req.file.path,
|
||||
} : album.image
|
||||
};
|
||||
|
||||
// Save the updated album
|
||||
await album.save();
|
||||
await Album.findByIdAndUpdate(id, updatedAlbum);
|
||||
|
||||
return res.status(200).json({
|
||||
error_code: 200,
|
||||
message: "Album updated successfully",
|
||||
album: album
|
||||
album: updatedAlbum
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Error inside UpdateAlbum Controller", err);
|
||||
|
@ -273,6 +275,7 @@ const updateAlbum = async (req, res) => {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
const deleteAlbum = async (req, res) => {
|
||||
|
@ -364,7 +367,7 @@ const getAlbums = async (req, res) => {
|
|||
_id: album._id,
|
||||
status: album.status,
|
||||
image: album.image,
|
||||
imageUrl:album.imageUrl,
|
||||
imageUrl: album.imageUrl,
|
||||
albumName: album.albumName,
|
||||
shortDescription: album.shortDescription,
|
||||
category: album.categoryId ? album.categoryId.name : null,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
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) => {
|
||||
// try {
|
||||
|
@ -207,7 +208,7 @@ const updateSubCategories = async (req, res) => {
|
|||
|
||||
const deleteMany = async (req, res) => {
|
||||
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({
|
||||
error_code: 200,
|
||||
message: 'All categories deleted successfully',
|
||||
|
|
|
@ -11,6 +11,7 @@ const artistSchema = new mongoose.Schema({
|
|||
fileName: String,
|
||||
fileAddress: String
|
||||
},
|
||||
imageUrl: { type: String },
|
||||
status: {
|
||||
type: String,
|
||||
enum: ['activate', 'deactivate'],
|
||||
|
|
Loading…
Reference in New Issue