server/src/Entity/customer.js
/**
    * Method to add images to s3 bucket.
    * @param imageData
    * @param imageType
    * @param fileExtension
    * @param position
    * @returns {Promise<unknown>}
    */
Method to add images to s3 bucket.
Method to add images to s3 bucket .
addImages(imageData, imageType, fileExtension, position) {
      return new Promise((resolve, reject) => {
         const imageKey = generator.generateRandomToken(16) + "." + fileExtension;
         const isSecure = (imageType === constants.IMAGE_TYPE_DOCUMENT);
         const baseUrl = (isSecure) ? constants.DOCUMENTS_BASE_URL : constants.IMAGES_BASE_URL;
         const imageUrl = baseUrl + imageKey;
         let promises = [];
         promises.push(s3Helper.uploadFile(imageData, imageKey, isSecure));
         promises.push(database.runSp(constants.SP_UPDATE_CUSTOMER_IMAGES,
            [imageType, imageKey, imageUrl, position, this._id]));
         Promise.all(promises).then(results => {
            resolve(imageUrl);
         }).catch(errs => {
            printer.printError(errs);
            reject(constants.ERROR_MESSAGE);
         });
      });
   }
addImages ( imageData , imageType , fileExtension , position ) { return new Promise ( ( resolve , reject ) => { const imageKey = generator . generateRandomToken ( 16 ) + "." + fileExtension ; const isSecure = ( imageType === constants . IMAGE_TYPE_DOCUMENT ) ; const baseUrl = ( isSecure ) ? constants . DOCUMENTS_BASE_URL : constants . IMAGES_BASE_URL ; const imageUrl = baseUrl + imageKey ; let promises = [ ] ; promises . push ( s3Helper . uploadFile ( imageData , imageKey , isSecure ) ) ; promises . push ( database . runSp ( constants . SP_UPDATE_CUSTOMER_IMAGES , [ imageType , imageKey , imageUrl , position , this . _id ] ) ) ; Promise . all ( promises ) . then ( results => { resolve ( imageUrl ) ; } ) . catch ( errs => { printer . printError ( errs ) ; reject ( constants . ERROR_MESSAGE ) ; } ) ; } ) ; }
Method to add images to s3 bucket.
Method to add images to s3 bucket .