diff --git a/package-lock.json b/package-lock.json index 020596f..837218f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "core-assignment-week-10", + "name": "core-assignment-week-9", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "core-assignment-week-10", + "name": "core-assignment-week-9", "version": "1.0.0", "license": "ISC", "dependencies": { diff --git a/task-1/delete.sh b/task-1/delete.sh new file mode 100644 index 0000000..66259e3 --- /dev/null +++ b/task-1/delete.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +curl -X DELETE http://localhost:3000/users/11 diff --git a/task-1/get.sh b/task-1/get.sh new file mode 100644 index 0000000..6c1462a --- /dev/null +++ b/task-1/get.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +curl http://localhost:3000/users/11 diff --git a/task-1/patch.sh b/task-1/patch.sh new file mode 100644 index 0000000..bb796e7 --- /dev/null +++ b/task-1/patch.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +curl -X PATCH http://localhost:3000/users/11 \ + -H "Content-Type: application/json" \ + -d '{ + "email": "johndoe@example.com" + }' diff --git a/task-1/post.sh b/task-1/post.sh new file mode 100644 index 0000000..e18256d --- /dev/null +++ b/task-1/post.sh @@ -0,0 +1,12 @@ +#!/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" + }' diff --git a/task-1/server/users.json b/task-1/server/users.json index fc8d197..2243905 100644 --- a/task-1/server/users.json +++ b/task-1/server/users.json @@ -109,6 +109,17 @@ "createdAt": "2024-09-14T12:30:00Z", "lastLogin": "2026-02-03T13:00:00Z", "department": "Engineering" + }, + { + "id": 11, + "name": "John Doe", + "email": "john.doe@example.com", + "password": "$2b$10$lx9RKgxUq9f39zi0cX4j8ODwemMIQ903up40U8LX.EecWGi6rqVKK", + "role": "user", + "active": true, + "createdAt": "2026-03-11T16:09:53.518Z", + "lastLogin": null, + "department": "Engineering" } ] } \ No newline at end of file diff --git a/task-2/services.js b/task-2/services.js index 2126969..dd97b7a 100644 --- a/task-2/services.js +++ b/task-2/services.js @@ -4,6 +4,9 @@ import { fetchData } from './fetcher.js'; const API_BASE_URL = 'https://api.nobelprize.org/2.1'; +// https://api.nobelprize.org/2.1/nobelPrizes?offset=0&limit=10&sort=desc +// https://api.nobelprize.org/2.1/nobelPrizes?offset=0&limit=10&sort=desc[&nobelPrizeYear=2020][&nobelPrizeCategory=physics] + /** * Fetch Nobel Prizes with optional filters * @param {Object} filters - Filter options @@ -15,7 +18,21 @@ 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; + let url = `${API_BASE_URL}/nobelPrizes`; + const params = new URLSearchParams({ + offset: filters.offset || 0, + limit: filters.limit || 10, + sort: 'desc' + }); + + // Only add optional filters when not "all" + if (filters.year !== 'all') { + params.set('nobelPrizeYear', filters.year); + } + if (filters.category !== 'all') { + params.set('nobelPrizeCategory', filters.category); + } + url += `?${params}`; //ADD the query string to the end of url fetchData(url, onSuccess, onError); -} +} \ No newline at end of file