Initial commit
This commit is contained in:
33
server/controllers/socialMediaController.js
Normal file
33
server/controllers/socialMediaController.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const SocialMedia = require('../models/SocialMedia');
|
||||
const { successResponse, errorResponse } = require('../utils/apiResponse');
|
||||
|
||||
const getSocialMedia = async (req, res, next) => {
|
||||
try {
|
||||
const socialLinks = await SocialMedia.find({ isEnabled: true });
|
||||
return successResponse(res, 'Social media links retrieved', socialLinks);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
const updateSocialMedia = async (req, res, next) => {
|
||||
try {
|
||||
const { links } = req.body; // Array of { platform, url, isEnabled }
|
||||
if (Array.isArray(links)) {
|
||||
for (const link of links) {
|
||||
await SocialMedia.findOneAndUpdate(
|
||||
{ platform: link.platform },
|
||||
{ url: link.url, isEnabled: link.isEnabled },
|
||||
{ upsert: true, new: true }
|
||||
);
|
||||
}
|
||||
}
|
||||
const updated = await SocialMedia.find({});
|
||||
return successResponse(res, 'Social media accounts updated', updated);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { getSocialMedia, updateSocialMedia };
|
||||
|
||||
Reference in New Issue
Block a user