Skip to content

Instantly share code, notes, and snippets.

@satyajitnayk
Created June 22, 2024 15:11
Show Gist options
  • Save satyajitnayk/0c06e0e721bf814c6b1241f11653dd66 to your computer and use it in GitHub Desktop.
Save satyajitnayk/0c06e0e721bf814c6b1241f11653dd66 to your computer and use it in GitHub Desktop.
nodejs practical question
const images = [
  { id: 1, url: 'XYZ' },
  { id: 2, url: 'DJJD' },
  { id: 3, url: 'JJEEJ' },
  { id: 4, url: 'EOOI' },
];

const reviews = [
  { id: 1, productId: 1, customerId: 1, images: [1, 2] },
  { id: 2, productId: 2, customerId: 2, images: [3] },
  { id: 3, productId: 1, customerId: 1, images: [4] },
  { id: 4, productId: 3, customerId: 4, images: [1, 4] },
];

const customers = [
  { id: 1, name: 'Mark', phoneNo: 1234567679, cardNo: 1234123456785678 },
  { id: 2, name: 'Louis', phoneNo: 987654321, cardNo: 1234123456785678 },
  { id: 3, name: 'Zach', phoneNo: 74783547385, cardNo: 1234123456785678 },
  { id: 4, name: 'Dona', phoneNo: 97436843643, cardNo: 1234123456785678 },
];

const products = [
  { id: 1, name: 'Apple' },
  { id: 2, name: 'Peach' },
  { id: 3, name: 'Grapes' },
];


// Complete the method as instructed
function getProductDetails(productId) {
  // check if productId is valid positiv integer or else throw Error "Need a valid positive interger"

  // if productId not found throe Product Not Found Error

  /**
   * return product details
   * 
   * encode phoneNumber of customer with base64
   * do not include customer cardNo in result
    
    Final Example Result
    `{
      "id": 1,
      "name": "Apple",
      "reviews": [
        {
          "id": 1,
          "images": [
            { "id": 1, "url": "XYZ" },
            { "id": 2, "url": "DJJD" }
          ],
          "customer": { "id": 1, "name": "Mark", "phoneNo": "MTIzNDU2NzY3OQ==" }
        },
        {
          "id": 3,
          "images": [{ "id": 4, "url": "EOOI" }],
          "customer": { "id": 1, "name": "Mark", "phoneNo": "MTIzNDU2NzY3OQ==" }
        }
      ]
    }`
   * 
   * */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment