Saving Polls to Database

Today was mainly spent figuring out how to save the Poll model to the database. In doing that, I learnt about AngularJS Providers and Factories, and how they are injected into controllers to get stuff done. I also learnt how to use AngularJS to perform client-side validation, and Mongoose to perform server-side validation.

When a user submits the form to create a new poll, AngularJS first performs client-side validation, then calls the createPoll() method. The controller then uses the Poll Factory to make a POST request to the API. The API routes the request to the server’s Poll controller, and performs server-side validation against the provided schema. Mongoose abstracts and simplifies this validation process. The newly created object, together with the poll id, is then returned. A callback in the AngularJS page controller is triggered, redirecting the user to the newly created poll.

I also learnt and made use of angular-moment while trying to improve the application’s user experience. Instead of displaying the date and time a poll was created, this module displays the relative time (e.g. 4 minutes ago) of creation.

I also started off on the poll details page. This page is designed for presenters to show the link of the poll for the audience to visit and answer. In order to make it easier, we planned to generate short URLs and provide QR Codes so that users do not have to type the full, long, URL into their mobile browser or laptop. For the QR Code, I made use of Google’s Chart API to draw and return an image of the QR Code for the corresponding URL used to access the poll.

We have yet to start on the URL shorterner, but will probably make use of existing URL shortening service such as goo.gl or bit.ly, or perhaps come up with our own within the same domain.