vicinityManager/server/services/items/registration.js
/*
Checks if the oid is in Mongo
If it is, creates a new one and checks again
Ensures oid uniqueness
*/
Checks if the oid is in Mongo
If it is, creates a new one and checks again
Ensures oid uniqueness
Checks if the oid is in Mongo If it is creates a new one and checks again Ensures oid uniqueness
function oidExist(oid){
  return itemOp.findOne({oid: oid})
  .then(
    function(data){
      if(!data){
        return new Promise(function(resolve, reject) { resolve(oid) ;} );
      } else {
        oid = uuid();
        oidExist(oid);
      }
    })
  .catch(
    function(err){
        return new Promise(function(resolve, reject) { reject('Error in Mongo: ' + err) ;} );
  });
}
function oidExist ( oid ) { return itemOp . findOne ( { oid : oid } ) . then ( function ( data ) { if ( ! data ) { return new Promise ( function ( resolve , reject ) { resolve ( oid ) ; } ) ; } else { oid = uuid ( ) ; oidExist ( oid ) ; } } ) . catch ( function ( err ) { return new Promise ( function ( resolve , reject ) { reject ( 'Error in Mongo: ' + err ) ; } ) ; } ) ; }
Checks if the oid is in Mongo
If it is, creates a new one and checks again
Ensures oid uniqueness
Checks if the oid is in Mongo If it is creates a new one and checks again Ensures oid uniqueness