Now you can run NODE_ENV=dev npm run seed to initialize the database with preset data.
Just remember to make a copy of the content in .env.dist to an .env file and set the following variables:
COMMUNITY_NAME=A community
COMMUNITY_COLOR_HEX=3177cc
DOCUMENT_TYPE_NAME=A simple type
Removed unused code
The POST for Community and DocumentType, plus other APIs endpoints that we wont be using, were removed. Hurray for minimal code!
Available APIs
GET /api/v1/document-type Retrieves the only document type available
PUT /api/v1/document-type Updates the only document type available
DocumentType versions
We will be using mongoose-version that makes copy of a documentType on every save. They will be stored in a collection called "documenttypes_versions",
The versions starts from 0. On creation, the version will be 0.
Inside the documentType model, there is a list of ignored paths. This are the fields that, if changed, it wont trigger a new version.
Also, I added currentVersion to the model. It should be in sync with the last version of the documentTyp.e. I added a pre middleware on the save hook when saving a documentType so it updates the value.
This was needed, cause the logic of mongoose-version for increasing the value of the version didn't worked as expected even having to ignore paths, so I made my own logic to fix that and to sync the currentVersion with the version container. It works as expected, now.
Tests updated
Yes, exactly!
> core@3.0.0 test /home/zaqueo/www/core
> NODE_ENV=test mocha --recursive --timeout 10000
Community API (/api/v1/community)
As anonymous user
✓ GET (/) Anyone should be able to get the community data (70ms)
As an admin user
✓ should get access_token from auth provider (805ms)
✓ PUT (/) should be able to update a community info (131ms)
DocumentType API (/api/v1/document-type)
As anonymous user
✓ GET (/) Anyone should be able to get documentType
As an admin user
✓ should get access_token from auth provider (264ms)
✓ PUT (/) it should be able to update document type (70ms)
Community DB-APIs
✓ Community.create() should create a community (99ms)
✓ Community.get() should get the only community created in the database
✓ Community.update() should update the only community created in the database
DocumentType DB-APIs
✓ DocumentType.create() should create a documentType (38ms)
✓ DocumentType.get() should get the only documentType created in the database
✓ DocumentType.update() should update a documentType
12 passing (2s)
How to run it from the beginning
Clone the repo
Follow the keycloack setup described on README
Remember to run the seed script in NODE_ENV=dev before running it!
Added the seed script
Now you can run
NODE_ENV=dev npm run seed
to initialize the database with preset data. Just remember to make a copy of the content in.env.dist
to an.env
file and set the following variables:Removed unused code
The POST for Community and DocumentType, plus other APIs endpoints that we wont be using, were removed. Hurray for minimal code!
Available APIs
DocumentType versions
We will be using mongoose-version that makes copy of a documentType on every save. They will be stored in a collection called "documenttypes_versions",
The versions starts from 0. On creation, the version will be 0. Inside the documentType model, there is a list of ignored paths. This are the fields that, if changed, it wont trigger a new version.
Also, I added
currentVersion
to the model. It should be in sync with the last version of the documentTyp.e. I added a pre middleware on thesave
hook when saving a documentType so it updates the value.This was needed, cause the logic of mongoose-version for increasing the value of the version didn't worked as expected even having to ignore paths, so I made my own logic to fix that and to sync the
currentVersion
with the version container. It works as expected, now.Tests updated
Yes, exactly!
How to run it from the beginning