Best JavaScript code snippet using argos
InterfaceAPI.js
Source:InterfaceAPI.js
1/**2 * Created by Benson on 2017/3/31.3 */4const _API = '/';5//æç« å表æ¥å£6export const ARTICLE = function (type,page,pageSize){7 const httpAPI = _API+'app/api/common/articles?type='+type+'&page='+page+'&pageSize='+pageSize;8 return httpAPI;9}10//æç« è¯¦æ
11export const ARTICLEDETAILS = function (id){12 const httpAPI = _API+'app/api/common/article/'+id;13 return httpAPI;14}15//è·åç¨æ·ç»ï¼ä¸»ç®¡å»çï¼16export const The_docGroup = function(authToken){17 const httpAPI = _API+'app/api/topThreeService/get/groupType';18 return {url:httpAPI,type:'GET',headers: {19 "authToken":authToken20 }};21}22//é£é©è¯ä¼°ï¼å表+æ£æï¼23export const The_risk_assessment = function(customerid,page,pageSize,authToken){24 const httpAPI = _API+'app/api/account/riskreport/infos?customerid='+customerid+'&iscustomer=true&page='+page+'&pageSize='+pageSize;25 return {url:httpAPI,type:'GET',headers: {26 "authToken":authToken27 }};28}29//å¥åº·ç®¡ç计åè¯ä¼°ï¼å表+æ£æï¼30export const the_health_managements = function(customerid,page,pageSize,authToken){31 const httpAPI = _API+'app/api/account/getHealthManagements?customerId='+customerid+'&page='+page+'&pageSize='+pageSize;32 return {url:httpAPI,type:'GET',headers: {33 "authToken":authToken34 },};35}36//æãå£åº¦æ¥åï¼åè¡¨ï¼ type=1 æ度 =2å£åº¦37export const getAutomationReport = function(type,page,pageSize,authToken){38 const httpAPI = _API+'app/api/account/getAutomationReport?type='+type+'&page='+page+'&pageSize='+pageSize;39 return {url:httpAPI,type:'GET',headers: {40 "authToken":authToken41 },};42}43//æå£è¯¦æ
44export const getAutomationReportDatil = function(end,start,authToken){45 const httpAPI = _API+'app/api/account/get/pic/sumReport?endDate='+end+'&startDate='+start;46 return {url:httpAPI,type:'GET',headers: {47 "authToken":authToken48 },};49}50//年度æ¥åï¼å表)51export const majordignosereport = function(customerid,page,pageSize,authToken){52 const httpAPI = _API+'app/api/account/majordignosereport/infos?customerid='+customerid+'&page='+page+'&pageSize='+pageSize;53 return {url:httpAPI,type:'GET',headers: {54 "authToken":authToken55 },};56}57//年度æ¥åï¼è¯¦æ
)58export const majordignosereportDatil = function(customerid,id,authToken){59 const httpAPI = _API+'app/api/doctor/health/info/dailyinfo/data/'+customerid+'?cusid='+customerid+'&repId='+id;60 return {url:httpAPI,type:'GET',headers: {61 "authToken":authToken62 }};63}64//ä¸è½½æ¥å65export const DownLoadRepot = function(id,authToken){66 const httpAPI = _API+'app/api/report/riskAssessment?id='+id;67 return {url:httpAPI,type:'GET',contentType:'application/octet-stream; charset=utf-8',headers: {68 "authToken":authToken69 }};70}71//ç¨æ·æ°æ®æ¥è¯¢ï¼è¡åï¼è¡ç³ãããï¼72export const UserData = function(dataType,endTime,startTime,page,pageSize,authToken){73 const httpAPI = _API+'app/api/account/health/check/infos?dataType='+dataType+'&endDate='+endTime+'&page='+page+'&pageSize='+pageSize+'&startDate='+startTime;74 return {url:httpAPI,type:'GET',headers: {75 "authToken":authToken76 },};77}78//ç¨æ·æ°æ®å¾æ æ¥è¯¢ï¼è¡åï¼è¡ç³ãããï¼79export const UserDataImg = function(dataType,endTime,startTime,authToken){80 const httpAPI = _API+'app/api/account/health/report?endDate='+endTime+'&startDate='+startTime+'&type='+dataType;81 return {url:httpAPI,type:'GET',headers: {82 "authToken":authToken83 }};84}85//æ°æ®é¢è§86export const UserHelDate = function (){87 const httpAPI = _API+'app/api/account/conversion/health/check/infos';88 return httpAPI;89}90//æ°æ®æ交91export const UserHelDatePost = function (){92 const httpAPI = _API+'app/api/account/health/check/infos';93 return httpAPI;94}95//å¥ç®¡å¸æé®å表ææ96export const ASKMList = function(page,pageSize,authToken){97 const httpAPI = _API+'app/api/common/health/advices?page='+page+'&pageSize='+pageSize;98 return {url:httpAPI,type:'GET',headers: {99 "authToken":authToken100 }};101}102//å¥ç®¡å¸æé®å表æç103export const ASKMListMy = function(page,pageSize,authToken){104 const httpAPI = _API+'app/api/account/health/advices?page='+page+'&pageSize='+pageSize;105 return {url:httpAPI,type:'GET',headers: {106 "authToken":authToken107 }};108}109//å¥ç®¡å¸æé®è¯¦æ
110export const ASKMDatile = function(page,pageSize,id,authToken){111 const httpAPI = _API+'app/api/consult/health/advice/'+id+'/replies?page='+page+'&pageSize='+pageSize;112 return {url:httpAPI,type:'GET',headers: {113 "authToken":authToken114 }};115}116//å¥ç®¡å¸æé®è¯¦æ
ï¼ç¨æ·åå¤117export const ASKMDatileUserInput = function(authToken){118 const httpAPI = _API+'app/api/consult/advice/reply';119 return {url:httpAPI,type:'POST',contentType : 'application/json',headers: {120 "authToken":authToken121 },error(rs){alert(rs.responseJSON.message)}};122}123//å¥ç®¡å¸æ交é®é¢124export const ASKMPost = function(authToken){125 const httpAPI = _API+'app/api/consult/advice';126 return {url:httpAPI,type:'POST',contentType : 'application/json',headers: {127 "authToken":authToken128 }};129}130//å»çæé®å表131export const ASKDOCList = function(page,pageSize,authToken){132 const httpAPI = _API+'app/api/account/health/consults?page='+page+'&pageSize='+pageSize;133 return {url:httpAPI,type:'GET',headers: {134 "authToken":authToken135 }};136}137//å»çæ交é®é¢138export const ASKDOCPost = function(authToken){139 const httpAPI = _API+'app/api/account/health/consult';140 return {url:httpAPI,type:'POST',contentType : 'application/json',headers: {141 "authToken":authToken142 },error(a,b,c){alert(a.responseJSON.message)}};143}144//å»çæé®è¯¦æ
145export const ASKDOCDatile = function(id,authToken){146 const httpAPI = _API+'app/api/account/health/consult/'+id147 return {url:httpAPI,type:'GET',headers: {148 "authToken":authToken149 }};150}151//è¯ä»·å»çå¨è¯¢152export const ASKDOCcommentPost = function(id,authToken){153 const httpAPI = _API+'app/api/account/health/consult/'+id+'/comment';154 return {url:httpAPI,contentType : 'application/json',headers: {155 "authToken":authToken156 }};157}158//é®å»çå表ä¸çå¢é159export const ASKDOCGetGroup = function(authToken){160 const httpAPI = _API+'app/api/account/health/groups';161 return {url:httpAPI,type:'GET',headers: {162 "authToken":authToken163 }};164}165//å©ä½è¯¢é®æ¬¡æ°166export const ASKTIME = function(authToken){167 const httpAPI = _API+'app/api/servicePackage/getCustomerServiceDetail';168 return {url:httpAPI,type:'GET',headers: {169 "authToken":authToken170 }};171}172//å¥åº·å¢éå表173export const HealthTeamList = function(page,pageSize,authToken){174 const httpAPI = _API+'app/api/account/query/health/groups?page='+page+'&pageSize='+pageSize;175 return {url:httpAPI,type:'GET',headers: {176 "authToken":authToken177 }};178}179//å¥åº·å¢é详æ
-A å¢é180export const HealthTeamGroup = function(id){181 const httpAPI = _API+'app/api/common/health/group/'+id;182 return {url:httpAPI,type:'GET'};183}184//å¥åº·å¢é详æ
-B å»ç185export const HealthTeamDoc = function(id){186 const httpAPI = _API+'app/api/common/health/group/'+id+'/doctors';187 return {url:httpAPI,type:'GET'};188}189//æ¥è¯¢å»ç详æ
190export const DocDatile = function(id){191 const httpAPI = _API+'app/api/common/doctor/'+id;192 return {url:httpAPI,type:'GET'};193}194//æ¥è¯¢å»çè¯ä»·195export const DocDatileComments = function(id){196 const httpAPI = _API+'app/api/common/doctor/'+id+'/comments';197 return {url:httpAPI,type:'GET'};198}199//è·åç份200export const GetProvinces = function(){201 const httpAPI = _API+'app/api/common/provinces';202 return {url:httpAPI,type:'GET'};203}204//è·ååå¸205export const GetCity = function(proID){206 const httpAPI = _API+'app/api/common/cities/province/'+proID;207 return {url:httpAPI,type:'GET'};208}209//个人ä¸å¿ 个人信æ¯210export const GETUserData = function(authToken){211 const httpAPI = _API+'app/api/account/get/customer/data';212 return {url:httpAPI,type:'GET',headers: {213 "authToken":authToken214 }};215}216//个人ä¸å¿ æ交个人信æ¯217export const POSTUserData = function(authToken){218 const httpAPI = _API+'app/api/account/update/customer/data';219 return {url:httpAPI,type:'POST',contentType : 'application/json',headers: {220 "authToken":authToken221 }};222}223//个人ä¸å¿ åºæ¬æ°æ®224export const GETUserBaseData = function(authToken){225 const httpAPI = _API+'app/api/account/get/customer/basic';226 return {url:httpAPI,type:'GET',headers: {227 "authToken":authToken228 }};229}230//个人ä¸å¿ æ交åºæ¬æ°æ®231export const POSTUserBaseData = function(authToken){232 const httpAPI = _API+'app/api/account/update/customer/basic';233 return {url:httpAPI,type:'POST',contentType : 'application/json',headers: {234 "authToken":authToken235 }};236}237//个人ä¸å¿ æ¢å¾ç
å²238export const GETUserHistory = function(authToken){239 const httpAPI = _API+'app/api/account/get/customer/history';240 return {url:httpAPI,type:'GET',headers: {241 "authToken":authToken242 }};243}244//个人ä¸å¿ æ交æ¢å¾ç
å²245export const POSTUserHistory = function(authToken){246 const httpAPI = _API+'app/api/account/update/customer/history';247 return {url:httpAPI,type:'POST',contentType : 'application/json',headers: {248 "authToken":authToken249 }};250}251//个人ä¸å¿ å é¤æ¢å¾ç
å²è®°å½252export const DelUserHistory = function(id,authToken){253 const httpAPI = _API+'app/api/common/delete/info?id='+id+'&type=1';254 return {url:httpAPI,type:'GET',contentType : 'application/json',headers: {255 "authToken":authToken256 }};257}258//个人ä¸å¿ è¯ç©259export const GETUserSituation = function(authToken){260 const httpAPI = _API+'app/api/account/get/customer/drug';261 return {url:httpAPI,type:'GET',headers: {262 "authToken":authToken263 }};264}265//个人ä¸å¿ è¯ç©å é¤266export const DelUserSituation = function(id,authToken){267 const httpAPI = _API+'app/api/common/delete/info?id='+id+'&type=0';268 return {url:httpAPI,type:'GET',headers: {269 "authToken":authToken270 }};271}272//个人ä¸å¿ è¯ç©å表 1è¯ç©å 2åå¦å273export const Getmedicine = function(type){274 const httpAPI = _API+'app/api/common/Medicine/names?type='+type;275 return {url:httpAPI,type:'GET'};276}277//个人ä¸å¿ è¯ç©åè¡¨æ ¹æ®å称è·å278export const GetmedicineByName = function(name){279 const httpAPI = _API+'app/api/common/Medicine/names?type=1&chemicalName='+name;280 return {url:httpAPI,type:'GET'};281}282//个人ä¸å¿ è¯ç©åå¦åæ ¹æ®å称è·å283export const GetmedicineHuaXueByName= function(name){284 const httpAPI = _API+'app/api/common/Medicine/names?type=2&name='+name;285 return {url:httpAPI,type:'GET'};286}287//个人ä¸å¿ è¯ç©æ交288export const PostUserSituation = function(authToken){289 const httpAPI = _API+'app/api/account/update/customer/drug';290 return {url:httpAPI,type:'POST',contentType : 'application/json',headers: {291 "authToken":authToken292 }};293}294//个人ä¸å¿ å»çäºä»¶295export const GETUserEvent = function(authToken){296 const httpAPI = _API+'app/api/account/get/customer/event';297 return {url:httpAPI,type:'GET',headers: {298 "authToken":authToken299 }};300}301//个人ä¸å¿ å»çäºä»¶ä¿®æ¹302export const PostUserEvent = function(authToken){303 const httpAPI = _API+'app/api/account/update/customer/event';304 return {url:httpAPI,type:'POST',contentType : 'application/json',headers: {305 "authToken":authToken306 }};307}308//ä¿®æ¹å¯ç 309export const changePWD = function(){310 const httpAPI = _API+'app/api/account/setting/password';311 return httpAPI312}313//个人ä¸å¿ æ¶æ¯å表 type=1æ¶æ¯ =2å
¬å314export const Getmessages = function(page,pageSize,type,authToken){315 const httpAPI = _API+'app/api/account/messages?isGuardian=false&page='+page+'&pageSize='+pageSize+'&type='+type;316 return {url:httpAPI,type:'GET',headers: {317 "authToken":authToken318 }};319}320export const GetmessagesByID = function(id,authToken,type){321 const httpAPI = _API+'app/api/account/message/'+id+'/type/'+type;322 return {url:httpAPI,type:'GET',headers: {323 "authToken":authToken324 }};325}326// æ 记已读327export const redmessages = function(authToken){328 const httpAPI = _API+'app/api/account/message/operate';329 return {url:httpAPI,type:'POST',contentType : 'application/json',headers: {330 "authToken":authToken331 }};332}333export const LoginAPI = function(){334 const httpAPI = _API+'app/api/account/login';335 return httpAPI;336}337//æªä½¿ç¨338export const LoginAPIYZM = function(){339 const httpAPI = _API+'captcha';340 return {url:httpAPI,type:'GET'};341}342export const LoginOutAPI = function(authToken){343 const httpAPI = _API+'app/api/account/logout';344 return {url:httpAPI,type:'POST',headers: {345 "authToken":authToken346 }};347}348export const fogetPWD = function(name,idNum){349 const httpAPI = _API+'app/api/common/getCustomerQuestion?idCardNumber='+idNum+'&username='+name;350 return {url:httpAPI,type:'GET'};351}352export const getCustomerSafeAnswer = function(id,safeAnswer){353 const httpAPI = _API+'app/api/common/getCustomerSafeAnswer?id='+id+'&safeAnswer='+safeAnswer;354 return {url:httpAPI,type:'GET'};355}356export const getCustomerPassword = function(id,password){357 const httpAPI = _API+'app/api/common/getCustomerPassword?id='+id+'&password='+password;358 return {url:httpAPI,type:'GET'};359}360//æªä½¿ç¨361export const protocol = function(){362 const httpAPI = _API+'app/api/common/protocol';363 return {url:httpAPI,type:'GET'};364}365//è·åæªè¯»æ¶æ¯ (type 2éç¥ãäºå¨æ»æ° 1æ¥ç¨ 3é®å»ç 8é®å¥åº·ç®¡çå¸) head使ç¨366export const getMessagesNoRead = (authToken,type)=>{367 const httpAPI = _API+'app/api/account/statistics/'+type;368 return {url:httpAPI,type:'GET',headers: {369 "authToken":authToken370 },error(){ sessionStorage.clear('userData');localStorage.clear();}};371}372//è·åæªè¯»æ¶æ¯ï¼type 1æ¶æ¯ 2å
¬åï¼373export const getMesNoRead = (authToken,type)=>{374 const httpAPI = _API+'app/api/account/message/new/count?type='+type;375 return {url:httpAPI,type:'GET',headers: {376 "authToken":authToken377 }};378}379//è·åäºä»¶380export const GETDateEvent = (authToken,endDate,startDate)=>{381 const httpAPI = _API+'app/api/schedule/month?endDate='+endDate+'&startDate='+startDate;382 return {url:httpAPI,type:'GET',headers: {383 "authToken":authToken384 }};385}386//è·åäºä»¶è¯¦æ
387export const GETDateEventDatile = (authToken,Date)=>{388 const httpAPI = _API+'app/api/schedule/day?date='+Date;389 return {url:httpAPI,type:'GET',headers: {390 "authToken":authToken391 }};392}393//ä¿®æ¹æ¥ç¨394export const EditDateEvent = (authToken)=>{395 const httpAPI = _API+'app/api/schedule/edit';396 return {url:httpAPI,type:'POST',contentType : 'application/json',headers: {397 "authToken":authToken398 }};399}400//æ°å»ºæ¥ç¨401export const NewDateEvent = (authToken)=>{402 const httpAPI = _API+'app/api/account/schedule';403 return {url:httpAPI,type:'POST',contentType : 'application/json',headers: {404 "authToken":authToken405 }};406}407//å é¤æ¥ç¨æ¶é´408export const DelDateEvent = (authToken,id)=>{409 const httpAPI = _API+'app/api/schedule/'+id;410 return {url:httpAPI,type:'DELETE',headers: {411 "authToken":authToken412 }};413}414//ç¨æ·èº«ä»½å¤æ ï¼ä¸ç²ï¼èåä¸ï¼415export const UserGroupType = (authToken)=>{416 const httpAPI = _API+'app/api/topThreeService/get/groupType';417 return {url:httpAPI,type:'GET',headers: {418 "authToken":authToken419 }};420}421//ä¸ç²ç¨æ·ä¸ªäººæ¹æ¡å表422export const UserTopThreeList = (userID,page,pageSize,authToken)=>{423 const httpAPI = _API+'app/api/account/getTopThreeHealthManagemenList?customerId='+userID+'&page='+page+'&pageSize='+pageSize;424 return {url:httpAPI,type:'GET',headers: {425 "authToken":authToken426 }};427}428//ä¸ç²ç¨æ·ä¸ªäººæ¹æ¡è¯¦æ
429export const UserTopThreeDatile = (ID,authToken)=>{430 const httpAPI = _API+'app/api/doctor/getTopThreeHealthManagement/'+ID;431 return {url:httpAPI,type:'GET',headers: {432 "authToken":authToken433 }};434}435//ä¸ç²ç¨æ·é访å表436export const UserTopThreeFUList = (page,authToken)=>{437 const httpAPI = _API+'app/api/topThreeService/get/topThreeServices?page='+page;438 return {url:httpAPI,type:'GET',headers: {439 "authToken":authToken440 }};441}442//è·åæçæå¡å表443export const GetService = (type,authToken)=>{444 const httpAPI = _API+'app/api/account/getMyService/'+type;445 return {url:httpAPI,type:'GET',async:false,headers: {446 "authToken":authToken447 }};448}449//åä¸é访å表450export const CerebralSList = (customerId,page,pageSize,authToken)=>{451 const httpAPI = _API+'app/api/strokeFollowUp/getStrokes?customerId='+customerId+"&page="+page+'&pageSize='+pageSize;452 return {url:httpAPI,type:'GET',async:false,headers: {453 "authToken":authToken454 }};455}456//åä¸é访详æ
457export const CerebralSDatile = (strokeFollowUpId,authToken)=>{458 const httpAPI = _API+'app/api/strokeFollowUp/getRecords?strokeFollowUpId='+strokeFollowUpId;459 return {url:httpAPI,type:'GET',async:false,headers: {460 "authToken":authToken461 }};462}463//æ è®°æ¥å已读464export const sendRead = (type,id,authToken)=>{465 const httpAPI = _API+'app/api/account/update/'+type+'/report/'+id;466 return {url:httpAPI,type:'post',async:false,headers: {467 "authToken":authToken468 }};469}470//ç¨æ·æ³¨å-æ£æµç¨æ·åæ¯å¦éå¤471export const registerCheckUserName = (userName)=>{472 const httpAPI = _API+'app/api/common/check/name/used?type=1&name='+userName;473 return {url:httpAPI,type:'get',async:false};474}475//ç¨æ·æ³¨å-æ£æµèº«ä»½è¯æ¯å¦éå¤476export const registerCheckregisterCheckUserName = (idCardNumber)=>{477 const httpAPI = _API+'app/api/common/check/idcard/used?idCardNumber='+idCardNumber;478 return {url:httpAPI,type:'get',async:true};479}480//ç¨æ·æ³¨å-åå¸æºææ¥è¯¢481export const registerCheckreGroup = (city,pr,page)=>{482 const httpAPI = _API+'app/api/common/health/findgroups?cityId='+city+'&page='+page+'&provinceId='+pr;483 return {url:httpAPI,type:'get',async:false};484}485//ç¨æ·æ³¨å-æ交信æ¯486export const register= ()=>{487 const httpAPI = _API+'app/api/account/register';488 return {url:httpAPI,type:'post',contentType:'application/json'};489}490//é®å»çï¼è¡¥å
èµæ491export const buchongtijiao= (id,authToken)=>{492 const httpAPI = _API+'app/api/account/health/consult/'+id;493 return {url:httpAPI,type:'post',contentType:'application/json',headers: {494 "authToken":authToken495 }};496}497//nmmp498export const chakannmmp= (id,authToken)=>{499 const httpAPI = _API+'app/api/account/health/check/info/'+id;500 return {url:httpAPI,type:'get',contentType:'application/json',headers: {501 "authToken":authToken502 }};503}504export const getyazm= ()=>{505 const httpAPI = _API+'captcha?' + Math.random();506 return httpAPI;507}508export const getOldLogin= ()=>{509 const httpAPI = 'http://'+window.location.host+'/index.html#/login';510 console.log(httpAPI);511 return httpAPI;512}513export const getOldCenter= ()=>{514 const httpAPI = _API+'index.html#/center';515 return httpAPI;516}517export const getDayPlan= (et, st, type)=>{518 const httpAPI = _API+'app/api/account/health/report?endDate='+et+"&startDate="+st+"&type="+type;519 return httpAPI;520}521export const getDownReport= (url, id)=>{522 const httpAPI = _API+'app/api/report/'+url+"?id="+id;523 return httpAPI;524}525export const getImg= (name)=>{526 const httpAPI = _API+'images/'+name+'.png';527 return httpAPI;528}529export const getDownCR= (name)=>{530 const httpAPI = _API+'index.html#/qr_code';531 return httpAPI;...
utils.js
Source:utils.js
1const domain = "http://localhost:8080";2export const login = (credential, asHost) => {3 const loginUrl = `${domain}/authenticate/${asHost ? "host" : "guest"}`;4 return fetch(loginUrl, {5 method: "POST",6 headers: {7 "Content-Type": "application/json",8 },9 body: JSON.stringify(credential),10 }).then((response) => {11 if (response.status !== 200) {12 throw Error("Fail to log in");13 }14 return response.json();15 });16};17export const register = (credential, asHost) => {18 const registerUrl = `${domain}/register/${asHost ? "host" : "guest"}`;19 return fetch(registerUrl, {20 method: "POST",21 headers: {22 "Content-Type": "application/json",23 },24 body: JSON.stringify(credential),25 }).then((response) => {26 if (response.status !== 200) {27 throw Error("Fail to register");28 }29 });30};31export const getReservations = () => {32 const authToken = localStorage.getItem("authToken");33 const listReservationsUrl = `${domain}/reservations`;34 return fetch(listReservationsUrl, {35 headers: {36 Authorization: `Bearer ${authToken}`,37 },38 }).then((response) => {39 if (response.status !== 200) {40 throw Error("Fail to get reservation list");41 }42 return response.json();43 });44};45export const getStaysByHost = () => {46 const authToken = localStorage.getItem("authToken");47 const listStaysUrl = `${domain}/stays/`;48 return fetch(listStaysUrl, {49 headers: {50 Authorization: `Bearer ${authToken}`,51 },52 }).then((response) => {53 if (response.status !== 200) {54 throw Error("Fail to get stay list");55 }56 return response.json();57 });58};59export const searchStays = (query) => {60 const authToken = localStorage.getItem("authToken");61 const searchStaysUrl = new URL(`${domain}/search/`);62 searchStaysUrl.searchParams.append("guest_number", query.guest_number);63 searchStaysUrl.searchParams.append(64 "checkin_date",65 query.checkin_date.format("YYYY-MM-DD")66 );67 searchStaysUrl.searchParams.append(68 "checkout_date",69 query.checkout_date.format("YYYY-MM-DD")70 );71 searchStaysUrl.searchParams.append("lat", 37);72 searchStaysUrl.searchParams.append("lon", -122);73 return fetch(searchStaysUrl, {74 headers: {75 Authorization: `Bearer ${authToken}`,76 },77 }).then((response) => {78 if (response.status !== 200) {79 throw Error("Fail to search stays");80 }81 return response.json();82 });83};84export const deleteStay = (stayId) => {85 const authToken = localStorage.getItem("authToken");86 const deleteStayUrl = `${domain}/stays/${stayId}`;87 return fetch(deleteStayUrl, {88 method: "DELETE",89 headers: {90 Authorization: `Bearer ${authToken}`,91 },92 }).then((response) => {93 if (response.status !== 200) {94 throw Error("Fail to delete stay");95 }96 });97};98export const bookStay = (data) => {99 const authToken = localStorage.getItem("authToken");100 const bookStayUrl = `${domain}/reservations`;101 return fetch(bookStayUrl, {102 method: "POST",103 headers: {104 Authorization: `Bearer ${authToken}`,105 "Content-Type": "application/json",106 },107 body: JSON.stringify(data),108 }).then((response) => {109 if (response.status !== 200) {110 throw Error("Fail to book reservation");111 }112 });113};114export const cancelReservation = (reservationId) => {115 const authToken = localStorage.getItem("authToken");116 const cancelReservationUrl = `${domain}/reservations/${reservationId}`;117 return fetch(cancelReservationUrl, {118 method: "DELETE",119 headers: {120 Authorization: `Bearer ${authToken}`,121 },122 }).then((response) => {123 if (response.status !== 200) {124 throw Error("Fail to cancel reservation");125 }126 });127};128export const getReservationsByStay = (stayId) => {129 const authToken = localStorage.getItem("authToken");130 const getReservationByStayUrl = `${domain}/stays/reservations/${stayId}`;131 return fetch(getReservationByStayUrl, {132 headers: {133 Authorization: `Bearer ${authToken}`,134 },135 }).then((response) => {136 if (response.status !== 200) {137 throw Error("Fail to get reservations by stay");138 }139 return response.json();140 });141};142export const uploadStay = (data) => {143 const authToken = localStorage.getItem("authToken");144 const uploadStayUrl = `${domain}/stays`;145 return fetch(uploadStayUrl, {146 method: "POST",147 headers: {148 Authorization: `Bearer ${authToken}`,149 },150 body: data,151 }).then((response) => {152 if (response.status !== 200) {153 throw Error("Fail to upload stay");154 }155 });...
imgur-auth.service.ts
Source:imgur-auth.service.ts
1import {Injectable} from '@angular/core';2import {AuthToken} from '../models/auth-token.model';3import {BehaviorSubject, Observable} from 'rxjs';4@Injectable({5 providedIn: 'root'6})7export class ImgurAuthService {8 static AUTH_TOKEN_STORAGE_KEY_NAME = 'imgur-auth-token';9 private _authTokenSubject: BehaviorSubject<AuthToken>;10 authToken$: Observable<AuthToken>;11 constructor() {12 const authToken = this._retrieveAuthDetails();13 this._authTokenSubject = new BehaviorSubject<AuthToken>(authToken);14 this.authToken$ = this._authTokenSubject.asObservable();15 }16 getCurrentAuthToken(): AuthToken {17 return this._authTokenSubject.getValue();18 }19 getAccessToken(): string {20 const authToken = this.getCurrentAuthToken();21 return authToken ? authToken.accessToken : null;22 }23 isLoggedIn(): boolean {24 const authToken: AuthToken = this.getCurrentAuthToken();25 return !!authToken && !authToken.isTokenExpired();26 }27 private _retrieveAuthDetails(): AuthToken {28 const storedToken = localStorage.getItem(ImgurAuthService.AUTH_TOKEN_STORAGE_KEY_NAME);29 if (!storedToken) {30 return null;31 }32 return AuthToken.buildFrom(JSON.parse(storedToken));33 }34 login(authToken: AuthToken): void {35 this._storeAuthDetails(authToken);36 }37 private _storeAuthDetails(authToken: AuthToken): void {38 if (!authToken || !authToken.accessToken) {39 return;40 }41 localStorage.setItem(ImgurAuthService.AUTH_TOKEN_STORAGE_KEY_NAME, JSON.stringify(authToken));42 this._authTokenSubject.next(authToken);43 }44 logout(): void {45 this._clearAuthDetails();46 this._authTokenSubject.next(null);47 }48 private _clearAuthDetails(): void {49 localStorage.removeItem(ImgurAuthService.AUTH_TOKEN_STORAGE_KEY_NAME);50 }...
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!!