This repo contains a broken server setup you are expected to fix. The server then needs to give the correct responses to the below questions.
To run the server, invoke
$npm install
$npm start
Steps to perform:
3. Create an api endpoint in src/api/prodapis/handlers.js
called /csv2json
which accepts a csv file as an input and then sends a json object as response.
For eg:
Payload:
| Name | Age | Sex |
| :---: | :-: | :-: |
| Harish | 10 | M |
| Suresh | 20 | M |
| Chanda | 30 | F |
Response:
[
{
"name" : "Harish",
"age" : "10",
"sex" : "M"
},
{
"name" : "Suresh",
"age" : "20",
"sex" : "M"
},
{
"name" : "Chanda",
"age" : "30",
"sex" : "F"
}
]
4. Api endpoint /loop
processes an array and is supposed to reply the output of function adder
, when the array is serially processed through it. Function adder
might seem to be performing an overcomplicated addition, but assume it to be a proxy for any asynchronous operation.
We are currently passing an array [1,2,3,4,5,6,7,8,9,10]
to the function adder. Calling this api will currently give you:
Response = 0
and on the console :
Trying to add 1
Trying to add 2
Trying to add 3
Trying to add 4
Trying to add 5
Trying to add 6
Trying to add 7
Trying to add 8
Trying to add 9
Trying to add 10
Current sum is 1
Current sum is 2
Current sum is 3
Current sum is 4
Current sum is 5
Current sum is 6
Current sum is 7
Current sum is 8
Current sum is 9
Current sum is 10
This is obviously incorrect, and the correct method should be:
Response = 55
with console printing:
Trying to add 1
Current sum is 1
Trying to add 2
Current sum is 3
Trying to add 3
Current sum is 6
Trying to add 4
Current sum is 10
Trying to add 5
Current sum is 15
Trying to add 6
Current sum is 21
Trying to add 7
Current sum is 28
Trying to add 8
Current sum is 36
Trying to add 9
Current sum is 45
Trying to add 10
Current sum is 55
Modify ONLY and only the handler loop
to get the expected response. Do not make any changes to function adder
. I am interested in receving both the correct response as well as the correct logging on console (showing perfectly that the operation is happening serially, and not parallely). The actual step of addition needs to be performed using function adder
, and not bypassing it by any means.
5. Build an api that chooses one of the bonus offers based on the probablities provided. Each offer has a cool-down period i.e. the the user will get NOSTRA0BONUS offer in the cool down period.
GET
/offers?userId=XXX
Response:
{
message:"success"
code:200
data:{
offer:{
title:""
code: ""
}
}
}
Offers:
-----------------------------------------------------------------------
code | desc | Probability | cool down period
-----------------------------------------------------------------------
NOSTRA100BONUS | Get 100% Bonus | 10 % | 12 HRS
NOSTRA50BONUS | Get 50% Bonus | 10 % | 10 HRS
NOSTRA10BONUS | Get 10% Bonus | 50 % | 5 HRS
NOSTRA0BONUS | Keep Playing !! | 30 % | 0 HRS
e.g. Say a user get NOSTRA100BONUS offer in the first attempt. for next 12 hrs he will get NOSTRA0BONUS till the cool down period has expired.
Note: You can use in-process data-structure to store offered bonus for every user.
wallet_balance,
number_of_deposits
depositted_users
You have an excel sheet attached with the repo (Prob6-Data.csv) where the values of the params are given with user ids.
NOTE : The excel has limited records. While completing the tasks, consider it is being used by millions of users. Try making it as scalable, dynamic, optimized as possible.
-
Task 1:
Make a system where we can easily store data using the columns mentioned in the Excel. Make Sure (GET, POST, PUT, DELETE) operations are fast. The given data set has data for 20 users. Consider these operations are happening for ~ 1 million users. Give us particular api points which can be used to (GET, POST, PUT, DELETE) data from the system. -
Task 2: Design the system in such a way that using the parameters mentioned below -> (wallet_balance,number_of_deposits, depositted_users) & with some specific operators ( “AND”, “OR”, “>”, “<”, “=” ). I can make any number /type dynamic queries with provided parameters and operators
- CONDITION CAN BE LIKE
- Deposited users and whose wallet balance is greater than 30
- Users who have not deposited but have wallet_balance > certain amount.
- ETC….
Note: Request can not contain anything other than the operators and parameters. You can use the operators and parameters in any order. Your api should automatically work if new operators and params are added
HINT: Input should contain one user_id and the query Expected output: true/false(boolean)
If output is true that means the user id in request satisfies the condition and vice versa
- You are free to use any publicly available npm library
- This code was tested in
node v8.1.0
andnpm v5.0.3
. Please update node/npm before starting. - You may need to remove the node modules folder and reinstall. Perform by:
$rm -rf node_modules/
$npm install