DemocracyOS / core

1 stars 1 forks source link

Adds DocumentType model, API, dbAPI and Tests related. #32

Closed guillecro closed 6 years ago

guillecro commented 6 years ago

This pull requests closes issues #18 #19 and #20.

Finally DocumentType is done. An example of a documentType would look like this:

{
    "name": "CV basic data",
    "icon": "fa-file-o",
    "description": "This are data that every CV should have needed for a CV",
    "fields": {
        "blocks": [
            {
                "name": "Authors contact info",
                "fields": [
                    "authorEmail",
                    "authorName",
                    "authorSurname"
                ]
            },
            {
                "name": "Org info",
                "fields": [
                    "orgEmail",
                    "orgAdress",
                    "orgTel"
                ]
            }
        ],
        "properties": {
            "authorName": {
                "type": "string",
                "title": "Author's name"
            },
            "authorSurname": {
                "type": "string",
                "title": "Author's surname"
            },
            "authorEmail": {
                "type": "string",
                "title": "Author's email"
            },
            "orgTel": {
                "type": "string",
                "title": "Author's tel"
            },
            "orgEmail": {
                "type": "string",
                "title": "Author's email"
            },
            "orgAdress": {
                "type": "string",
                "title": "Author's address"
            }
        },
        "required": [
            "authorName",
            "authorSurname",
            "authorEmail"
        ]
    }
}

APIs available:

Path Method Returns Auth
/api/v1/document-types GET Gives a list of all the document types available. Paginated. An optional query parameter is versions=true where it also populates each document type with all the previous versions respectively none
/api/v1/document-types POST Create a document type admin
/api/v1/document-types/:id GET Retrieves a document type with id :id none
/api/v1/document-types/:id PUT Updates a document type with ID :id admin
/api/v1/document-types/:id DELETE Deletes a document type with ID :id admin
/api/v1/document-types/:id/versions GET Retrieves all the versions of a specific document type :id admin
/api/v1/document-types/:id/versions/:v GET Retrieves a version (:v) of a specific document type with the ID :id admin

Everytime you create a new documentType and update it, you will be creating a new version in another collection, thanks to mongoose-version.

For now, every change creates a new version. I wasn't able to "ignore" the creation of a new version based on a list of paths, so even if you change the name, or the description, a new version is created, but i think that for now, it does what it should do.

Also i made some others fixes to docker-compose and updated the README.md for the setup instructions.

Well, this is just a start! But i think it works perfectly for document.

franciclo commented 6 years ago

I think the minimal case scenario could be done with less functionalities, lets chat about it.

guillecro commented 6 years ago

Closing pull request for now, due to not being a proper contribution.