Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task #1 #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
35 changes: 35 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Реализовать функционал для получения данных пользователя в нужном формате,
в зависимости от роли пользователя.
Данные пользователя будут располагаться http://fake-url.ru/:userId.
На вход приходит id пользователя в виде строки.
Функция должна возвратить данные пользователя в зависимости от роли.
Пока ролей только 2: admin, user, но планируется добавление других ролей
формата соответственно тоже 2:
для admin - name, role, password
для user - name, role
*/

import axios from "axios";

export const get = async (id_user) => {
const { data } = await axios.get(`http://fake-url.ru/${id_user}`);

let data1;
switch (true) {
case data.role === "admin": {
data1 = {
name: data.name,
role: data.role,
password: data.password,
};
}
case data.role === "user": {
data1 = {
name: data.name,
role: data.role,
};
}
}
return data1;
};