34 lines
1010 B
JavaScript
34 lines
1010 B
JavaScript
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 };
|
|
|