DEV Community

Phan Hieu Nguyen
Phan Hieu Nguyen

Posted on

SenecaCDot telescope

Summary

I worked on a big project (but not big issue) that all my fellow students are working on
Repo link
Pull request

Features

Adding validation for CRUD operation's param; and writing some tests for it.

Challenges

The most challenging task was actually setting up the environment for this projects. In prerequisites, there are 3 applications that I have to install Node.js, Redis, Elasticsearch. I assumed I have to have all 3 by default to set up. Later on when starting service, there are 2 options: using Docker or Natively installed. I chose to use Docker. And it cause error because Redis is already in use, because I manually install it in prerequisites. After sometime, I figured out to stop local Redis service that I installed, then it (Docker) would work. So I hope the instructions would be better if prerequisites have 2 options similar to "starting service" part: Docker and Native.

Working on the actual issue was simpler. Adding Express (backend) validator feels like adding extra function before CRUD request actually run, so
route.delete('path/:id', (req,res) ...
become
route.delete('path/:id', validateFunction(), (req,res) ...
I used a simple validation for :id like a phone number, it has to have 10 digit. And then later on we can check if the existence of that :id.
I really like this validate because it will save some resource comparing to always check the existence :id from database.

The last task was writing test for my validate function. I have never written a proper test before (please don't make fun a me), so I was excited. It wasn't difficult because there were some tests already written in the projects, so I just followed them and had 2 test cases for mine. One with 9 digits and one with 12 digits. It turned out just fine, and I was very happy.

Top comments (0)