Laboratoria/models
This module is meant to be used with Node.js and expects the Node.js version of
the mongoose
module as an argument. If you are
looking for schemas to be used in the front-end please check
Laboratoria/schemas
.
Installation
npm install --save Laboratoria/models
Or add it in your package.json
and then npm install
:
{
"dependencies": {
"models": "Laboratoria/models#v1.0.0-alpha.1"
}
}
Usage
For more detailed information, please check the
official mongoose
docs
Creating and saving a model:
const mongoose = require('mongoose');
const { Project } = require('models')(mongoose);
const project = new Project({
slug: 'cipher',
repo: 'Laboratoria/curricula-js',
path: 'projects/01-cipher',
});
project.save()
.then(console.log)
.catch(console.error);
Finding models:
Project.find({}, (err, docs) => {
if (err) {
console.error(err);
}
});
Project.find({})
.then(console.log)
.catch(console.error);
Using Model.validate
as a Promise
:
const mongoose = require('mongoose');
const { Project } = require('models')(mongoose);
const project = new Project({
slug: 'cipher',
repo: 'Laboratoria/curricula-js',
path: 'projects/01-cipher',
});
project.validate()
.then(() => {
})
.catch((err) => {
});
Using Model.validate
with a callback:
const mongoose = require('mongoose');
const { Project } = require('models')(mongoose);
const project = new Project({
slug: 'cipher',
repo: 'Laboratoria/curricula-js',
path: 'projects/01-cipher',
});
project.validate((err) => {
});
Testing
Unit tests (and linter):
yarn test
End-to-end tests:
yarn e2e
Models
Application
Campuses
Cohorts
Endorsement
Graduates
Organizations
Placement
Projects
Tags
Topics
Users
Schemas
See Laboratoria/schemas
.