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.

5 changes: 5 additions & 0 deletions task-1/delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

USER_ID=11

curl -X DELETE http://localhost:3000/users/$USER_ID \
-H "Content-Type: application/json"
5 changes: 5 additions & 0 deletions task-1/get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

USER_ID=11

curl -X GET http://localhost:3000/users/$USER_ID \
-H "Content-Type: application/json"
10 changes: 10 additions & 0 deletions task-1/patch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@



USER_ID=11

curl -X PATCH http://localhost:3000/users/$USER_ID \
-H "Content-Type: application/json" \
-d '{
"email": "johndoe@example.com"
}'
12 changes: 12 additions & 0 deletions task-1/post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# add new user
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"
}'
18 changes: 15 additions & 3 deletions task-2/services.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Nobel Prize API Documentation: https://www.nobelprize.org/about/developer-zone-2/

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

const API_BASE_URL = 'https://api.nobelprize.org/2.1';
Expand All @@ -13,9 +12,22 @@ const API_BASE_URL = 'https://api.nobelprize.org/2.1';
* @param {number} filters.limit - Number of results per page (default: 10)
* @param {Function} onSuccess - Callback for successful fetch
* @param {Function} onError - Callback for fetch errors
*
*/
export function fetchNobelPrizes(filters = {}, onSuccess, onError) {
let url = ''; // TODO Construct the full URL with query parameters;
const { year, category, offset = 0, limit = 10 } = filters;

let url = `${API_BASE_URL}/nobelPrizes?offset=${offset}&limit=${limit}`;

// only add year if it is not "all"
if (year && year !== 'all') {
url += `&year=${year}`;
}

// only add category if it is not "all"
if (category && category !== 'all') {
url += `&nobelPrizeCategory=${category}`;
}

fetchData(url, onSuccess, onError);
}
}
13 changes: 13 additions & 0 deletions task-2/testServices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { fetchNobelPrizes } from './services.js';

// اختبار الدالة بدون أي فلاتر
fetchNobelPrizes({},
data => console.log('All Prizes:', data),
error => console.error('Error:', error)
);

// اختبار الدالة مع سنة وفئة معينة
fetchNobelPrizes({ year: '2020', category: 'phy' },
data => console.log('Physics Prizes 2020:', data),
error => console.error('Error:', error)
);
8 changes: 5 additions & 3 deletions task-2/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export default class UI {
* Populate year select dropdown with years from 1901 to current year
*/
populateYearSelect() {
const currentYear = new Date().getFullYear();
const startYear = 1901;

const currentYear = new Date().getFullYear();
const startYear = 1901;

// Add 'All' option first
const allOption = document.createElement('option');
Expand Down Expand Up @@ -108,7 +109,8 @@ export default class UI {

// Get filter values
const category = this.dom.categorySelect.value;
const year = this.dom.yearSelect.value;
const year = this.dom.yearSelect.value;


// Update state
this.state.filters.category = category;
Expand Down