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
216 changes: 108 additions & 108 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions task-1/delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

curl -s -X DELETE "http://localhost:3000/users/11"
3 changes: 3 additions & 0 deletions task-1/get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

curl -s "http://localhost:3000/users/11"
7 changes: 7 additions & 0 deletions task-1/patch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

curl -s -X PATCH "http://localhost:3000/users/11" \
-H "Content-Type: application/json; charset=UTF-8" \
-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 @@
#!/usr/bin/env bash

curl -s -X POST "http://localhost:3000/users" \
-H "Content-Type: application/json; charset=UTF-8" \
-d '{
"name": "John Doe",
"email": "john.doe@example.com",
"password": "secret123",
"role": "user",
"active": true,
"department": "Engineering"
}'
7 changes: 4 additions & 3 deletions task-1/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ app.get('/users/:id', (req, res) => {

// CREATE a new user
app.post('/users', async (req, res) => {
const { name, email, password, role, department } = req.body;
const { name, email, password, role, active, department } = req.body;
const hashedPassword = await bcrypt.hash(password, 10);
const users = readUsers();
const newUser = {
Expand All @@ -59,7 +59,7 @@ app.post('/users', async (req, res) => {
email,
password: hashedPassword,
role,
active: true,
active,
createdAt: new Date().toISOString(),
lastLogin: null,
department,
Expand All @@ -75,12 +75,13 @@ app.put('/users/:id', async (req, res) => {
const users = readUsers();
const userIndex = users.findIndex((u) => u.id === parseInt(req.params.id));
if (userIndex !== -1) {
const { name, email, password, role, department } = req.body;
const { name, email, password, role, active, department } = req.body;
const updatedUser = {
...users[userIndex],
name,
email,
role,
active,
department,
...(password && { password: await bcrypt.hash(password, 10) }), // Update password if provided
};
Expand Down
16 changes: 15 additions & 1 deletion task-2/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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;
const params = new URLSearchParams();

params.set('offset', filters.offset);
params.set('limit', filters.limit);
params.set('sort', 'desc');

if (filters.year !== 'all') {
params.set('nobelPrizeYear', filters.year);
}

if (filters.category !== 'all') {
params.set('nobelPrizeCategory', filters.category);
}

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

fetchData(url, onSuccess, onError);
}