Best JavaScript code snippet using wpt
client.js
Source:client.js
1// pages/client/client.js2var util = require('../../utils/util.js')3//è·ååºç¨å®ä¾4var app = getApp()5var vm = null6//ä¸ä»çnavbaræ ·å¼7var zj_navbar = [{8 value: "zj0",9 name: "æçæ¥å¤"10}, {11 value: "zj1",12 name: "å·²æ¥å¤"13}, {14 value: "zj2",15 name: "å·²å°è®¿"16}, {17 value: "zj3",18 name: "å·²æ交"19}, {20 value: "zj4",21 name: "å·²ç¾çº¦"22}, {23 value: "zj5",24 name: "å
¨æ¬¾å°è´¦"25}, {26 value: "zj6",27 name: "å¯ç»ç®"28}, {29 value: "zj7",30 name: "å·²ç»ç®"31}];32//æ¡åºè´è´£äººçnavbaræ ·å¼33var ac_navbar = [{34 value: "ac0",35 name: "å¾
æ¥æ¶"36}, {37 value: "ac1",38 name: "å¾
å°è®¿"39}, {40 value: "ac2",41 name: "å¾
æ交"42}, {43 value: "ac3",44 name: "å¾
ç¾çº¦"45}, {46 value: "ac4",47 name: "å¾
å
¨æ¬¾å°è´¦"48}, {49 value: "ac5",50 name: "å
¨æ¬¾å·²å°è´¦"51}, {52 value: "ac6",53 name: "å¾
确认"54}, {55 value: "ac7",56 name: "已确认"57}];58//æç´¢æ¥å£è°ç¨åæ°59var search_param = {60 page: 161}62var reload_flag = true; //éæ°å 载楼çæ°ç»æ å¿63var set_role = "0"; //è§è²è®¾å® 0ï¼ä¸ä» 1ï¼æ¡åºè´è´£äºº64Page({65 /**66 * 页é¢çåå§æ°æ®67 */68 data: {69 currentTab: 0, //å½åç¹å»çtabé项70 userInfo: {}, //ç¨æ·ç¼åä¿¡æ¯71 navbar: [], //顶é¨å¯¼èª72 hidden: "", //页é¢éè73 no_view_hidden: "hidden", //æªæ£ç´¢å°æ°æ®çæ示页é¢74 baobeis: [], //æ¥å¤å表75 houses: [], //å
¨é¨æ¥¼çå表ï¼ç¨äºé项å¼76 house: "", //éå®ç楼ç77 start_time: "", //å¼å§æ¥æ78 end_time: "" //ç»ææ¥æ79 },80 /**81 * çå½å¨æå½æ°--çå¬é¡µé¢å è½½82 */83 onLoad: function(options) {84 vm = this;85 //å è½½å
¨é¨æ¥¼ç86 vm.getHouseList(); //æ索楼ç87 vm.reloadPage(); //å·æ°é¡µé¢88 },89 //设置头é¨å¯¼èªæ¡90 setNavTab: function(e) {91 //ä¸ä»92 if (set_role == "0") {93 vm.setData({94 navbar: zj_navbar95 });96 }97 //ç½®ä¸é¡¾é®98 if (set_role == "1") {99 vm.setData({100 navbar: ac_navbar101 });102 }103 },104 //è¿è¡åå°æ°æ®è·å105 getDatasFromSrv: function(e) {106 console.log("set_role:" + set_role);107 //ä¸ä»108 if (set_role == "0") {109 vm.getListForZJByStatus();110 }111 //ç½®ä¸é¡¾é®112 if (set_role == "1") {113 vm.getListForACByStatus();114 }115 },116 //è·åä¸ä»ç»´åº¦çæ¥å¤å表117 getListForZJByStatus: function(e) {118 util.getListForZJByStatus(search_param, function(res) {119 console.log("getListForZJByStatus res:" + JSON.stringify(res))120 var baobeis_arr = [];121 if (!reload_flag) { //å¦æä¸æ¯éæ°å è½½ï¼è®¾ç½®houses_arr为ç°æçvm.data.houses122 baobeis_arr = vm.data.baobeis;123 }124 reload_flag = false;125 var msgObj = res.data.ret.data;126 console.log("msgObj.length length:" + msgObj.length);127 for (var i = 0; i < msgObj.length; i++) {128 msgObj[i] = util.setBaobeiInfo(msgObj[i]);129 baobeis_arr.push(msgObj[i]);130 }131 console.log("after set msgObj:" + JSON.stringify(msgObj));132 vm.setData({133 baobeis: baobeis_arr134 });135 //æ¯å¦å±ç¤ºæªæ¾å°æ¥¼ççæ示136 if (vm.data.baobeis.length == 0) {137 vm.setData({138 no_view_hidden: ""139 })140 } else {141 vm.setData({142 no_view_hidden: "hidden"143 })144 }145 search_param.page = search_param.page + 1; //页é¢å¢å 146 wx.stopPullDownRefresh();147 }, function(res) {})148 },149 //è·åæ¡åºè´è´£äººç»´åº¦çæ¥å¤å表150 getListForACByStatus: function(e) {151 util.getListForACByStatus(search_param, function(res) {152 console.log("getListForZJByStatus res:" + JSON.stringify(res))153 var baobeis_arr = [];154 if (!reload_flag) { //å¦æä¸æ¯éæ°å è½½ï¼è®¾ç½®houses_arr为ç°æçvm.data.houses155 baobeis_arr = vm.data.baobeis;156 }157 reload_flag = false;158 var msgObj = res.data.ret.data;159 console.log("msgObj.length length:" + msgObj.length);160 for (var i = 0; i < msgObj.length; i++) {161 msgObj[i] = util.setBaobeiInfo(msgObj[i]);162 baobeis_arr.push(msgObj[i]);163 }164 console.log("after set msgObj:" + JSON.stringify(msgObj));165 vm.setData({166 baobeis: baobeis_arr167 });168 //æ¯å¦å±ç¤ºæªæ¾å°æ¥¼ççæ示169 if (vm.data.baobeis.length == 0) {170 vm.setData({171 no_view_hidden: ""172 })173 } else {174 vm.setData({175 no_view_hidden: "hidden"176 })177 }178 search_param.page = search_param.page + 1; //页é¢å¢å 179 wx.stopPullDownRefresh();180 }, function(res) {})181 },182 //è·å楼çå表183 getHouseList: function() {184 util.house_getListByCon({185 "level": "0",186 "page_size": 100187 }, function(res) {188 console.log("getHouseList res:" + JSON.stringify(res))189 var msgObj = res.data.ret.data190 console.log("msgObj.length length:" + msgObj.length);191 vm.setData({192 houses: msgObj193 });194 })195 },196 //éæ©æ¥¼ç197 setHouseOption: function(e) {198 console.log("setHouseOption e:" + JSON.stringify(e))199 var id = e.detail.value;200 var houses = vm.data.houses201 vm.setData({202 house: houses[id]203 })204 //è¿è¡æ¥å¤ä¿¡æ¯æ£ç´¢205 search_param.house_id = vm.data.house.id;206 reload_flag = true;207 search_param.page = 1;208 console.log("setHouseOption search_param:" + JSON.stringify(search_param));209 vm.getDatasFromSrv();210 },211 //éæ©å¼å§æ¶é´212 setStartTime: function(e) {213 console.log("setStartTime e:" + JSON.stringify(e))214 vm.setData({215 start_time: e.detail.value216 })217 search_param.start_time = vm.data.start_time;218 reload_flag = true;219 search_param.page = 1;220 vm.getDatasFromSrv();221 },222 //éæ©ç»ææ¶é´223 setEndTime: function(e) {224 console.log("setEndTime e:" + JSON.stringify(e))225 vm.setData({226 end_time: e.detail.value227 })228 search_param.end_time = vm.data.end_time;229 reload_flag = true;230 search_param.page = 1;231 vm.getDatasFromSrv();232 },233 /**234 * çå½å¨æå½æ°--çå¬é¡µé¢å次渲æå®æ235 */236 onReady: function() {237 },238 /**239 * çå½å¨æå½æ°--çå¬é¡µé¢æ¾ç¤º240 */241 onShow: function() {242 },243 // ç¹å»æ é¢åæ¢å½å页æ¶æ¹åæ ·å¼244 switchNav: function(e) {245 console.log('switchNav e:' + JSON.stringify(e));246 search_param.page = 1;247 var cur = e.currentTarget.dataset.current;248 if (vm.data.current_tab == cur) {249 return false;250 } else {251 this.setData({252 currentTab: cur253 })254 //ä¸ä»255 if (set_role == "0") {256 switch (cur) {257 case 0: //æçæ¥å¤258 delete search_param.baobei_status;259 delete search_param.can_jiesuan_status;260 delete search_param.pay_zhongjie_status;261 break;262 case 1: //å·²æ¥å¤263 search_param.baobei_status = "0";264 delete search_param.can_jiesuan_status;265 delete search_param.pay_zhongjie_status;266 break;267 case 2: //å·²å°è®¿268 search_param.baobei_status = "1";269 delete search_param.can_jiesuan_status;270 delete search_param.pay_zhongjie_status;271 break;272 case 3: //å·²æ交273 search_param.baobei_status = "2";274 delete search_param.can_jiesuan_status;275 delete search_param.pay_zhongjie_status;276 break;277 case 4: //å·²ç¾çº¦278 search_param.baobei_status = "3";279 delete search_param.can_jiesuan_status;280 delete search_param.pay_zhongjie_status;281 break;282 case 5: //å
¨æ¬¾å°è´¦283 search_param.baobei_status = "4";284 delete search_param.can_jiesuan_status;285 delete search_param.pay_zhongjie_status;286 break;287 case 6: //å¯ç»ç®288 search_param.can_jiesuan_status = "1";289 delete search_param.baobei_status;290 delete search_param.pay_zhongjie_status;291 break;292 case 7: //å·²ç»ç®293 search_param.pay_zhongjie_status = "1";294 delete search_param.baobei_status;295 delete search_param.can_jiesuan_status;296 break;297 }298 }299 //æ¡åºè´è´£äºº300 if (set_role == "1") {301 switch (cur) {302 case 0: //å¾
æ¥æ¶303 delete search_param.baobei_status;304 delete search_param.can_jiesuan_status;305 delete search_param.pay_zhongjie_status;306 break;307 case 1: //å¾
å°è®¿308 search_param.baobei_status = "0";309 delete search_param.can_jiesuan_status;310 delete search_param.pay_zhongjie_status;311 break;312 case 2: //å¾
æ交313 search_param.baobei_status = "1";314 delete search_param.can_jiesuan_status;315 delete search_param.pay_zhongjie_status;316 break;317 case 3: //å¾
ç¾çº¦318 search_param.baobei_status = "2";319 delete search_param.can_jiesuan_status;320 delete search_param.pay_zhongjie_status;321 break;322 case 4: //å¾
å
¨æ¬¾å°è´¦323 search_param.baobei_status = "3";324 delete search_param.can_jiesuan_status;325 delete search_param.pay_zhongjie_status;326 break;327 case 5: //å
¨æ¬¾å·²å°è´¦328 search_param.baobei_status = "4";329 delete search_param.can_jiesuan_status;330 delete search_param.pay_zhongjie_status;331 break;332 case 6: //å¾
确认333 search_param.can_jiesuan_status = "0";334 delete search_param.baobei_status;335 delete search_param.pay_zhongjie_status;336 break;337 case 7: //已确认338 search_param.can_jiesuan_status = "1";339 delete search_param.baobei_status;340 delete search_param.can_jiesuan_status;341 break;342 }343 }344 reload_flag = true;345 search_param.page = 1;346 vm.getDatasFromSrv();347 }348 },349 //ç¹å»è¿è¡æ¥å¤æä½350 clickBaobeiOpt: function(e) {351 console.log("clickBaobeiOpt e:" + JSON.stringify(e));352 var id = e.currentTarget.dataset.id;353 var baobei_status = e.currentTarget.dataset.baobeistatus;354 //ä¸ä»åªå
许æä½å°è®¿åçç¶æ355 if (set_role == "0" && baobei_status != "0") {356 util.showModal("æ示信æ¯", "ä¸ä»åªå
许æä½å·²æ¥å¤ç¶æçè®°å½", function(ret) {}, function(ret) {});357 return;358 }359 var param = {360 id: id,361 set_role: set_role362 }363 wx.navigateTo({364 url: '/pages/client/baobeiOpt/baobeiOpt?jsonStr=' + JSON.stringify(param),365 })366 },367 /**368 * çå½å¨æå½æ°--çå¬é¡µé¢éè369 */370 onHide: function() {371 },372 /**373 * çå½å¨æå½æ°--çå¬é¡µé¢å¸è½½374 */375 onUnload: function() {376 },377 /**378 * 页é¢ç¸å
³äºä»¶å¤çå½æ°--çå¬ç¨æ·ä¸æå¨ä½379 */380 onPullDownRefresh: function() {381 // set_role = null;382 vm.reloadPage();383 },384 //éæ°å è½½æ°æ®å页é¢-ç¨äºé¡µé¢onLoadåä¸æå·æ°çåºæ¯385 reloadPage: function(e) {386 vm.setData({387 house: "", //éå®ç楼ç388 start_time: "", //å¼å§æ¥æ389 end_time: "", //ç»ææ¥æ390 currentTab: 0, //设置å½åçtab为第ä¸ä¸ª391 userInfo: util.getLocalUserInfo() //设置ç¨æ·ç¼å392 })393 394 //å
¼å®¹æ¡åºè´è´£äººåæ¢èº«ä»½ï¼set_roleåå§å为nullï¼è¿æ ·é¦æ¬¡å è½½çåºæ¯å³åå§åset_role395 if (util.judgeIsAnyNullStr(set_role)) {396 set_role = vm.data.userInfo.role; //设å®ç¨æ·è§è²397 }398 vm.setNavTab(); //设置导èªtab399 search_param = {400 page: 1401 }402 reload_flag = true;403 vm.getDatasFromSrv();404 },405 //æ¡åºè´è´£äººåæ¢è§è²406 clickSwitchRole: function(e) {407 console.log("clickSwitchRole e:" + JSON.stringify(e));408 //å¦æset_role为1ï¼ååæ¢ä¸º0409 if (set_role == "0") {410 util.showModal("åæ¢èº«ä»½", "åæ¢ä¸ºæ¡åºè´è´£äºº", function(ret) {411 set_role = "1";412 vm.reloadPage();413 }, null)414 } else {415 util.showModal("åæ¢èº«ä»½", "åæ¢ä¸ºä¸ä»", function(ret) {416 set_role = "0";417 vm.reloadPage();418 }, null)419 }420 },421 //æ¸
空åæ°422 clearParam: function() {423 reload_flag = true;424 search_param = {425 page: 1,426 }427 vm.setData({428 search_word: "",429 house: "", //éå®ç楼ç430 start_time: "", //å¼å§æ¥æ431 end_time: "" //ç»ææ¥æ432 })433 },434 /**435 * 页é¢ä¸æ触åºäºä»¶çå¤çå½æ°436 */437 onReachBottom: function() {438 console.log("onReachBottom search_param:" + JSON.stringify(search_param));439 vm.getDatasFromSrv(); //å è½½æ´å¤çæ¥å¤ä¿¡æ¯440 },441 /**442 * ç¨æ·ç¹å»å³ä¸è§å享443 */444 onShareAppMessage: function() {445 }...
selHouse.js
Source:selHouse.js
1// pages/baobei/selHouse/selHouse.js2var util = require('../../../utils/util.js')3var app = getApp()4var vm = null5//æç´¢æ¥å£è°ç¨åæ°6var search_param = {7 page: 1,8 level: '1'9}10var reload_flag = true; //éæ°å 载楼çæ°ç»æ å¿11Page({12 /**13 * 页é¢çåå§æ°æ®14 */15 data: {16 systemInfo: {}, //ç³»ç»ä¿¡æ¯17 houses: [], //楼çå表信æ¯18 area_text: "å
¨é¨åºå",19 type_text: "å
¨é¨ç±»å",20 label_text: "å
¨é¨æ ç¾",21 no_view_hidden: "hidden",22 search_word: "",23 },24 /**25 * çå½å¨æå½æ°--çå¬é¡µé¢å è½½26 */27 onLoad: function(options) {28 vm = this;29 search_param = {30 page: 1,31 level: '1'32 }33 },34 /**35 * çå½å¨æå½æ°--çå¬é¡µé¢å次渲æå®æ36 */37 onReady: function() {38 },39 /**40 * çå½å¨æå½æ°--çå¬é¡µé¢æ¾ç¤º41 */42 onShow: function() {43 vm = this44 //åå§åsysInfo45 app.getSystemInfo(function(res) {46 console.log("getSystemInfo:" + JSON.stringify(res));47 vm.setData({48 systemInfo: res49 })50 })51 util.showLoading('å è½½ä¸...');52 vm.getHouseList(); //æ索楼ç53 vm.getSearchOptions(); //è·åæ索楼çé项54 },55 //è·å楼çå表56 getHouseList: function() {57 util.house_getListByCon(search_param, function(res) {58 console.log("getHouseList res:" + JSON.stringify(res))59 var houses_arr = [];60 if (!reload_flag) { //å¦æä¸æ¯éæ°å è½½ï¼è®¾ç½®houses_arr为ç°æçvm.data.houses61 houses_arr = vm.data.houses;62 }63 reload_flag = false;64 var msgObj = res.data.ret.data;65 console.log("msgObj.length length:" + msgObj.length);66 for (var i = 0; i < msgObj.length; i++) {67 houses_arr.push(msgObj[i]);68 }69 vm.setData({70 houses: houses_arr71 });72 search_param.page = search_param.page + 1; //页é¢å¢å 73 wx.stopPullDownRefresh();74 //æ¯å¦å±ç¤ºæªæ¾å°æ¥¼ççæ示75 if (vm.data.houses.length == 0) {76 vm.setData({77 no_view_hidden: ""78 })79 } else {80 vm.setData({81 no_view_hidden: "hidden"82 })83 }84 search_param.page = search_param.page + 1; //页é¢å¢å 85 wx.stopPullDownRefresh();86 })87 },88 //è·å楼çæç´¢é项89 getSearchOptions: function() {90 util.getHouseOptions({}, function(ret) {91 // console.log("getSearchOptions" + JSON.stringify(ret))92 var area_option = ret.data.ret.area93 var type_option = ret.data.ret.type94 var label_option = ret.data.ret.label95 area_option.unshift({96 name: "å
¨é¨åºå"97 })98 type_option.unshift({99 name: "å
¨é¨ç±»å"100 })101 label_option.unshift({102 name: "å
¨é¨æ ç¾"103 })104 vm.setData({105 area_option: area_option,106 type_option: type_option,107 label_option: label_option,108 })109 })110 },111 //æ ¹æ®åºåæç´¢112 setAreaOption: function(e) {113 reload_flag = true;114 search_param.page = 1;115 console.log('pickeråééæ©æ¹åï¼æºå¸¦å¼ä¸º', e.detail.value)116 var id = e.detail.value;117 var area_option = vm.data.area_option118 if (id == 0) {119 delete search_param.area_id;120 } else {121 search_param.area_id = area_option[id].id;122 }123 vm.setData({124 area_text: area_option[id].name125 })126 console.log("search_param:" + JSON.stringify(search_param));127 util.showLoading('å è½½ä¸...');128 vm.getHouseList();129 },130 //æ ¹æ®ç±»åæç´¢131 setTypeOption: function(e) {132 reload_flag = true;133 search_param.page = 1;134 console.log('setTypeOption e:', e.detail.value)135 var id = e.detail.value;136 var type_option = vm.data.type_option137 if (id == 0) {138 delete search_param.type_id;139 } else {140 search_param.type_id = type_option[id].id;141 }142 vm.setData({143 type_text: type_option[id].name144 })145 console.log("search_param:" + JSON.stringify(search_param));146 util.showLoading('å è½½ä¸...');147 vm.getHouseList();148 },149 //æ ¹æ®ä»·æ ¼è¿è¡æç´¢150 setPriceOption: function(e) {151 reload_flag = true;152 search_param.page = 1;153 console.log('setPriceOption e:', e.detail.value)154 var id = e.detail.value;155 var price_option = vm.data.price_option156 if (id == 0) {157 delete search_param.price_min;158 delete search_param.price_max;159 } else {160 search_param.price_min = price_option[id].price_min;161 search_param.price_max = price_option[id].price_max;162 }163 console.log("search_param:" + JSON.stringify(search_param));164 util.showLoading('å è½½ä¸...');165 vm.getHouseList();166 },167 //æ ¹æ®æ ç¾æç´¢168 setLabelOption: function(e) {169 reload_flag = true;170 search_param.page = 1;171 console.log('setLabelOption e:', e.detail.value)172 var id = e.detail.value;173 var label_option = vm.data.label_option174 if (id == 0) {175 delete search_param.label_id;176 } else {177 search_param.label_id = label_option[id].id;178 }179 vm.setData({180 label_text: label_option[id].name181 })182 console.log("search_param:" + JSON.stringify(search_param));183 util.showLoading('å è½½ä¸...');184 vm.getHouseList();185 },186 // æ ¹æ®æ¥¼çidè·åæ¿æºä¿¡æ¯187 clickHouse: function(e) {188 console.log("clickHouse e:" + JSON.stringify(e))189 util.isNeedNavigateToSetMyInfoPage()190 var house_id = JSON.stringify(e.currentTarget.dataset.house_id)191 wx.navigateTo({192 url: '/pages/baobei/baobei?house_id=' + house_id193 })194 },195 //è¾å
¥æ¥¼çå称196 inputSearchWord: function(e) {197 console.log("inputRealName e:" + JSON.stringify(e));198 this.setData({199 search_word: e.detail.value200 })201 },202 //ç¹å»æç´¢ï¼è·³è½¬å°æ索页é¢203 clickSearch: function() {204 search_param.search_word = vm.data.search_word;205 search_param.page = 1;206 reload_flag = true;207 vm.getHouseList();208 },209 //éä¸æ¥¼ç210 selHouse: function(e) {211 console.log("selHouse e:" + JSON.stringify(e))212 var house = {213 title: e.currentTarget.dataset.housename,214 id: e.currentTarget.dataset.houseid,215 }216 var pages = getCurrentPages()217 var prePage = pages[pages.length - 2]218 prePage.setData({219 house: house220 })221 util.navigateBack(1);222 },223 //æ¸
空åæ°224 clearParam: function() {225 reload_flag = true;226 search_param = {227 page: 1,228 level: "1 "229 }230 vm.setData({231 search_word: "",232 area_text: "å
¨é¨åºå",233 type_text: "å
¨é¨ç±»å",234 label_text: "å
¨é¨æ ç¾",235 })236 },237 /**238 * çå½å¨æå½æ°--çå¬é¡µé¢éè239 */240 onHide: function() {241 },242 /**243 * çå½å¨æå½æ°--çå¬é¡µé¢å¸è½½244 */245 onUnload: function() {246 },247 /**248 * 页é¢ç¸å
³äºä»¶å¤çå½æ°--çå¬ç¨æ·ä¸æå¨ä½249 */250 onPullDownRefresh: function() {251 vm.clearParam();252 vm.getHouseList(); //æ索楼ç253 },254 /**255 * 页é¢ä¸æ触åºäºä»¶çå¤çå½æ°256 */257 onReachBottom: function() {258 console.log("onReachBottom page:" + search_param.page);259 vm.getHouseList(); //æ索楼ç260 },261 /**262 * ç¨æ·ç¹å»å³ä¸è§å享263 */264 onShareAppMessage: function() {265 }...
index.js
Source:index.js
1const express = require("express");2const app = express();3app.use(express.json());4const url = require("url");5const sls = require("serverless-http");6//Fetching model7const companyDetails = require("./model/companyDetails");8const orderDetails = require("./model/orderDetails");9//Database connection information10const db = require("./database");11//Making connection with the database12db.authenticate()13 .then(() => console.log("Connected To Database..."))14 .catch((err) => console.log("Error", err));15//Fetching details of all companies (R)16app.get("/listcompanies", async (req, res) => {17 await companyDetails18 .findAll()19 .then((result) => {20 res.status(200).json(result);21 })22 .catch((err) => {23 res.status(400).json(err);24 });25});26//Fetching details of a company (R)27app.get("/getcompany", async (req, res) => {28 const custom_url = new URL(29 req.protocol + "://" + req.get("host") + req.originalUrl30 );31 const search_param = custom_url.searchParams;32 if (JSON.stringify(req.query) === "{}") {33 res.status(404).json({34 message: "Please enter proper parameter",35 });36 } else if (37 search_param.has("cid") === false ||38 search_param.has("type") === false39 ) {40 res.status(404).json({41 message: "Please enter proper parameter",42 });43 } else if (req.query.cid === "" || req.query.type === "") {44 res.status(404).json({45 message: "Please enter proper parameter",46 });47 } else {48 await companyDetails49 .findOne({ where: { C_ID: req.query.cid, Type: req.query.type } })50 .then((result) => {51 res.status(200).json(result);52 })53 .catch((err) => {54 res.status(400).json(err);55 });56 }57});58//Fetching details of all oreders (R)59app.get("/listorders", async (req, res) => {60 await orderDetails61 .findAll()62 .then((result) => {63 res.status(200).json(result);64 })65 .catch((err) => {66 res.status(400).json(err);67 });68});69//Adding a new company (C)70app.post("/addcompany", async (req, res) => {71 const custom_url = new URL(72 req.protocol + "://" + req.get("host") + req.originalUrl73 );74 const search_param = custom_url.searchParams;75 if (JSON.stringify(req.query) === "{}") {76 res.status(404).json({77 message: "Please enter proper parameter",78 });79 } else if (80 search_param.has("cid") === false ||81 search_param.has("cname") === false ||82 search_param.has("type") === false ||83 search_param.has("price") === false ||84 search_param.has("driver") === false85 ) {86 res.status(404).json({87 message: "Please enter proper parameter",88 });89 } else if (90 req.query.cid === "" ||91 req.query.cname === "" ||92 req.query.type === "" ||93 req.query.price === "" ||94 req.query.driver === ""95 ) {96 res.status(404).json({97 message: "Please enter proper parameter",98 });99 } else {100 await companyDetails101 .create({102 C_ID: req.query.cid,103 C_Name: req.query.cname,104 Type: req.query.type,105 Price: req.query.price,106 Driver: req.query.driver,107 })108 .then((result) => {109 res.status(200).json({110 message: "New Company Added Successfully",111 });112 })113 .catch((err) => {114 res.status(400).json(err);115 });116 }117});118//Adding a new order (C)119app.post("/addorder", async (req, res) => {120 const custom_url = new URL(121 req.protocol + "://" + req.get("host") + req.originalUrl122 );123 const search_param = custom_url.searchParams;124 if (JSON.stringify(req.query) === "{}") {125 res.status(404).json({126 message: "Please enter proper parameter",127 });128 } else if (129 search_param.has("oid") === false ||130 search_param.has("username") === false ||131 search_param.has("email") === false ||132 search_param.has("address") === false ||133 search_param.has("cid") === false ||134 search_param.has("type") === false135 ) {136 res.status(404).json({137 message: "Please enter proper parameter",138 });139 } else if (140 req.query.oid === "" ||141 req.query.username === "" ||142 req.query.email === "" ||143 req.query.address === "" ||144 req.query.cid === "" ||145 req.query.type === ""146 ) {147 res.status(404).json({148 message: "Please enter proper parameter",149 });150 } else {151 await orderDetails152 .create({153 O_ID: req.query.oid,154 Username: req.query.username,155 Email: req.query.email,156 Address: req.query.address,157 C_ID: req.query.cid,158 Type: req.query.type,159 })160 .then((result) => {161 res.status(200).json({162 message: "New Order Added Successfully",163 });164 })165 .catch((err) => {166 res.status(400).json(err);167 });168 }169});170//Edit driver and rate of service (U)171app.post("/editcompany", async (req, res) => {172 const custom_url = new URL(173 req.protocol + "://" + req.get("host") + req.originalUrl174 );175 const search_param = custom_url.searchParams;176 if (JSON.stringify(req.query) === "{}") {177 res.status(404).json({178 message: "Please enter proper parameter",179 });180 } else if (181 search_param.has("cid") === false ||182 search_param.has("type") === false ||183 search_param.has("price") === false ||184 search_param.has("driver") === false185 ) {186 res.status(404).json({187 message: "Please enter proper parameter",188 });189 } else if (190 req.query.cid === "" ||191 req.query.type === "" ||192 req.query.price === "" ||193 req.query.driver === ""194 ) {195 res.status(404).json({196 message: "Please enter proper parameter",197 });198 } else {199 await companyDetails200 .update(201 {202 Price: req.query.price,203 Driver: req.query.driver,204 },205 {206 where: { C_ID: req.query.cid, Type: req.query.type },207 }208 )209 .then((result) => {210 if (result[0] === 1) {211 res.status(200).json({212 message: "Company Edited Successfully",213 });214 } else {215 res.status(400).json({216 message: "No such value exist",217 });218 }219 })220 .catch((err) => {221 res.status(400).json(err);222 });223 }224});225//Edit driver (U)226app.post("/editdriver", async (req, res) => {227 const custom_url = new URL(228 req.protocol + "://" + req.get("host") + req.originalUrl229 );230 const search_param = custom_url.searchParams;231 if (JSON.stringify(req.query) === "{}") {232 res.status(404).json({233 message: "Please enter proper parameter",234 });235 } else if (236 search_param.has("cid") === false ||237 search_param.has("type") === false ||238 search_param.has("driver") === false239 ) {240 res.status(404).json({241 message: "Please enter proper parameter",242 });243 } else if (244 req.query.cid === "" ||245 req.query.type === "" ||246 req.query.driver === ""247 ) {248 res.status(404).json({249 message: "Please enter proper parameter",250 });251 } else {252 await companyDetails253 .update(254 {255 Driver: req.query.driver,256 },257 {258 where: { C_ID: req.query.cid, Type: req.query.type },259 }260 )261 .then((result) => {262 if (result[0] === 1) {263 res.status(200).json({264 message: "Driver Edited Successfully",265 });266 } else {267 res.status(400).json({268 message: "No such value exist",269 });270 }271 })272 .catch((err) => {273 res.status(400).json(err);274 });275 }276});277//app.listen(3000, () => console.log(`Listening to port 3000...`));...
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {host: 'www.webpagetest.org'};3var wpt = new WebPageTest('www.webpagetest.org');4wpt.getLocations(function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11wpt.getTesters(function(err, data) {12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 }17});18wpt.getTestStatus('170516_1A_1a5b6c5a6a1a8a8e2b2c3b3a2a3a3a3', function(err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25wpt.getTestResults('170516_1A_1a5b6c5a6a1a8a8e2b2c3b3a2a3a3a3', function(err, data) {26 if (err) {27 console.log(err);28 } else {29 console.log(data);30 }31});32wpt.getTestResults('170516_1A_1a5b6c5a6a1a8a8e2b2c3b3a2a3a3a3', { requests: true }, function(err, data) {33 if (err) {34 console.log(err);35 } else {36 console.log(data);37 }38});39wpt.getTestResults('170516_1A_1a5b6c5a6a1a8a8e2b2c3b3a2a3a3a3', { requests: true, breakDown: true, pageSpeed: true }, function(err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46wpt.getTestResults('170516_1A_1a5b6c5a6a1a8a8e2b2c3b3a2a3a3a3', { requests: true, breakDown: true, pageSpeed: true, video: true }, function(err, data) {47 if (err) {48 console.log(err);
Using AI Code Generation
1var wptools = require('wptools');2var wp = wptools.page('Albert Einstein');3wp.get(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var wp = wptools.page('Albert Einstein');8wp.get(function(err, resp) {9 console.log(resp);10});
Using AI Code Generation
1var wpt = require('webpagetest');2var webpagetest = new wpt('API_KEY');3webpagetest.search_tests('test', function(err, data) {4 console.log(data);5});6var wpt = require('webpagetest');7var webpagetest = new wpt('API_KEY');8webpagetest.search_tests('test', function(err, data) {9 console.log(data);10});11var wpt = require('webpagetest');12var webpagetest = new wpt('API_KEY');13webpagetest.search_tests('test', function(err, data) {14 console.log(data);15});16var wpt = require('webpagetest');17var webpagetest = new wpt('API_KEY');18webpagetest.search_tests('test', function(err, data) {19 console.log(data);20});21var wpt = require('webpagetest');22var webpagetest = new wpt('API_KEY');23webpagetest.search_tests('test', function(err, data) {24 console.log(data);25});26var wpt = require('webpagetest');27var webpagetest = new wpt('API_KEY');28webpagetest.search_tests('test', function(err, data) {29 console.log(data);30});31var wpt = require('webpagetest');32var webpagetest = new wpt('API_KEY');33webpagetest.search_tests('test', function(err, data) {34 console.log(data);35});36var wpt = require('webpagetest');37var webpagetest = new wpt('API_KEY');38webpagetest.search_tests('test', function(err, data) {39 console.log(data);40});41var wpt = require('webpagetest');
Using AI Code Generation
1var wptools = require('wptools');2var search = new wptools.search('Barack Obama');3search.get(function(err, response) {4 console.log(response);5});6var wptools = require('wptools');7var search = new wptools.search('Barack Obama');8search.get(function(err, response) {9 console.log(response);10});11var wptools = require('wptools');12var search = new wptools.search('Barack Obama');13search.get(function(err, response) {14 console.log(response);15});16var wptools = require('wptools');17var search = new wptools.search('Barack Obama');18search.get(function(err, response) {19 console.log(response);20});21var wptools = require('wptools');22var search = new wptools.search('Barack Obama');23search.get(function(err, response) {24 console.log(response);25});26var wptools = require('wptools');27var search = new wptools.search('Barack Obama');28search.get(function(err, response) {29 console.log(response);30});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!