RecentlyViewed API, view API, home page file added
This commit is contained in:
@@ -11,6 +11,7 @@ export interface Project extends Document {
|
||||
thumbnail: string;
|
||||
sharedUsers: [];
|
||||
DeletedAt: Date;
|
||||
isViewed: number;
|
||||
total_versions: string;
|
||||
Present_version: string;
|
||||
}
|
||||
@@ -24,6 +25,7 @@ const projectSchema: Schema = new Schema(
|
||||
sharedUsers: [{ type: Schema.Types.ObjectId, ref: "user" }],
|
||||
DeletedAt: { type: Date, default: null },
|
||||
isDeleted: { type: Boolean, default: false },
|
||||
isViewed: { type: Number },
|
||||
total_versions: { type: String },
|
||||
Present_version: { type: String },
|
||||
},
|
||||
|
||||
34
src/shared/services/home/recentDatasService.ts
Normal file
34
src/shared/services/home/recentDatasService.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import projectModel from "../../model/project/project-model.ts";
|
||||
import userModel from "../../model/user-Model.ts";
|
||||
import { existingUser } from "../helpers/ProjecthelperFn.ts";
|
||||
|
||||
interface IRecentData {
|
||||
organization: string;
|
||||
userId: string;
|
||||
}
|
||||
export const RecentlyAdded = async (data: IRecentData) => {
|
||||
try {
|
||||
const { userId, organization } = data;
|
||||
const userExisting = await existingUser(userId, organization);
|
||||
if (!userExisting) return { status: "User not found" };
|
||||
const userRecentData = await userModel(organization)
|
||||
.findOne({ _id: userId })
|
||||
.populate({
|
||||
path: "recentlyViewed",
|
||||
model: projectModel(organization),
|
||||
select: "_id projectName createdBy thumbnail createdAt isViewed",
|
||||
});
|
||||
let RecentDatas = [];
|
||||
userRecentData.recentlyViewed.map(async (project: object) => {
|
||||
console.log("project: ", typeof project);
|
||||
const projectExisting = await projectModel(organization).findOne({
|
||||
_id: project,
|
||||
isArchive: false,
|
||||
});
|
||||
});
|
||||
if (!userRecentData) return { status: "Datas were empty" };
|
||||
return { status: "Success", data: userRecentData.recentlyViewed };
|
||||
} catch (error) {
|
||||
return { status: error };
|
||||
}
|
||||
};
|
||||
@@ -179,11 +179,23 @@ export const viewProject = async (data: ProjectInterface) => {
|
||||
newArr.pop();
|
||||
}
|
||||
}
|
||||
await userExisting.updateOne(
|
||||
{ _id: userId, isArchive: false },
|
||||
{ recentlyViewed: newArr }
|
||||
await userModel(organization).updateOne(
|
||||
{ _id: userId },
|
||||
{ recentlyViewed: newArr },
|
||||
{ new: true }
|
||||
);
|
||||
return { data: existingProject };
|
||||
const projectData = await projectModel(organization)
|
||||
.findOneAndUpdate(
|
||||
{
|
||||
_id: projectId,
|
||||
createdBy: userId,
|
||||
isArchive: false,
|
||||
},
|
||||
{ isViewed: Date.now() },
|
||||
{ new: true }
|
||||
)
|
||||
.select("_id projectName createdBy thumbnail createdAt");
|
||||
return { status: "Success", data: projectData };
|
||||
} catch (error: unknown) {
|
||||
return { status: error };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user