SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. api.route('/updateField')
  2.     .patch(async (req, res, next) => {
  3.         const customerID = res.locals.client;
  4.         const fieldID = req.query.fieldID;
  5.         const value = req.query.value;
  6.  
  7.         //Validation
  8.         if (!fieldID || !value) {
  9.             sendFailResponse(31, "A required parameter is missing.", res);
  10.         }
  11.         const mydb = mysql.new();
  12.         var qry = `flawed query i removed`;
  13.         mydb.query(qry, (err, data, fields) => {
  14.             if(err) {
  15.                 sendFailResponse(37, "Internal database error. Please contact Limble for assistance.", res);
  16.             }
  17.             else {
  18.                 switch (data[0].fieldTypeID) {
  19.                     case 1:
  20.                         //Text
  21.                         break;
  22.                     case 2:
  23.                         //Date
  24.                         sendFailResponse(43, "That fieldType is not currently supported in this call.", res);
  25.                         break;
  26.                     case 3:
  27.                         //Picture
  28.                         sendFailResponse(43, "That fieldType is not currently supported in this call.", res);
  29.                         break;
  30.                     case 4:
  31.                         //Document
  32.                         sendFailResponse(43, "That fieldType is not currently supported in this call.", res);
  33.                         break;
  34.                     case 5:
  35.                         //Number
  36.                         if(!parseInt(value)) {
  37.                             sendFailResponse(43, "That field requires a numerical value.", res);
  38.                         }
  39.                         break;
  40.                     case 6:
  41.                         //Currency
  42.                         sendFailResponse(43, "That fieldType is not currently supported in this call.", res);
  43.                         break;
  44.                     default:
  45.                         sendFailResponse(44, "An unexpected error occured. Please contact Limble for assistance", res);
  46.                 }
  47.             }
  48.         });
  49.  
  50.         //Execution
  51.         const bridge = new PHPBridge();
  52.         try {
  53.             await bridge.updateAssetField(
  54.                 customerID,
  55.                 fieldID,
  56.                 value
  57.             );
  58.             return sendSuccessResponse(res);
  59.         } catch(err) {
  60.             // TODO proper err message
  61.             return sendFailResponse(3, err.message, res);
  62.         }
  63.     })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top