GIF89a
import { SongRequestForm } from "../../models/songRequestForm.model.js";
import ApiError from "../../utils/ApiErrorHandler.js";
import ApiResponse from "../../utils/ApiRespinseHandler.js";
import AsyncHandler from "../../utils/AsyncHandler.js";
export const createSongRequest = AsyncHandler(async (req, res) => {
const { name, contact, songCategory, language } = req.body;
const songRequest = await SongRequestForm.create({
name,
contact,
songCategory: songCategory?.toUpperCase(),
language
});
res.status(201).json(
new ApiResponse(
201,
"Song request created successfully",
songRequest
)
);
});
export const getSongRequests = AsyncHandler(async (req, res) => {
const requests = await SongRequestForm.find().sort({ createdAt: -1 });
res.status(200).json(
new ApiResponse(
200,
"Song requests fetched successfully",
requests
)
);
});
export const updateSongRequest = AsyncHandler(async (req, res) => {
const { id } = req.params;
const { name, contact, songCategory } = req.body;
const request = await SongRequestForm.findById(id);
if (!request) {
throw new ApiError(404, "Song request not found");
}
if (name !== undefined) request.name = name;
if (contact !== undefined) request.contact = contact;
if (songCategory !== undefined) {
request.songCategory = songCategory.toUpperCase();
}
await request.save();
res.status(200).json(
new ApiResponse(
200,
"Song request updated successfully",
request
)
);
});
export const deleteSongRequest = AsyncHandler(async (req, res) => {
const { id } = req.params;
const request = await SongRequestForm.findById(id);
if (!request) {
throw new ApiError(404, "Song request not found");
}
await SongRequestForm.findByIdAndDelete(id);
res.status(200).json(
new ApiResponse(
200,
"Song request deleted successfully",
{}
)
);
});