Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/controllers/books/bookController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import User from "../../models/User.js";
import cloudinary from "../../utils/cloudinary.js";
import logger from "../../config/logger.js";
import { validateMagicBytes } from "../../utils/fileValidation.js";
import { createNewBookNotification } from "../notificationController.js";

//cretae a book
export const createBook = async (req, res) => {
Expand Down Expand Up @@ -73,6 +74,11 @@ export const createBook = async (req, res) => {
filePublicId: fileUpload.public_id,
});

// Emit new book notification asynchronously to followers
createNewBookNotification(book._id, req.user._id, book.title).catch((err) =>
logger.error("Error creating book notification:", err)
);

res.status(201).json({ success: true, book });
} catch (err) {
logger.error("Book creation error:", err);
Expand Down
6 changes: 6 additions & 0 deletions src/controllers/courses/courseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import mongoose from "mongoose";
import logger from "../../config/logger.js";
import { catchAsync, APIError } from "../../middlewares/errorHandler.js";
import { getCacheOrSet, CACHE_TTL, CACHE_KEYS } from "../../utils/cache.js";
import { createNewCourseNotification } from "../notificationController.js";

/**
* Create a new course
Expand Down Expand Up @@ -34,6 +35,11 @@ export const createCourse = catchAsync(async (req, res, next) => {

logger.info(`✅ Course created successfully: ${course._id} - ${title}`);

// Emit new course notification asynchronously to followers
createNewCourseNotification(course._id, req.user._id, course.title).catch((err) =>
logger.error("Error creating course notification:", err)
);

res.status(201).json({
success: true,
message: "Course created successfully",
Expand Down
Loading
Loading