24 lines
720 B
JavaScript

import mongoose from 'mongoose';
import { generateId } from '../../utils.js';
const userSchema = new mongoose.Schema(
{
_reference: { type: String, default: () => generateId()() },
username: { required: true, type: String },
name: { required: true, type: String },
firstName: { required: false, type: String },
lastName: { required: false, type: String },
email: { required: true, type: String },
profileImage: { type: mongoose.SchemaTypes.ObjectId, ref: 'file', required: false },
},
{ timestamps: true }
);
userSchema.virtual('id').get(function () {
return this._id;
});
userSchema.set('toJSON', { virtuals: true });
export const userModel = mongoose.model('user', userSchema);