Backend/Microservices/OrderInventoryService/server/src/Entity/asset.js
/**
    * Method to create the asset.
    * @param productGrade: The grade of the product.
    * @param location: The location of the asset.
    * @param procurementPrice: The procurement price of the asset.
    * @param basePrice: The base price.
    * @param sellingPrice: The selling price.
    * @param attributesList: The list of attributes for the product.
    * @param jwToken: The user token, has to be a vendor.
    * @returns {Promise<Array>}: The response code and the response.
    */
Method to create the asset.
@param productGrade: The grade of the product.
@param location: The location of the asset.
@param procurementPrice: The procurement price of the asset.
@param basePrice: The base price.
@param sellingPrice: The selling price.
@param attributesList: The list of attributes for the product.
@param jwToken: The user token, has to be a vendor.
@returns {Promise}: The response code and the response.
Method to create the asset . @param productGrade : The grade of the product . @param location : The location of the asset . @param procurementPrice : The procurement price of the asset . @param basePrice : The base price . @param sellingPrice : The selling price . @param attributesList : The list of attributes for the product . @param jwToken : The user token has to be a vendor . @returns { Promise } : The response code and the response .
createAsset(productGrade, location, procurementPrice, basePrice, sellingPrice, attributesList, jwToken) {
      return new Promise(async (resolve, reject) => {
         try {
            const userData = await utils.validateUserToken(jwToken);
            if (validators.validateUndefined(userData) && userData[constants.ID] > 0 &&
               utils.checkWhetherRoleExists(userData[constants.ROLES], constants.ROLE_VENDOR_ID)) {
               this._assetUniqueNumber = validators.validateString(this._assetUniqueNumber) ?
                  this._assetUniqueNumber : generators.generateRandomToken(16);
               database.runSp(constants.SP_CREATE_ASSET, [this._assetName, this._assetUniqueNumber,
                  this._category, this._subCategory, this._sku, this._manufacturer,
                  validators.validateString(productGrade) ? productGrade : false,
                  validators.validateString(location) ? location : false, userData[constants.ID],
                  procurementPrice, validators.validateNumber(basePrice) ? basePrice : false,
                  sellingPrice, JSON.stringify(attributesList)]).then(_resultSet => {
                  const result = _resultSet[0][0];
                  resolve([constants.RESPONSE_SUCESS_LEVEL_1, result]);
               }).catch(err => {
                  printer.printError(err);
                  reject([constants.ERROR_LEVEL_3, constants.ERROR_MESSAGE]);
               });
            } else {
               reject([constants.ERROR_LEVEL_4, constants.FORBIDDEN_MESSAGE]);
            }
         } catch (e) {
            printer.printError(e);
            reject([constants.ERROR_LEVEL_3, constants.ERROR_MESSAGE]);
         }
      });
   }
createAsset ( productGrade , location , procurementPrice , basePrice , sellingPrice , attributesList , jwToken ) { return new Promise ( async ( resolve , reject ) => { try { const userData = await utils . validateUserToken ( jwToken ) ; if ( validators . validateUndefined ( userData ) && userData [ constants . ID ] > 0 && utils . checkWhetherRoleExists ( userData [ constants . ROLES ] , constants . ROLE_VENDOR_ID ) ) { this . _assetUniqueNumber = validators . validateString ( this . _assetUniqueNumber ) ? this . _assetUniqueNumber : generators . generateRandomToken ( 16 ) ; database . runSp ( constants . SP_CREATE_ASSET , [ this . _assetName , this . _assetUniqueNumber , this . _category , this . _subCategory , this . _sku , this . _manufacturer , validators . validateString ( productGrade ) ? productGrade : false , validators . validateString ( location ) ? location : false , userData [ constants . ID ] , procurementPrice , validators . validateNumber ( basePrice ) ? basePrice : false , sellingPrice , JSON . stringify ( attributesList ) ] ) . then ( _resultSet => { const result = _resultSet [ 0 ] [ 0 ] ; resolve ( [ constants . RESPONSE_SUCESS_LEVEL_1 , result ] ) ; } ) . catch ( err => { printer . printError ( err ) ; reject ( [ constants . ERROR_LEVEL_3 , constants . ERROR_MESSAGE ] ) ; } ) ; } else { reject ( [ constants . ERROR_LEVEL_4 , constants . FORBIDDEN_MESSAGE ] ) ; } } catch ( e ) { printer . printError ( e ) ; reject ( [ constants . ERROR_LEVEL_3 , constants . ERROR_MESSAGE ] ) ; } } ) ; }
Method to create the asset.
Method to create the asset .