Some checks failed
farmcontrol/farmcontrol-api/pipeline/head There was a failure building this commit
27 lines
898 B
JavaScript
27 lines
898 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 },
|
|
appPasswordHash: { type: String, required: false, select: false },
|
|
},
|
|
{ timestamps: true }
|
|
);
|
|
|
|
userSchema.index({ username: 'text', name: 'text', firstName: 'text', lastName: 'text', email: 'text' });
|
|
|
|
userSchema.virtual('id').get(function () {
|
|
return this._id;
|
|
});
|
|
|
|
userSchema.set('toJSON', { virtuals: true });
|
|
|
|
export const userModel = mongoose.model('user', userSchema);
|