tutorial api creation and project changes
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import * as express from "express";
|
||||
import { recentDataController, searchProjectController, searchTrashProjectController } from "../controller/home/homeControllers.ts";
|
||||
import { searchTrashProject } from "../../shared/services/home/homeService.ts";
|
||||
import { tutorialsDataController } from "../controller/home/tutorialControllers.ts";
|
||||
|
||||
const homePageRouter = express.Router();
|
||||
|
||||
homePageRouter.get("/RecentlyViewed/:userId/:organization", recentDataController);
|
||||
homePageRouter.get("/searchProjects", searchProjectController);
|
||||
homePageRouter.get("/searchTrashProjects", searchTrashProjectController);
|
||||
homePageRouter.get("/tutorials", tutorialsDataController);
|
||||
export default homePageRouter;
|
||||
|
||||
37
src/api-server/controller/home/tutorialControllers.ts
Normal file
37
src/api-server/controller/home/tutorialControllers.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { getTutorials } from "../../../shared/services/home/tutorialsService.ts";
|
||||
import { Request, Response } from "express";
|
||||
|
||||
export const tutorialsDataController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization = "tutorials" } = req.body;
|
||||
if (!organization) {
|
||||
res.status(400).json({
|
||||
message: "Organization is required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const result = await getTutorials({ organization });
|
||||
|
||||
switch (result?.status) {
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
tutorials: result.data,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
20
src/shared/services/home/tutorialsService.ts
Normal file
20
src/shared/services/home/tutorialsService.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import projectModel from '../../model/project/project-model.ts';
|
||||
|
||||
|
||||
interface GetTutorials {
|
||||
organization: string;
|
||||
}
|
||||
|
||||
export const getTutorials = async (data: GetTutorials) => {
|
||||
try {
|
||||
const { organization } = data;
|
||||
|
||||
const tutorials = await projectModel(organization).find()
|
||||
.select("_id projectName createdBy thumbnail createdAt projectUuid createdAt");
|
||||
|
||||
return { status: 'Success', data: tutorials };
|
||||
} catch (err) {
|
||||
console.error('Error fetching data:', err);
|
||||
return { status: 'Error' };
|
||||
}
|
||||
};
|
||||
@@ -102,7 +102,7 @@ export const GetAllProjects = async (data: GetProjectsInterface) => {
|
||||
createdBy:userId,
|
||||
isArchive: false,
|
||||
})
|
||||
.select("_id projectName createdBy thumbnail createdAt projectUuid");
|
||||
.select("_id projectName createdBy thumbnail createdAt projectUuid createdAt");
|
||||
if (projectDatas) return { status: "Success", Datas: projectDatas };
|
||||
} catch (error: unknown) {
|
||||
return { status: error };
|
||||
@@ -149,7 +149,7 @@ export const updateProject = async (data: updateProjectInput) => {
|
||||
{ projectName: projectName, thumbnail: thumbnail },
|
||||
{ new: true }
|
||||
)
|
||||
.select("_id projectName createdBy thumbnail createdAt");
|
||||
.select("_id projectName createdBy thumbnail createdAt projectUuid");
|
||||
if (updateProject) return { status: "Success", data: updateProject };
|
||||
} catch (error: unknown) {
|
||||
return { status: error };
|
||||
|
||||
@@ -5,8 +5,6 @@ import { emitEventResponse, emitToSenderAndAdmins, } from "../../utils/emitEvent
|
||||
|
||||
export const projectHandleEvent = async ( event: string,socket: Socket,io:Server,data: any, connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] }, callback?: Function
|
||||
) => {
|
||||
console.log('event: ', event);
|
||||
console.log('data:controller ', data);
|
||||
if (event !== EVENTS.addProject || !data?.organization) return;
|
||||
const requiredFields = ["projectUuid", "userId", "thumbnail", "organization"];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
@@ -59,7 +57,6 @@ export const projectDeleteHandleEvent = async (
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
console.log('event: ', event);
|
||||
if (event !== EVENTS.deleteProject || !data?.organization) return;
|
||||
const requiredFields = ["projectId", "userId", "organization"];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
@@ -77,7 +74,6 @@ export const projectDeleteHandleEvent = async (
|
||||
return;
|
||||
}
|
||||
const result = await DeleteProject(data);
|
||||
console.log('result: ', result);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string }> = {
|
||||
@@ -116,7 +112,6 @@ export const projecUpdateHandleEvent = async (
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
console.log('data:update ', data);
|
||||
if (event !== EVENTS.ProjectUpdate || !data?.organization) return;
|
||||
const requiredFields = ["projectId", "userId", "organization"];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
@@ -145,6 +140,13 @@ export const projecUpdateHandleEvent = async (
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const projectDeleteDatas =
|
||||
status === "Success" && result?.data
|
||||
? {
|
||||
projectUuid: result.data.projectUuid,
|
||||
projectName: result.data.projectName,
|
||||
thumbnail: result.data.thumbnail,
|
||||
projectId: result.data._id,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
|
||||
const response = {
|
||||
@@ -158,6 +160,5 @@ export const projecUpdateHandleEvent = async (
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.projectUpdateResponse, response, connectedUsersByOrg)
|
||||
console.log('response: ', response);
|
||||
|
||||
}
|
||||
@@ -1103,7 +1103,7 @@ export const initSocketServer = (httpServer: any) => {
|
||||
// const organization = socket.handshake.query.organization as string;
|
||||
// const email = socket.handshake.query.email as string;
|
||||
const { organization, email, userId } = socket.handshake.auth
|
||||
console.log(' socket.handshake.auth: ', socket.handshake.auth);
|
||||
// console.log(' socket.handshake.auth: ', socket.handshake.auth);
|
||||
|
||||
if (organization) {
|
||||
socket.join(organization);
|
||||
@@ -1119,7 +1119,7 @@ export const initSocketServer = (httpServer: any) => {
|
||||
}
|
||||
|
||||
const role = await getUserRole(userId, organization);
|
||||
console.log('role: ', role);
|
||||
// console.log('role: ', role);
|
||||
if (role === "Admin") {
|
||||
socket.join(`${organization}_admins`);
|
||||
}
|
||||
@@ -1138,7 +1138,7 @@ export const initSocketServer = (httpServer: any) => {
|
||||
// console.log(`🔗 User connected: ${userId} with role ${role} in ${organization}`);
|
||||
// console.log("🧩 connectedUsersByOrg: ", connectedUsersByOrg);
|
||||
} else {
|
||||
console.warn(`❌ Cannot store user. Missing data:`,);
|
||||
// console.warn(`❌ Cannot store user. Missing data:`,);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ export const emitToSenderAndAdmins = (
|
||||
result: EmitOptions,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] }
|
||||
) => {
|
||||
console.log('result.data,: ', result.data,);
|
||||
// Emit to sender directly
|
||||
socket.emit(event, {
|
||||
message: result.message,
|
||||
|
||||
@@ -4,8 +4,6 @@ import userModel from "../../shared/model/user-Model.ts";
|
||||
|
||||
|
||||
export async function getUserRole(userId: string, organization: string): Promise<string> {
|
||||
console.log('userId: ', userId);
|
||||
const user = await userModel(organization).findOne({ _id: userId });
|
||||
console.log('user: ', user);
|
||||
return user?.role || "User"; // default to 'user' if no role found
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user