mcp-talent-server
Version:
Model Context Protocol server for talent management tools
69 lines • 2.7 kB
JavaScript
import mongoose, { Schema } from "mongoose";
// Folder Schema
const FolderSchema = new Schema({
name: { type: String, required: true, trim: true },
path: { type: String, required: true, index: true },
userId: { type: Schema.Types.ObjectId, ref: "User", required: true, index: true },
parentFolderId: { type: Schema.Types.ObjectId, ref: "Folder", default: null, index: true },
googleDriveId: { type: String, sparse: true, index: true }, // Google Drive folder ID for imported folders
}, {
timestamps: true,
toJSON: { virtuals: true },
toObject: { virtuals: true }
});
// Compound index for unique folder names within the same parent and user
FolderSchema.index({ name: 'text' }, { unique: true });
// Compound index for unique Google Drive imports per user
// FolderSchema.index({ googleDriveId: 1, userId: 1 }, { unique: true, sparse: true });
// Virtual for subfolder count
FolderSchema.virtual('subfolderCount', {
ref: 'Folder',
localField: '_id',
foreignField: 'parentFolderId',
count: true,
});
// Virtual for image count
FolderSchema.virtual('imageCount', {
ref: 'Image',
localField: '_id',
foreignField: 'folderId',
count: true,
});
// Image Schema
const ImageSchema = new Schema({
originalName: { type: String, required: true },
filename: { type: String, required: true, unique: true },
url: { type: String, required: true },
size: { type: Number, required: true },
mimetype: { type: String, required: true },
userId: { type: Schema.Types.ObjectId, ref: "User", required: true, index: true },
folderId: { type: Schema.Types.ObjectId, ref: "Folder", required: true, index: true },
googleDriveId: { type: String, sparse: true, index: true }, // Google Drive file ID for imported images
analysis: {
textContent: { type: String, default: "" },
labels: [{ type: String }],
description: { type: String, default: "" },
metadata: {
width: { type: Number, default: 0 },
height: { type: Number, default: 0 },
format: { type: String, default: "" },
size: { type: Number, default: 0 },
},
},
tags: [{ type: String, trim: true }],
}, {
timestamps: true,
toJSON: { virtuals: true },
toObject: { virtuals: true }
});
// Text index for search functionality
ImageSchema.index({
originalName: 'text',
tags: 'text',
});
// Compound index for unique Google Drive imports per user
// Export models
export const Folder = mongoose.model("Folder", FolderSchema);
export const Image = mongoose.model("Image", ImageSchema);
export default { Folder, Image };
//# sourceMappingURL=gallery.model.js.map