Complete backend for #21

Model, db-api.js and index.js for delegations.