wallitems update and project model creation

This commit is contained in:
2025-05-13 18:10:11 +05:30
parent 0297ba4993
commit d41142bfd0
7 changed files with 168 additions and 3 deletions

View File

@@ -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},

View 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;

View 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 });
};