DEV Community

Cover image for Creating a job board with Node.js and FaunaDB - Part 3
Luis Felipe Ciochetta
Luis Felipe Ciochetta

Posted on • Updated on

Creating a job board with Node.js and FaunaDB - Part 3

This is the third part of a series of posts documenting my studies with FaunaDB, these are the links for the first two posts:

This is the first post I am writting first in english and then translating to portuguese, let's see how this works out


*Company Module:
The hopeful start where I create this module and do some changes so it fits the model

*Testing the module:
Testing the two first functions of the module

*Losing my sanity with the update function:
It took me about an hour to write this part of the article because I got it wrong so many times, but I finally finished the update function

Company Module

I figured out that the company module should be really easy to do as well, so I will create it quickly and move on

I've started out by cloning the entire module for skills, then going to the validation, formatting and update and added the other fields.

In validation, I've added email:

And in the return, I've added each field:

Alt Text

This "social_media" feels a little bit unsecure, I don't know how it will work out.

In the formatting, I've added the new fields:

In the update, I am sending now the entire object (which I am not sure it's a good idea, but let's find out:

Testing the module

So now, I will add this companies module to the application and do some tests.

The url will be http://localhost/companies.

In my first try, I've realized the names were all incorrect in the routes.js file, so I've fixed it and tried again.

List is working:

Insert is working:

Losing my sanity with the update function

Update is not working, and that is about this "toString()" I am using in validation and also about not getting the value from the database before trying to update.

So I will first conditionally add these values to the object.

And I will add a part to this process, where I first get the company from the database, edit what I need, and then validate the object.

So using the query described here I will get the company.

I created this function to get it:

And validate it exists:

Alt Text

And now, I will create a function that will transfer the fields from the request company to the database company.

Alt Text
So, this one is kinda weirda, I've copied it from a project I've done a time ago;

In the first part I grab the dbCompany object and break it down to it's entries, and then map those entries, changing any value that is present in the request for the new one.

After that, I find every key that is missing from the original object.

Then, I add each new key to the first array and create a new object from it.

This object will be the one I am validating.

So I will test again now and see how it goes.

And I messed something up, because I did edit it, however the data now looks like this:

Alt Text

I think I messed up the validation function, I was doing

return {
        Valid: true,
        Company : Company,
Enter fullscreen mode Exit fullscreen mode

And I think the correct is

return {
        Valid: true,
        Company ,
Enter fullscreen mode Exit fullscreen mode

Tried again, failed again.

But after some logging, I think I figured it out, I think it's the data I am sending to Fauna, it should not be inside curly brackets.

So I tried again with the company without curly brackets and it worked.

Alt Text


Never underestimate the amount of bugs that can show up just because you have done this kind of function before.

The company module works, so I will start with the Candidate module in the next post.

Repository for this project:

Top comments (0)