@ironroggers/core-schemas
v1.0.6
Published
Reusable MongoDB Mongoose schemas for core entities
Maintainers
Readme
@your-scope/core-schemas
Reusable Mongoose models and schemas for core entities. CommonJS, no TypeScript.
Install
npm install @your-scope/core-schemas mongooseUsage
Connect mongoose in your app first, then import whatever you need:
const mongoose = require('mongoose');
const { User, Role, Project, Attendance } = require('@your-scope/core-schemas');
await mongoose.connect('mongodb://localhost:27017/mydb');
// Create a project
const project = await Project.create({ name: 'Alpha', status: 1 });
// Create a role
const role = await Role.create({ name: 'Admin', project: project._id });
// Create a user
const user = await User.create({
userName: 'jdoe',
email: '[email protected]',
password: 'hashed_password',
role: role._id,
project: project._id,
status: 1,
});
// Log attendance
const record = await Attendance.create({
user: user._id,
date: new Date(),
userStatus: 'present',
sessions: [
{ type: 'checkin', time: new Date(), geoLocation: { lat: 40.7128, lng: -74.006 } },
],
workHours: 8,
});Extending a Schema
const mongoose = require('mongoose');
const { UserSchema } = require('@your-scope/core-schemas');
UserSchema.add({ department: String });
module.exports = mongoose.model('User', UserSchema);Exported Models
| Export | Collection |
|---|---|
| Project | projects |
| Permission | permissions |
| Designation | designations |
| Role | roles |
| SSO | ssos |
| Attachment | attachments |
| User | users |
| Attendance | attendances |
Each model is also available as a raw schema export (e.g. UserSchema, RoleSchema) for extension.
Folder Structure
src/
schemas/ # Pure Schema definitions
models/ # mongoose.model() wrappers
index.js # Single entry point