mirror of
https://github.com/philipredstone/relnet.git
synced 2025-07-09 23:26:41 +02:00
initial commit
This commit is contained in:
52
src/models/person.model.ts
Normal file
52
src/models/person.model.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import mongoose, { Document, Schema } from 'mongoose';
|
||||
|
||||
export interface IPerson extends Document {
|
||||
_id: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
birthday?: Date;
|
||||
network: mongoose.Types.ObjectId;
|
||||
position: {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
}
|
||||
|
||||
const PersonSchema = new Schema(
|
||||
{
|
||||
firstName: {
|
||||
type: String,
|
||||
required: [true, 'First name is required'],
|
||||
trim: true,
|
||||
},
|
||||
lastName: {
|
||||
type: String,
|
||||
required: [true, 'Last name is required'],
|
||||
trim: true,
|
||||
},
|
||||
birthday: {
|
||||
type: Date,
|
||||
},
|
||||
network: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'Network',
|
||||
required: true,
|
||||
},
|
||||
position: {
|
||||
x: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
y: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
// Create compound index to ensure uniqueness within a network
|
||||
PersonSchema.index({ firstName: 1, lastName: 1, network: 1 }, { unique: true });
|
||||
|
||||
export default mongoose.model<IPerson>('Person', PersonSchema);
|
Reference in New Issue
Block a user