patchSample(params, userName) {
    const now = new Date().toISOString();
    const reqBody = params.queryBody.value;
    const sampleName = params.key.value;
    const parsedSampleName = parseName(sampleName.toLowerCase());
    const subjectAbsolutePath = parsedSampleName.subject.absolutePath;
    const aspectName = parsedSampleName.aspect.name;
    let currSampObj;
    let aspectObj;
    return checkWritePermission(aspectName, userName)
    .then(() => redisOps.getHashPromise(sampleType, sampleName))
    .then((sampObj) => {
      if (!sampObj) {
        throw new redisErrors.ResourceNotFoundError({
          explanation: 'Sample not found.',
        });
      }

      currSampObj = sampObj;

      return redisOps.getHashPromise(aspectType, aspectName);
    })
    .then((aspObj) => {
      if (!aspObj || (aspObj.isPublished == 'false')) {
        throw new redisErrors.ResourceNotFoundError({
          explanation: 'Aspect not found.',
        });
      }

      modelUtils.removeExtraAttributes(reqBody, sampleFieldsArr);
      aspectObj = sampleStore.arrayObjsStringsToJson(
        aspObj, constants.fieldsToStringify.aspect
      );

      return redisOps.getHashPromise(subjectType, subjectAbsolutePath);
    })
    .then((subjObj) => {
      if (!subjObj || (subjObj.isPublished == 'false')) {
        throw new redisErrors.ResourceNotFoundError({
          explanation: 'Subject not found.',
        });
      }

      return checkWritePermission(aspectObj, userName);
    })
    .then(() => {
      if (reqBody.value) {
        const status = sampleUtils.computeStatus(aspectObj, reqBody.value);
        if (currSampObj[sampFields.STATUS] !== status) {
          reqBody[sampFields.PRVS_STATUS] = currSampObj[sampFields.STATUS];
          reqBody[sampFields.STS_CHANGED_AT] = now;
          reqBody[sampFields.STATUS] = status;
        }

        reqBody[sampFields.UPD_AT] = now;
      }

      if (reqBody.relatedLinks) {
        reqBody[sampFields.RLINKS] = reqBody.relatedLinks;
      }

      // stringify arrays
      constants.fieldsToStringify.sample.forEach((field) => {
        if (reqBody[field]) {
          reqBody[field] = JSON.stringify(reqBody[field]);
        }
      });
      return redisOps.setHashMultiPromise(sampleType, sampleName, reqBody);
    })
    .then(() => redisOps.getHashPromise(sampleType, sampleName))
    .then((updatedSamp) => {
      parseName(updatedSamp.name); // throw if invalid name
      return cleanAddAspectToSample(updatedSamp, aspectObj);
    })
    .catch((err) => {
      throw err;
    });
  }
/**
   * Patch sample. First get sample. If not found, throw error. Get aspect.
   * Update request body with required fields based on value and related links
   * if needed. Update sample. Then get updated sample, attach aspect and return
   * response. Note: Message body and message code will be updated if provided,
   * else no fields for message body/message code in redis object.
   *
   * @param  {Object} params - Request parameters
   * @param {String} userName - The user performing the write operation
   * @returns {Promise} - Resolves to a sample object
   */
Patch sample. First get sample. If not found, throw error. Get aspect.
Update request body with required fields based on value and related links
if needed. Update sample. Then get updated sample, attach aspect and return
response. Note: Message body and message code will be updated if provided,
else no fields for message body/message code in redis object.

@param  {Object} params - Request parameters
@param {String} userName - The user performing the write operation
@returns {Promise} - Resolves to a sample object
Patch sample . First get sample . If not found throw error . Get aspect . Update request body with required fields based on value and related links if needed . Update sample . Then get updated sample attach aspect and return response . Note : Message body and message code will be updated if provided else no fields for message body / message code in redis object . @param { Object } params - Request parameters @param { String } userName - The user performing the write operation @returns { Promise } - Resolves to a sample object
patchSample(params, userName) {
    const now = new Date().toISOString();
    const reqBody = params.queryBody.value;
    const sampleName = params.key.value;
    const parsedSampleName = parseName(sampleName.toLowerCase());
    const subjectAbsolutePath = parsedSampleName.subject.absolutePath;
    const aspectName = parsedSampleName.aspect.name;
    let currSampObj;
    let aspectObj;
    return checkWritePermission(aspectName, userName)
    .then(() => redisOps.getHashPromise(sampleType, sampleName))
    .then((sampObj) => {
      if (!sampObj) {
        throw new redisErrors.ResourceNotFoundError({
          explanation: 'Sample not found.',
        });
      }
      currSampObj = sampObj;
      return redisOps.getHashPromise(aspectType, aspectName);
    })
    .then((aspObj) => {
      if (!aspObj || (aspObj.isPublished == 'false')) {
        throw new redisErrors.ResourceNotFoundError({
          explanation: 'Aspect not found.',
        });
      }
      modelUtils.removeExtraAttributes(reqBody, sampleFieldsArr);
      aspectObj = sampleStore.arrayObjsStringsToJson(
        aspObj, constants.fieldsToStringify.aspect
      );
      return redisOps.getHashPromise(subjectType, subjectAbsolutePath);
    })
    .then((subjObj) => {
      if (!subjObj || (subjObj.isPublished == 'false')) {
        throw new redisErrors.ResourceNotFoundError({
          explanation: 'Subject not found.',
        });
      }
      return checkWritePermission(aspectObj, userName);
    })
    .then(() => {
      if (reqBody.value) {
        const status = sampleUtils.computeStatus(aspectObj, reqBody.value);
        if (currSampObj[sampFields.STATUS] !== status) {
          reqBody[sampFields.PRVS_STATUS] = currSampObj[sampFields.STATUS];
          reqBody[sampFields.STS_CHANGED_AT] = now;
          reqBody[sampFields.STATUS] = status;
        }
        reqBody[sampFields.UPD_AT] = now;
      }
      if (reqBody.relatedLinks) {
        reqBody[sampFields.RLINKS] = reqBody.relatedLinks;
      }
      constants.fieldsToStringify.sample.forEach((field) => {
        if (reqBody[field]) {
          reqBody[field] = JSON.stringify(reqBody[field]);
        }
      });
      return redisOps.setHashMultiPromise(sampleType, sampleName, reqBody);
    })
    .then(() => redisOps.getHashPromise(sampleType, sampleName))
    .then((updatedSamp) => {
      parseName(updatedSamp.name); 
      return cleanAddAspectToSample(updatedSamp, aspectObj);
    })
    .catch((err) => {
      throw err;
    });
  }
patchSample ( params , userName ) { const now = new Date ( ) . toISOString ( ) ; const reqBody = params . queryBody . value ; const sampleName = params . key . value ; const parsedSampleName = parseName ( sampleName . toLowerCase ( ) ) ; const subjectAbsolutePath = parsedSampleName . subject . absolutePath ; const aspectName = parsedSampleName . aspect . name ; let currSampObj ; let aspectObj ; return checkWritePermission ( aspectName , userName ) . then ( ( ) => redisOps . getHashPromise ( sampleType , sampleName ) ) . then ( ( sampObj ) => { if ( ! sampObj ) { throw new redisErrors . ResourceNotFoundError ( { explanation : 'Sample not found.' , } ) ; } currSampObj = sampObj ; return redisOps . getHashPromise ( aspectType , aspectName ) ; } ) . then ( ( aspObj ) => { if ( ! aspObj || ( aspObj . isPublished == 'false' ) ) { throw new redisErrors . ResourceNotFoundError ( { explanation : 'Aspect not found.' , } ) ; } modelUtils . removeExtraAttributes ( reqBody , sampleFieldsArr ) ; aspectObj = sampleStore . arrayObjsStringsToJson ( aspObj , constants . fieldsToStringify . aspect ) ; return redisOps . getHashPromise ( subjectType , subjectAbsolutePath ) ; } ) . then ( ( subjObj ) => { if ( ! subjObj || ( subjObj . isPublished == 'false' ) ) { throw new redisErrors . ResourceNotFoundError ( { explanation : 'Subject not found.' , } ) ; } return checkWritePermission ( aspectObj , userName ) ; } ) . then ( ( ) => { if ( reqBody . value ) { const status = sampleUtils . computeStatus ( aspectObj , reqBody . value ) ; if ( currSampObj [ sampFields . STATUS ] !== status ) { reqBody [ sampFields . PRVS_STATUS ] = currSampObj [ sampFields . STATUS ] ; reqBody [ sampFields . STS_CHANGED_AT ] = now ; reqBody [ sampFields . STATUS ] = status ; } reqBody [ sampFields . UPD_AT ] = now ; } if ( reqBody . relatedLinks ) { reqBody [ sampFields . RLINKS ] = reqBody . relatedLinks ; } constants . fieldsToStringify . sample . forEach ( ( field ) => { if ( reqBody [ field ] ) { reqBody [ field ] = JSON . stringify ( reqBody [ field ] ) ; } } ) ; return redisOps . setHashMultiPromise ( sampleType , sampleName , reqBody ) ; } ) . then ( ( ) => redisOps . getHashPromise ( sampleType , sampleName ) ) . then ( ( updatedSamp ) => { parseName ( updatedSamp . name ) ; return cleanAddAspectToSample ( updatedSamp , aspectObj ) ; } ) . catch ( ( err ) => { throw err ; } ) ; }
Patch sample.
Patch sample .
// stringify arrays // throw if invalid name