wallitems update and project model creation
This commit is contained in:
6
src/api-server/Routes/projectRoutes.ts
Normal file
6
src/api-server/Routes/projectRoutes.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import * as express from "express";
|
||||
import { createProjectController } from "../controller/project/projectController.ts";
|
||||
|
||||
const projectRouter = express.Router();
|
||||
projectRouter.post("/upsertProject",createProjectController)
|
||||
export default projectRouter
|
||||
@@ -19,6 +19,7 @@ import floadWidgetRoutes from "./Routes/floadWidgetRoute.ts";
|
||||
import templateRoutes from "./Routes/templateRoutes.ts";
|
||||
import widget3dRoutes from "./Routes/widget3dRoutes.ts";
|
||||
import productRouter from "./Routes/productRoutes.ts";
|
||||
import projectRouter from "./Routes/projectRoutes.ts";
|
||||
// import productFlowRoutes from "./Routes/productFlowRouts.ts";
|
||||
|
||||
const app = express();
|
||||
@@ -80,4 +81,5 @@ app.use("/api/v2", templateRoutes);
|
||||
app.use("/api/v2", widget3dRoutes);
|
||||
app.use("/api/v2", productRouter);
|
||||
// app.use("/api/v2", productFlowRoutes);
|
||||
app.use("/api/v1",projectRouter)
|
||||
export default app;
|
||||
|
||||
46
src/api-server/controller/project/projectController.ts
Normal file
46
src/api-server/controller/project/projectController.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Request, Response } from "express";
|
||||
import { createProject } from "../../../shared/services/project/project-Serivices.ts";
|
||||
|
||||
export const createProjectController = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const result = await createProject(req.body);
|
||||
console.log("result:", result);
|
||||
|
||||
switch (result.status) {
|
||||
case "project_exists":
|
||||
res.status(409).json({
|
||||
success: false,
|
||||
message: "Project already exists",
|
||||
});
|
||||
break;
|
||||
|
||||
case "user_not_found":
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
|
||||
case "success":
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
message: "Project created successfully",
|
||||
data: result.project,
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error in controller:", error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Internal server error",
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -4,6 +4,7 @@ import MainModel from '../../connect/mongoose.ts';
|
||||
export interface wallitems extends Document {
|
||||
modelUuid: string;
|
||||
modelName: string
|
||||
modelfileID: string;
|
||||
type: string
|
||||
csgposition: []
|
||||
csgscale: []
|
||||
@@ -16,7 +17,8 @@ export interface wallitems extends Document {
|
||||
|
||||
// Define the Mongoose Schema
|
||||
const wallItemsSchema: Schema = new Schema({
|
||||
modelUuid: { type: String,unique:true },
|
||||
modelUuid: { type: String},
|
||||
modelfileID: { type: String},
|
||||
modelName: { type: String},
|
||||
type: { type: String },
|
||||
csgposition: { type: Array},
|
||||
|
||||
29
src/shared/model/project/project-model.ts
Normal file
29
src/shared/model/project/project-model.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Schema, Document, Types } from "mongoose";
|
||||
import MainModel from "../../connect/mongoose.ts";
|
||||
import {User} from "../user-Model.ts";
|
||||
|
||||
export interface Project extends Document {
|
||||
projectUuid: string;
|
||||
projectName: string;
|
||||
createdBy: User["_id"];
|
||||
isArchive: boolean
|
||||
thumbnail: string
|
||||
sharedUsers: []
|
||||
|
||||
}
|
||||
const projectSchema:Schema = new Schema({
|
||||
projectUuid: { type: String, required: true },
|
||||
projectName: { type: String },
|
||||
thumbnail: { type: String },
|
||||
isArchive: { type: Boolean,default:false },
|
||||
createdBy: { type: Schema.Types.ObjectId, ref: "user" },
|
||||
sharedUsers: [{ type: Schema.Types.ObjectId, ref: "user" }],
|
||||
|
||||
|
||||
}, { timestamps: true })
|
||||
|
||||
const projectModel = (db: string) => {
|
||||
return MainModel(db, "Projects", projectSchema, "Projects");
|
||||
};
|
||||
|
||||
export default projectModel;
|
||||
80
src/shared/services/project/project-Serivices.ts
Normal file
80
src/shared/services/project/project-Serivices.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import projectModel from "../../model/project/project-model.ts";
|
||||
import userModel from "../../model/user-Model.ts";
|
||||
import { Types } from 'mongoose';
|
||||
interface CreateProjectInput {
|
||||
projectName: string;
|
||||
projectUuid: string;
|
||||
createdBy: string; // user ID
|
||||
thumbnail?: string;
|
||||
sharedUsers?: string[];
|
||||
organization:string
|
||||
}
|
||||
|
||||
export const createProject = async (data: CreateProjectInput) => {
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
const{projectName,projectUuid,createdBy,thumbnail,sharedUsers,organization}=data
|
||||
console.log('createdBy: ', typeof createdBy);
|
||||
const userExisting =await existingUser(createdBy,organization)
|
||||
if (!userExisting)
|
||||
{
|
||||
return {
|
||||
status: "user_not_found",
|
||||
};
|
||||
|
||||
}
|
||||
const projectExisting = await existingProject(projectUuid, organization);
|
||||
console.log('projectExisting: ', projectExisting);
|
||||
|
||||
if (projectExisting) {
|
||||
return {
|
||||
status: "project_exists",
|
||||
project: projectExisting,
|
||||
};
|
||||
}
|
||||
|
||||
const project = await projectModel(organization).create({
|
||||
projectName: projectName,
|
||||
projectUuid: projectUuid,
|
||||
createdBy: createdBy,
|
||||
thumbnail: thumbnail || "",
|
||||
sharedUsers: sharedUsers || [],
|
||||
isArchive: false,
|
||||
});
|
||||
return {
|
||||
status: "success",
|
||||
project: project,
|
||||
};
|
||||
} catch (error) {
|
||||
console.log('error: ', error);
|
||||
return {
|
||||
exists: false,
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export const existingProject = async (projectUuid: string,organization:string) => {
|
||||
console.log("projectUuid",typeof projectUuid);
|
||||
const projectData= await projectModel(organization).findOne({projectUuid:projectUuid,isArchive:false})
|
||||
console.log('projectData: ', projectData);
|
||||
return projectData
|
||||
};
|
||||
|
||||
export const existingUser = async (createdBy: string, organization: string) => {
|
||||
console.log('createdBy: ', typeof createdBy);
|
||||
if (!Types.ObjectId.isValid(createdBy)) {
|
||||
console.log('Invalid ObjectId format');
|
||||
return null;
|
||||
}
|
||||
const userData = await userModel(organization).findOne({
|
||||
_id: createdBy,
|
||||
});
|
||||
console.log('userData:', userData);
|
||||
return userData; // ✅ Make sure you return it
|
||||
};
|
||||
|
||||
|
||||
export const archiveProject = async (projectId: string,organization:string) => {
|
||||
return await projectModel(organization).findByIdAndUpdate(projectId, { isArchive: true }, { new: true });
|
||||
};
|
||||
@@ -4,7 +4,7 @@ import wallItenmModel from "../../../shared/model/assets/wallitems-Model.ts";
|
||||
|
||||
export const setWallItems = async (data: any) => {
|
||||
try {
|
||||
const { modelUuid, modelName, position, type, csgposition, csgscale, quaternion, scale, organization } = data
|
||||
const { modelUuid,modelfileID, modelName, position, type, csgposition, csgscale, quaternion, scale, organization } = data
|
||||
|
||||
|
||||
const findvalue = await wallItenmModel(organization).findOne({ modelUuid: modelUuid })
|
||||
@@ -28,7 +28,7 @@ export const setWallItems = async (data: any) => {
|
||||
|
||||
} else {
|
||||
|
||||
const newValue = await wallItenmModel(organization).create({ modelUuid, modelName, position, type, csgposition, csgscale, quaternion, scale });
|
||||
const newValue = await wallItenmModel(organization).create({ modelUuid,modelfileID, modelName, position, type, csgposition, csgscale, quaternion, scale });
|
||||
return { success: true, message: 'wallIitem created', data: newValue, organization: organization }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user