Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions task-1/delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
curl -X DELETE http://localhost:3000/users/11
2 changes: 2 additions & 0 deletions task-1/get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
curl -X GET http://localhost:3000/users/11
6 changes: 6 additions & 0 deletions task-1/patch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
curl -X PATCH http://localhost:3000/users/11 \
-H "Content-Type: application/json" \
-d '{
"email": "johndoe@example.com"
}'
11 changes: 11 additions & 0 deletions task-1/post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
curl -X POST http://localhost:3000/users \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john.doe@example.com",
"password": "secret123",
"role": "user",
"active": true,
"department": "Engineering"
}'
17 changes: 14 additions & 3 deletions task-2/services.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Nobel Prize API Documentation: https://www.nobelprize.org/about/developer-zone-2/

import { fetchData } from './fetcher.js';
import { fetchData } from "./fetcher.js";

const API_BASE_URL = 'https://api.nobelprize.org/2.1';
const API_BASE_URL = "https://api.nobelprize.org/2.1";

/**
* Fetch Nobel Prizes with optional filters
Expand All @@ -15,7 +15,18 @@ const API_BASE_URL = 'https://api.nobelprize.org/2.1';
* @param {Function} onError - Callback for fetch errors
*/
export function fetchNobelPrizes(filters = {}, onSuccess, onError) {
let url = ''; // TODO Construct the full URL with query parameters;
// TODO Construct the full URL with query parameters
let url =
`${API_BASE_URL}/nobelPrizes?` +
new URLSearchParams({
...(filters.year !== "all" && { nobelPrizeYear: filters.year }),
...(filters.category !== "all" && {
nobelPrizeCategory: filters.category,
}),
Comment on lines +22 to +25

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to do a double-take before I understood what this code does. In this case, I would prefer simpler code that I can understand at first glance. It may be a bit longer but with less chance of brain-fry.

  const params = new URLSearchParams({
    offset: filters.offset || 0,
    limit: filters.limit || 10,
    sort: "desc",
  });
  // console.log(params)

  if (filters.year !== "all") {
    params.append("nobelPrizeYear", filters.year);
  }

  if (filters.category !== "all") {
    params.append("nobelPrizeCategory", filters.category);
  }

 const url = `${API_BASE_URL}/nobelPrizes?${params.toString()}`;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @remarcmij
Thanks for your time and for showing me the alternative approach! I’ll keep readability in mind, but I also think this version looks quite clean. I appreciate the feedback!😊

offset: filters.offset || 0,
limit: filters.limit || 10,
sort: "desc",
});

fetchData(url, onSuccess, onError);
}