Click here to Skip to main content
15,071,262 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working in an audio encoding desktop application where Front end will be sending me the database data called jobdata and i have to update jobdetails object which is present in the array of jobdata which is as follows
{
 "jobId": "dc67b147-754f-48e3-8233-da4aa66913d6",
 "currentLicenseCount": 1,
 "licenseId": "159bb263-b265-451a-ae3d-0d789d586de7",
 "completedAt": 0,
 "reservedLicenseCount": 3,
 "isComplete": false,
 "userId": "5728f50d-146b-47d2-aa7b-a50bc37d641d",
 "updatedAt": 1616999479,
 "jobDetails": [
  {
   "encodingStrength": 0,
   "contentValidation": true,
   "contentFilePath": "/home/ubuntu/Downloads/sample1 (2).mp3",
   "additionalMetadata": {
    "format": {
     "container": "MPEG",
     "duration": 122.12244897959184,
     "codec": "MPEG 1 Layer 3",
     "trackInfo": [],
     "codecProfile": "CBR",
     "numberOfChannels": 2,
     "bitrate": 128000,
     "lossless": false,
     "sampleRate": 44100,
     "tagTypes": [
      "ID3v2.4"
     ]
    },
   "contentSamplingFrequency": 128000,
   "contentFileType": null,
   "contentDescription": null,
   "sonicKey": "fooyGoXpdAf",
   "contentDuration": 122.12244897959184,
   "contentSize": 0,
   "liscenseId": "159bb263-b265-451a-ae3d-0d789d586de7",
   "contentEncoding": null,
   "contentFileName": "sample1 (2).mp3",
   "contentQuality": null,
   "contentType": "MPEG",
   "isComplete": false,
   "fileId": "f6722638-629a-4b88-a3cc-ac5334f762d5"
  },
  {
   "encodingStrength": 0,
   "contentValidation": true,
   "contentFilePath": "/home/ubuntu/Downloads/sample1.mp3",
   "additionalMetadata": {
    "format": {
     "container": "MPEG",
     "duration": 122.12244897959184,
     "codec": "MPEG 1 Layer 3",
     "trackInfo": [],
     "codecProfile": "CBR",
     "numberOfChannels": 2,
     "bitrate": 128000,
     "lossless": false,
     "sampleRate": 44100,
     "tagTypes": [
      "ID3v2.4"
     ]
    },
   "contentSamplingFrequency": 128000,
   "contentFileType": null,
   "contentDescription": null,
   "sonicKey": "8iYrr1p0O3X",
   "contentDuration": 122.12244897959184,
   "contentSize": 0,
   "liscenseId": "159bb263-b265-451a-ae3d-0d789d586de7",
   "contentEncoding": null,
   "contentFileName": "sample1.mp3",
   "contentQuality": null,
   "contentType": "MPEG",
   "isComplete": false,
   "fileId": "05d1be20-f816-438b-8063-da25305459e7"
  },
  {
   "encodingStrength": 0,
   "contentValidation": true,
   "contentFilePath": "/home/ubuntu/Downloads/sample3.mp3",
   "additionalMetadata": {
    "format": {
     "container": "MPEG",
     "duration": 105.82204081632653,
     "codec": "MPEG 1 Layer 3",
     "trackInfo": [],
     "codecProfile": "CBR",
     "numberOfChannels": 2,
     "bitrate": 128000,
     "lossless": false,
     "sampleRate": 44100,
     "tagTypes": [
      "ID3v2.4"
     ]
    },
   "contentSamplingFrequency": 128000,
   "contentFileType": null,
   "contentDescription": null,
   "sonicKey": "uwE4yCM_2YO",
   "contentDuration": 105.82204081632653,
   "contentSize": 0,
   "liscenseId": "159bb263-b265-451a-ae3d-0d789d586de7",
   "contentEncoding": null,
   "contentFileName": "sample3.mp3",
   "contentQuality": null,
   "contentType": "MPEG",
   "isComplete": true,
   "fileId": "15e063ed-8e12-44cd-8674-011e2a189e26"
  }
 ],
 "createdAt": 1616999479,
 "jobName": "meet job 1"
}


What I have tried:

here it is an array of objects, if the job has 3 files and I have to update the "iscomplete" flag as true and I can't directly put the element as true because there may be multiple file id's ...so i just have to iterate till the length of the array and update "iscomplete" in my backend where ever I find "iscomplete" flag as true in the front end, I have used foreach loop but I don't know why this part doesn't get updated....

//mark file completion and increment the current license count of the job
    var arrayFileData = [];
    arrayFileData = jobData.jobDetails;
    arrayFileData.forEach(function (_value, i) {
      if ((fileId == arrayFileData[i]['fileId'])) {
        arrayFileData[i]['isComplete'] = true;
        jobData['currentLicenseCount'] = jobData['currentLicenseCount'] + 1;
        jobData.jobDetails = arrayFileData;
      }
    });
Posted
Updated 4-Apr-21 20:01pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900