Tag-Based Message Formatting
€30-250 EUR
Paguhet në dorëzim
It is mandatory to have Node.js code.
Consider a JSON object that contains the following structure and values:
{
"context": {
"language": "FR",
"channel": "WEB"
},
"output": [
"ansCode": "BS_ANS_100",
"otherdata": "othervalue"
],
"user": {
"name": "Bobby",
"lastName": "Sponge",
"age": "2",
"balance": "$59.34"
}
}
Consider an existing Database (MySQL) that contains the following table:
TABLE Answer (
Answer_UID int PK
Code string
Language string
Channel string
Text string)
That contains the following value as example:
(100,
“BS_ANS_100”,
“EN”,
“WEB”,
“Hello dear <? [login to view URL] > <? [login to view URL] >, your balance is <? [login to view URL] >.”)
We are looking for a Node.js function that:
- Get the JSON object “[login to view URL]” value;
- That fetch from the Database all records that match the value of the “[login to view URL]” for the given ‘[login to view URL]’ and ‘[login to view URL]’ defined in the JSON object.
o If there are multiple records that are returned, a random record must be selected.
o If there is no match in the DB because there is no DB entry for ‘Channel’, the record that match ‘Code’ and ‘Language’ must be returned.
o If there is no match in the DB because there is no DB entry for ‘Language’, the record that match ‘Code’ and ‘Channel’ must be returned.
o If there is no match in the DB because there is no DB entry for ‘Language’ and ‘Channel’, the record that match ‘Code’ must be returned.
o If there is no match in the DB because there is no DB entry for ‘Code’, an error must be returned.
- Extract the ‘Text’ string from the record of the DB
- Calls an existing function to replace in ‘Text’ each tag (delimited by the ‘<?’ and the ‘>’) by their corresponding value in the JSON object.
o The result of the above example will give: “Hello dear Bobby Sponge, your balance is $59.34.”. The tag “<? [login to view URL] >” has been replace by the JSON value of the key “[login to view URL]”. This replacement function exists and is currently working.
o BUT on top of this, we are looking for Formatting capabilities.
o If the Tag contains the word ‘Format’ then formatting must be applied. As example if Text = “Your balance is <? Format(‘# ##0.00 $’, [login to view URL]) >.” Then the function should return the string: “Your balance is 59.34 $.”
o The formats for Currencies and Date must be supported, like “HH:mm:ss”, “DD/MM/YY” or “YYYY-MM-DD hh:mm:ss” etc.
o We may think adding additional format in the future, but not many, therefore the formatting string ("HH:mm:ss" as example) must be flexible.
Consider also that "Format" is our initial function that does formatting of text. We must be able to replace Format by some other capability. Here is an exemple:
- Assume Text = “The weather for today is <? [login to view URL]('today', 'New York', 'temperature') >.”
- The function should recognise that it is not Format but [login to view URL] and calla sub-function to get the weather for 'New York' for 'today' and 'temperature'. The number of parameter can depend. And the variable of the API must depend on the '[login to view URL]' value in the JSON object.
- The result should be “The weather for today is 75F."
We are looking for someone who can develop that Node.js function that takes as input parameter the JSON object and return a formatted string as described above. The function must perform the call into the DB and manage the errors as described above.
Additionally the code must be flexible enough to manage different keywords like "[login to view URL]" and not just "Format".
ID Projekti: #17450260
Rreth projektit
Është zgjedhur fitues:
10 profesionistë freelancer dërguan një ofertë mesatare prej €171 për këtë punë
Hello, I am expert working on Node.js, I always provide fastest results with quality. I have an experience of more than 10 years in web development and maintenance. I have in-depth knowledge of php, mysql, javascript , Më shumë
Hello! We are interesting your project very well and full time devlopers. We have great skill in Node.js and javascript. Our price and period is negotiable. Employee’s satisfy is my happiness ! Let's go ahead w Më shumë