thread Version updated

This commit is contained in:
2025-06-23 16:42:47 +05:30
parent 3ec45276f4
commit 20509c268a
8 changed files with 155 additions and 107 deletions

View File

@@ -14,12 +14,12 @@ export const threadCreate = async (
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { projectId } = req.body;
const { projectId, versionId } = req.body;
if (!req.user?.userId || !req.user?.organization) {
res.status(401).json({ message: "Unauthorized" });
return;
}
if (!projectId || !organization || !userId) {
if (!projectId || !organization || !userId || !versionId) {
res.status(400).json({
message: "All fields are required",
});
@@ -33,9 +33,9 @@ export const threadCreate = async (
message: "Project not found",
});
break;
case "CurrentVersion Data not found":
case "Version Data not found":
res.status(404).json({
message: "CurrentVersion Data not found",
message: "Version Data not found",
});
break;
case "User not found":
@@ -67,12 +67,12 @@ export const threaddelete = async (
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { projectId } = req.body;
const { projectId, versionId } = req.body;
if (!req.user?.userId || !req.user?.organization) {
res.status(401).json({ message: "Unauthorized" });
return;
}
if (!projectId || !organization || !userId) {
if (!projectId || !organization || !userId || !versionId) {
res.status(400).json({
message: "All fields are required",
});
@@ -86,9 +86,9 @@ export const threaddelete = async (
message: "Project not found",
});
break;
case "CurrentVersion Data not found":
case "Version Data not found":
res.status(404).json({
message: "CurrentVersion Data not found",
message: "Version Data not found",
});
break;
case "User not found":
@@ -119,12 +119,12 @@ export const threadUpdateTitle = async (
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { projectId, threadId } = req.body;
const { projectId, threadId, versionId } = req.body;
if (!req.user?.userId || !req.user?.organization) {
res.status(401).json({ message: "Unauthorized" });
return;
}
if (!projectId || !threadId || !organization || !userId) {
if (!projectId || !threadId || !organization || !userId || !versionId) {
res.status(400).json({
message: "All fields are required",
});
@@ -142,9 +142,9 @@ export const threadUpdateTitle = async (
message: "Project not found",
});
break;
case "CurrentVersion Data not found":
case "Version Data not found":
res.status(404).json({
message: "CurrentVersion Data not found",
message: "Version Data not found",
});
break;
case "User not found":
@@ -176,12 +176,12 @@ export const threadComment = async (
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { projectId, threadId } = req.body;
const { projectId, threadId, versionId } = req.body;
if (!req.user?.userId || !req.user?.organization) {
res.status(401).json({ message: "Unauthorized" });
return;
}
if (!projectId || !threadId || !organization || !userId) {
if (!projectId || !threadId || !organization || !userId || !versionId) {
res.status(400).json({
message: "All fields are required",
});
@@ -196,9 +196,9 @@ export const threadComment = async (
message: "Project not found",
});
break;
case "CurrentVersion Data not found":
case "Version Data not found":
res.status(404).json({
message: "CurrentVersion Data not found",
message: "Version Data not found",
});
break;
case "User not found":
@@ -236,12 +236,19 @@ export const threadCommentDelete = async (
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { projectId, threadId, commentId } = req.body;
const { projectId, threadId, commentId, versionId } = req.body;
if (!req.user?.userId || !req.user?.organization) {
res.status(401).json({ message: "Unauthorized" });
return;
}
if (!projectId || !commentId || !threadId || !organization || !userId) {
if (
!projectId ||
!commentId ||
!threadId ||
!organization ||
!userId ||
!versionId
) {
res.status(400).json({
message: "All fields are required",
});
@@ -255,9 +262,9 @@ export const threadCommentDelete = async (
message: "Project not found",
});
break;
case "CurrentVersion Data not found":
case "Version Data not found":
res.status(404).json({
message: "CurrentVersion Data not found",
message: "Version Data not found",
});
break;
case "User not found":
@@ -298,18 +305,23 @@ export const getALLthreads = async (
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { projectId } = req.params;
const { projectId, versionId } = req.params;
if (!req.user?.userId || !req.user?.organization) {
res.status(401).json({ message: "Unauthorized" });
return;
}
if (!projectId || !organization || !userId) {
if (!projectId || !organization || !userId || !versionId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await findThreads({ projectId, userId, organization });
const result = await findThreads({
versionId,
projectId,
userId,
organization,
});
switch (result?.status) {
case "Project not found":
@@ -317,9 +329,9 @@ export const getALLthreads = async (
message: "Project not found",
});
break;
case "CurrentVersion Data not found":
case "Version Data not found":
res.status(404).json({
message: "CurrentVersion Data not found",
message: "Version Data not found",
});
break;
case "User not found":

View File

@@ -1,35 +1,26 @@
import express from "express";
import { tokenValidator } from "../../../shared/utils/token.ts";
import { getALLthreads, threadComment, threadCommentDelete, threadCreate, threaddelete, threadUpdateTitle } from "../v1Controllers/threadController/threadController.ts";
import {
getALLthreads,
threadComment,
threadCommentDelete,
threadCreate,
threaddelete,
threadUpdateTitle,
} from "../v1Controllers/threadController/threadController.ts";
const V1ThreadRoutes = express.Router();
V1ThreadRoutes.post(
"/upsetThread/",
tokenValidator,
threadCreate
);
V1ThreadRoutes.patch(
"/Thread/delete",
tokenValidator,
threaddelete
);
V1ThreadRoutes.patch(
"/Thread/updateTitle",
tokenValidator,
threadUpdateTitle
);
V1ThreadRoutes.post(
"/Thread/addComment",
tokenValidator,
threadComment
);
V1ThreadRoutes.post("/upsetThread/", tokenValidator, threadCreate);
V1ThreadRoutes.patch("/Thread/delete", tokenValidator, threaddelete);
V1ThreadRoutes.patch("/Thread/updateTitle", tokenValidator, threadUpdateTitle);
V1ThreadRoutes.post("/Thread/addComment", tokenValidator, threadComment);
V1ThreadRoutes.patch(
"/Thread/deleteComment",
tokenValidator,
threadCommentDelete
);
V1ThreadRoutes.get(
"/Threads/:projectId",
"/Threads/:projectId/:versionId",
tokenValidator,
getALLthreads
);
export default V1ThreadRoutes
export default V1ThreadRoutes;

View File

@@ -7,6 +7,7 @@ export interface Token extends Document {
refreshToken: string;
resetTokenExpiry?: Date;
resetToken: string;
role: string;
}
const tokenSchema: Schema = new Schema({
userId: { type: Schema.Types.ObjectId, ref: "User" },

View File

@@ -12,6 +12,10 @@ const AuthSchema: Schema = new Schema({
userName: {
type: String,
required: true,
},role: {
type: String,
default: "User",
enum: ["User", "Admin"],
},
Email: {
type: String,

View File

@@ -7,7 +7,7 @@ interface IComment {
userId: User["_id"];
comment: string;
isArchive: boolean;
createdAt: number
createdAt: number;
}
export interface IThread extends Document {
projectId: Project["_id"];
@@ -22,28 +22,26 @@ export interface IThread extends Document {
comments: IComment[];
isArchive: boolean;
isResolved: boolean;
}
const CommentSchema = new Schema<IComment>(
{
userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },
comment: { type: String, },
isArchive: { type: Boolean, default: false },
createdAt: {
type: Number,
default: Date.now()
}
const CommentSchema = new Schema<IComment>({
userId: { type: Schema.Types.ObjectId, ref: "User", required: true },
comment: { type: String },
isArchive: { type: Boolean, default: false },
createdAt: {
type: Number,
default: Date.now(),
},
);
});
const threadSchema = new Schema<IThread>({
projectId: { type: Schema.Types.ObjectId, ref: 'Project', required: true },
state: { type: String, enum: ['active', 'inactive'], required: true },
threadTitle: { type: String, },
createdBy: { type: Schema.Types.ObjectId, ref: 'User', required: true },
createdAt: { type: Number, },
projectId: { type: Schema.Types.ObjectId, ref: "Project", required: true },
versionId: { type: Schema.Types.ObjectId, ref: "Version", required: true },
state: { type: String, enum: ["active", "inactive"], required: true },
threadTitle: { type: String },
createdBy: { type: Schema.Types.ObjectId, ref: "User", required: true },
createdAt: { type: Number },
isArchive: { type: Boolean, default: false },
isResolved: { type: Boolean, default: false },
lastUpdatedAt: { type: String, },
lastUpdatedAt: { type: String },
position: {
type: [Number],
required: true,
@@ -58,4 +56,4 @@ const threadSchema = new Schema<IThread>({
const ThreadModel = (db: string) => {
return MainModel(db, "Threads", threadSchema, "Threads");
};
export default ThreadModel;
export default ThreadModel;

View File

@@ -32,6 +32,7 @@ interface IComment {
interface IgetThread {
projectId: string;
versionId: string;
userId: string;
organization: string;
}
@@ -39,6 +40,7 @@ export const createThread = async (data: IThread) => {
try {
const {
projectId,
versionId,
state,
userId,
position,
@@ -46,6 +48,7 @@ export const createThread = async (data: IThread) => {
threadTitle,
organization,
} = data;
console.log('data;: ', data);
const userExisting = await existingUser(userId, organization);
if (!userExisting) {
return {
@@ -60,15 +63,15 @@ export const createThread = async (data: IThread) => {
if (!projectExisting) {
return { status: "Project not found" };
}
const currentVersion = await LivingCurrentVersion(
const ExistingVersion = await LivingCurrentVersion(
organization,
projectExisting._id,
projectExisting.Present_version
versionId
);
if (!currentVersion) return { status: "CurrentVersion Data not found" };
if (!ExistingVersion) return { status: "Version Data not found" };
const newThread = await ThreadModel(organization).create({
projectId,
versionId: currentVersion._id,
versionId: versionId,
state,
createdBy: userId,
position,
@@ -77,6 +80,7 @@ export const createThread = async (data: IThread) => {
isArchive: false,
createdAt: Date.now(),
});
console.log('newThread: ', newThread);
const responseData = {
_id: newThread._id,
projectId: newThread.projectId,
@@ -101,7 +105,7 @@ export const createThread = async (data: IThread) => {
};
export const deleteThread = async (data: IThread) => {
try {
const { projectId, userId, organization, threadId } = data;
const { projectId, userId, versionId, organization, threadId } = data;
const userExisting = await existingUser(userId, organization);
if (!userExisting) {
return {
@@ -116,12 +120,12 @@ export const deleteThread = async (data: IThread) => {
if (!projectExisting) {
return { status: "Project not found" };
}
const currentVersion = await LivingCurrentVersion(
const ExistingVersion = await LivingCurrentVersion(
organization,
projectExisting._id,
projectExisting.Present_version
versionId
);
if (!currentVersion) return { status: "CurrentVersion Data not found" };
if (!ExistingVersion) return { status: "Version Data not found" };
const findThreadId = await ThreadModel(organization).findOne({
_id: threadId,
createdBy: userId,
@@ -147,6 +151,7 @@ export const updateThreadTitle = async (data: IThread) => {
try {
const {
projectId,
versionId,
userId,
threadTitle,
organization,
@@ -168,12 +173,12 @@ export const updateThreadTitle = async (data: IThread) => {
if (!projectExisting) {
return { status: "Project not found" };
}
const currentVersion = await LivingCurrentVersion(
const ExistingVersion = await LivingCurrentVersion(
organization,
projectExisting._id,
projectExisting.Present_version
versionId
);
if (!currentVersion) return { status: "CurrentVersion Data not found" };
if (!ExistingVersion) return { status: "Version Data not found" };
const findThreadId = await ThreadModel(organization).findById(threadId);
if (findThreadId) {
const updateThread = await ThreadModel(organization).findOneAndUpdate(
@@ -200,8 +205,15 @@ export const updateThreadTitle = async (data: IThread) => {
};
export const addComments = async (data: IThread) => {
try {
const { projectId, userId, comment, organization, threadId, commentId } =
data;
const {
projectId,
versionId,
userId,
comment,
organization,
threadId,
commentId,
} = data;
const userExisting = await existingUser(userId, organization);
if (!userExisting) {
return {
@@ -216,12 +228,12 @@ export const addComments = async (data: IThread) => {
if (!projectExisting) {
return { status: "Project not found" };
}
const currentVersion = await LivingCurrentVersion(
const ExistingVersion = await LivingCurrentVersion(
organization,
projectExisting._id,
projectExisting.Present_version
versionId
);
if (!currentVersion) return { status: "CurrentVersion Data not found" };
if (!ExistingVersion) return { status: "Version Data not found" };
const findThreadId = await ThreadModel(organization).findById(threadId);
if (commentId) {
const updated = await ThreadModel(organization).findOneAndUpdate(
@@ -276,7 +288,8 @@ export const addComments = async (data: IThread) => {
};
export const deleteComments = async (data: IThread) => {
try {
const { projectId, userId, commentId, organization, threadId } = data;
const { projectId, versionId, userId, commentId, organization, threadId } =
data;
const userExisting = await existingUser(userId, organization);
if (!userExisting) {
return {
@@ -291,12 +304,12 @@ export const deleteComments = async (data: IThread) => {
if (!projectExisting) {
return { status: "Project not found" };
}
const currentVersion = await LivingCurrentVersion(
const ExistingVersion = await LivingCurrentVersion(
organization,
projectExisting._id,
projectExisting.Present_version
versionId
);
if (!currentVersion) return { status: "CurrentVersion Data not found" };
if (!ExistingVersion) return { status: "Version Data not found" };
const findThreadId = await ThreadModel(organization).findOne({
_id: threadId,
});
@@ -330,7 +343,7 @@ export const deleteComments = async (data: IThread) => {
};
export const findThreads = async (data: IgetThread) => {
try {
const { projectId, userId, organization } = data;
const { projectId, versionId, userId, organization } = data;
const userExisting = await existingUser(userId, organization);
if (!userExisting) {
return {
@@ -345,14 +358,17 @@ export const findThreads = async (data: IgetThread) => {
if (!projectExisting) {
return { status: "Project not found" };
}
const currentVersion = await LivingCurrentVersion(
const VersionGetId = versionId
? versionId
: projectExisting.Present_version;
const ExistingVersion = await LivingCurrentVersion(
organization,
projectExisting._id,
projectExisting.Present_version
VersionGetId
);
if (!currentVersion) return { status: "CurrentVersion Data not found" };
if (!ExistingVersion) return { status: "Version Data not found" };
const findThreads = await ThreadModel(organization)
.find({ isArchive: false, projectId, versionId: currentVersion._id })
.find({ isArchive: false, projectId, versionId: versionId })
.lean();
const formattedThreads = findThreads.map((thread) => {

View File

@@ -62,11 +62,12 @@ export const AuthSignup = async (
const newuser = await AuthModel(organization).create({
userName: userName,
Email: caseChange,
role: role,
Password: hashPassword,
});
await UsersDataModel(organization).create({
userId: newuser._id,
role: role,
// role: role,
isShare: isShare,
profilePicture: profilePicture,
});

View File

@@ -33,6 +33,7 @@ export const createThreadHandleEvent = async (
"rotation",
"organization",
"projectId",
"versionId",
];
const missingFields = validateFields(data, requiredFields);
@@ -55,8 +56,8 @@ export const createThreadHandleEvent = async (
Success: { message: "Thread created Successfully" },
"User not found": { message: "User not found" },
"Project not found": { message: "Project not found" },
"CurrentVersion Data not found": {
message: "CurrentVersion Data not found",
"Version Data not found": {
message: "Version Data not found",
},
};
const msg = messages[status] || { message: "Internal server error" };
@@ -99,7 +100,13 @@ export const deleteThreadHandleEvent = async (
}
) => {
if (event !== EVENTS.deleteThread || !data?.organization) return;
const requiredFields = ["userId", "threadId", "organization", "projectId"];
const requiredFields = [
"userId",
"threadId",
"organization",
"projectId",
"versionId",
];
const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) {
@@ -121,8 +128,8 @@ export const deleteThreadHandleEvent = async (
Success: { message: "Thread deleted Successfully" },
"User not found": { message: "User not found" },
"Project not found": { message: "Project not found" },
"CurrentVersion Data not found": {
message: "CurrentVersion Data not found",
"Version Data not found": {
message: "Version Data not found",
},
"can't deleted": { message: "Thread could not be deleted" },
};
@@ -155,7 +162,13 @@ export const addCommentHandleEvent = async (
}
) => {
if (event !== EVENTS.addComment || !data?.organization) return;
const requiredFields = ["userId", "organization", "threadId", "projectId"];
const requiredFields = [
"userId",
"versionId",
"organization",
"threadId",
"projectId",
];
const missingFields = validateFields(data, requiredFields);
@@ -178,8 +191,8 @@ export const addCommentHandleEvent = async (
Success: { message: "Thread comments add Successfully" },
"User not found": { message: "User not found" },
"Project not found": { message: "Project not found" },
"CurrentVersion Data not found": {
message: "CurrentVersion Data not found",
"Version Data not found": {
message: "Version Data not found",
},
updated: { message: "Comment updated successfully" },
};
@@ -215,7 +228,13 @@ export const deleteCommentHandleEvent = async (
}
) => {
if (event !== EVENTS.deleteComment || !data?.organization) return;
const requiredFields = ["userId", "organization", "commentId", "projectId"];
const requiredFields = [
"userId",
"versionId",
"organization",
"commentId",
"projectId",
];
const missingFields = validateFields(data, requiredFields);
@@ -237,8 +256,8 @@ export const deleteCommentHandleEvent = async (
Success: { message: "Thread comment deleted Successfully" },
"User not found": { message: "User not found" },
"Project not found": { message: "Project not found" },
"CurrentVersion Data not found": {
message: "CurrentVersion Data not found",
"Version Data not found": {
message: "Version Data not found",
},
unauthorized: { message: "You can only delete your own comment." },
"thread not found": { message: "thread not found" },
@@ -272,7 +291,13 @@ export const threadUpdateHandleEvent = async (
}
) => {
if (event !== EVENTS.updateThreat || !data?.organization) return;
const requiredFields = ["userId", "organization", "threadId", "projectId"];
const requiredFields = [
"userId",
"versionId",
"organization",
"threadId",
"projectId",
];
const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) {
@@ -293,8 +318,8 @@ export const threadUpdateHandleEvent = async (
Success: { message: "ThreadTitle updated Successfully" },
"User not found": { message: "User not found" },
"Project not found": { message: "Project not found" },
"CurrentVersion Data not found": {
message: "CurrentVersion Data not found",
"Version Data not found": {
message: "Version Data not found",
},
};
const msg = messages[status] || { message: "Internal server error" };