GIF89a
import { WriterMusicBookingModel } from "../../models/writerMusicBooking.mode.js";
import ApiError from "../../utils/ApiErrorHandler.js";
import ApiResponse from "../../utils/ApiRespinseHandler.js";
import AsyncHandler from "../../utils/AsyncHandler.js";
import User from '../../models/user.model.js'
export const createBooking = AsyncHandler(async (req, res) => {
const { artistId } = req.params;
if (!artistId){
throw new ApiError(400, 'Artist id missing in params');
}
const {
serviceType,
name,
contactNumber,
songCategory,
songType,
language,
} = req.body;
if (
!serviceType ||
!name ||
!contactNumber ||
!songCategory ||
!songType ||
!language
) {
throw new ApiError(400, "All fields are required");
}
const artist = await User.findOne({ authId: artistId });
if (!artist) {
throw new ApiError(404, "Artist not found");
}
const booking = await WriterMusicBookingModel.create({
artistId,
serviceType,
name,
contactNumber,
songCategory,
songType,
language,
});
return res.status(201).json(
new ApiResponse(
201,
"Booking submitted successfully",
booking
)
);
});
export const getBookings = AsyncHandler(async (req, res) => {
const bookings = await WriterMusicBookingModel.find()
.sort({ createdAt: -1 });
return res.status(200).json(
new ApiResponse(
200,
"Bookings fetched successfully",
bookings
)
);
});
export const getArtistBookings = AsyncHandler(async (req, res) => {
const { artistId } = req.params;
const bookings = await WriterMusicBookingModel.find({
artistId,
}).sort({ createdAt: -1 });
return res.status(200).json(
new ApiResponse(
200,
"Artist bookings fetched successfully",
bookings
)
);
});