Best JavaScript code snippet using wpt
PlayingCraftService.js
Source:PlayingCraftService.js
...8const headers = {9 Accept: 'application/json',10 ContentType: 'application/json',11};12function getRequestHeaders() {13 const state = store.getState();14 headers.Authorization = `Bearer ${state.user.token}`;15 return headers;16}17const generateUUID = async () => {18 return uuid.getRandomUUID();19};20const PlayingCraftService = {21 updateDeviceToken(device_token) {22 return axios.post(23 `${Env.APIURL}/api/profile/updateDeviceToken`,24 {25 device_token,26 },27 {28 headers: getRequestHeaders(),29 }30 );31 },32 getAllCrafts() {33 return axios.post(34 `${Env.APIURL}/api/playingCraft/getAllCrafts`,35 {},36 {37 headers: getRequestHeaders(),38 }39 );40 },41 deleteCraft(id) {42 return axios.post(43 `${Env.APIURL}/api/playingCraft/deleteCraft/${id}`,44 {},45 {46 headers: getRequestHeaders(),47 }48 );49 },50 clearCrafts() {51 // console.log('clear craft api', `${Env.APIURL}/api/playingCraft/clearEmptyCrafts`);52 return axios.post(53 `${Env.APIURL}/api/playingCraft/clearEmptyCrafts`,54 {},55 {56 headers: getRequestHeaders(),57 }58 );59 },60 addCraftToCart(item_id) {61 return axios.post(62 `${Env.APIURL}/api/playingCraft/addCraftToCart/${item_id}`,63 {},64 {65 headers: getRequestHeaders(),66 }67 );68 },69 removeCraftFromCart(item_id) {70 return axios.post(71 `${Env.APIURL}/api/playingCraft/removeCraftFromCart/${item_id}`,72 {},73 {74 headers: getRequestHeaders(),75 }76 );77 },78 addCraftToPurchase(item_id) {79 const resp = axios.post(80 `${Env.APIURL}/api/playingCraft/addCraftToPurchase/${item_id}`,81 {},82 {83 headers: getRequestHeaders(),84 }85 );86 // console.log(resp);87 return resp;88 },89 addCraftToWishlist(item_id) {90 return axios.post(91 `${Env.APIURL}/api/playingCraft/addCraftToWishlist/${item_id}`,92 {},93 {94 headers: getRequestHeaders(),95 }96 );97 },98 removeCraftFromWishlist(item_id) {99 return axios.post(100 `${Env.APIURL}/api/playingCraft/removeCraftFromWishlist/${item_id}`,101 {},102 {103 headers: getRequestHeaders(),104 }105 );106 },107 addComment(craft_id, comment_body, photo, mentioned_users) {108 return axios.post(109 `${Env.APIURL}/api/playingCraft/addComment/${craft_id}`,110 {111 comment_body,112 attach_url: photo,113 mentioned_users,114 },115 {116 headers: getRequestHeaders(),117 }118 );119 },120 replyComment(craft_id, comment_body, comment_id, photo, mentioned_users) {121 return axios.post(122 `${Env.APIURL}/api/playingCraft/replyComment/${craft_id}`,123 {124 comment_body,125 comment_id,126 attach_url: photo,127 mentioned_users,128 },129 {130 headers: getRequestHeaders(),131 }132 );133 },134 getCommentsReply(comment_id) {135 return axios.post(136 `${Env.APIURL}/api/playingCraft/getCommentsReply/${comment_id}`,137 {},138 {139 headers: getRequestHeaders(),140 }141 );142 },143 getComments(craft_id) {144 return axios.post(145 `${Env.APIURL}/api/playingCraft/getComments/${craft_id}`,146 {},147 {148 headers: getRequestHeaders(),149 }150 );151 },152 deleteComment(comment_id) {153 return axios.post(154 `${Env.APIURL}/api/playingCraft/deleteComment/${comment_id}`,155 {},156 {157 headers: getRequestHeaders(),158 }159 );160 },161 reportComment(comment_id) {162 return axios.post(163 `${Env.APIURL}/api/playingCraft/reportComment`,164 {165 // report_content: report_content,166 comment_id,167 },168 {169 headers: getRequestHeaders(),170 }171 );172 },173 reportCraft(report_content, craft_id) {174 return axios.post(175 `${Env.APIURL}/api/playingCraft/reportCraft`,176 {177 report_content,178 craft_id,179 },180 {181 headers: getRequestHeaders(),182 }183 );184 },185 getCommentReport() {186 return axios.post(187 `${Env.APIURL}/api/report/getCommentReport`,188 {},189 {190 headers: getRequestHeaders(),191 }192 );193 },194 getCraftReport() {195 return axios.post(196 `${Env.APIURL}/api/report/getCraftReport`,197 {},198 {199 headers: getRequestHeaders(),200 }201 );202 },203 removeCommentReport(report_id) {204 return axios.post(205 `${Env.APIURL}/api/report/removeCommentReport`,206 {207 report_id,208 },209 {210 headers: getRequestHeaders(),211 }212 );213 },214 removeCraftReport(report_id) {215 return axios.post(216 `${Env.APIURL}/api/report/removeCraftReport`,217 {218 report_id,219 },220 {221 headers: getRequestHeaders(),222 }223 );224 },225 getCraft(craft_id) {226 return axios.post(227 `${Env.APIURL}/api/playingCraft/getCraft/${craft_id}`,228 {},229 {230 headers: getRequestHeaders(),231 }232 );233 },234 getFiles(craft_id) {235 return axios.get(`${Env.APIURL}/api/playingCraft/${craft_id}/file`, {236 headers: getRequestHeaders(),237 });238 },239 deleteFile(craft_id, file_id) {240 return axios.delete(`${Env.APIURL}/api/playingCraft/${craft_id}/file/${file_id}`, {241 headers: getRequestHeaders(),242 });243 },244 joinStudioCraft(studio_id, craft_id) {245 console.log(246 'join studio',247 `${Env.APIURL}/api/studio-craft-join`,248 studio_id,249 craft_id,250 getRequestHeaders()251 );252 return axios.post(253 `${Env.APIURL}/api/studio-craft-join`,254 {255 studio_id,256 craft_id,257 },258 {259 headers: getRequestHeaders(),260 }261 );262 },263 setTitle(craft_id, title) {264 return axios.post(265 `${Env.APIURL}/api/playingCraft/setTitle/${craft_id}`,266 {267 craft_id,268 title,269 },270 {271 headers: getRequestHeaders(),272 }273 );274 },275 setHashTags(craft_id, hashTags) {276 return axios.post(277 `${Env.APIURL}/api/playingCraft/setHashTags/${craft_id}`,278 {279 hashTags: JSON.stringify(hashTags),280 },281 {282 headers: getRequestHeaders(),283 }284 );285 },286 setDescription(craft_id, description) {287 return axios.post(288 `${Env.APIURL}/api/playingCraft/setDescription/${craft_id}`,289 {290 description,291 },292 {293 headers: getRequestHeaders(),294 }295 );296 },297 setProductionDescription(craft_id, description) {298 return axios.post(299 `${Env.APIURL}/api/playingCraft/setProductionDescription/${craft_id}`,300 {301 description,302 },303 {304 headers: getRequestHeaders(),305 }306 );307 },308 setArtCategories(craft_id, categories) {309 return axios.post(310 `${Env.APIURL}/api/playingCraft/setArtCategories/${craft_id}`,311 {312 categories: JSON.stringify(categories),313 },314 {315 headers: getRequestHeaders(),316 }317 );318 },319 setMusicCategories(craft_id, categories) {320 return axios.post(321 `${Env.APIURL}/api/playingCraft/setMusicCategories/${craft_id}`,322 {323 categories: JSON.stringify(categories),324 },325 {326 headers: getRequestHeaders(),327 }328 );329 },330 setLyrics(craft_id, lyrics) {331 return axios.post(332 `${Env.APIURL}/api/playingCraft/setLyrics/${craft_id}`,333 {334 lyrics,335 },336 {337 headers: getRequestHeaders(),338 }339 );340 },341 addNewCraft(type = '1') {342 return axios.post(343 `${Env.APIURL}/api/playingCraft/addNewCraft`,344 {345 type,346 },347 {348 headers: getRequestHeaders(),349 }350 );351 },352 async uploadFile(url, type, name, craftId, onProgress, mainFile, uploadingArt) {353 const file = {354 // `uri` can also be a file system path (i.e. file://)355 uri: url,356 name,357 type,358 };359 console.log('file', file);360 const uuidName = await generateUUID();361 const key = `uploads/${moment().format('MM_DD_YYYY')}/${uuidName}`;362 console.log('file', key);363 return new Promise((resolve, reject) => {364 const options = {365 type: 'multipart',366 method: 'POST',367 headers: {368 'content-type': type, // server requires a content-type header369 },370 url: Env.S3URL,371 field: 'file',372 path: url,373 parameters: {374 ...S3Policy.generate({375 keyPrefix: 'uploads/',376 bucket: Env.bucket,377 region: Env.region,378 accessKey: Env.accessKey,379 secretKey: Env.secretKey,380 successActionStatus: 201,381 key,382 date: new Date(),383 contentType: type,384 }),385 },386 };387 let canReport = true;388 Upload.startUpload(options)389 .then(async (uploadId) => {390 // console.log(`options: ${options}`);391 if (typeof onProgress === 'function') {392 onProgress({393 id: uploadId,394 progress: 0,395 });396 }397 Upload.addListener('progress', uploadId, (data) => {398 console.log(`Progress: ${data.progress}%`);399 if (typeof onProgress === 'function' && canReport === true) {400 canReport = false;401 onProgress({402 id: uploadId,403 progress: data.progress,404 });405 setTimeout(() => (canReport = true), 500);406 }407 });408 Upload.addListener('error', uploadId, (data) => {409 console.log(`Error: ${data.error}`);410 reject();411 });412 Upload.addListener('cancelled', uploadId, (data) => {413 console.log(`Cancelled!`, data);414 reject();415 });416 Upload.addListener('completed', uploadId, (data) => {417 // data includes responseCode: number and responseBody: Object418 if (typeof onProgress === 'function') {419 onProgress({420 id: uploadId,421 progress: 100,422 });423 }424 console.log('data', data);425 const body = {426 files: [427 {428 url: key,429 filename: name,430 filetype: type.split('/')[0],431 },432 ],433 };434 console.log(body);435 axios436 .post(`${Env.APIURL}/api/playingCraft/${craftId}/file`, body, {437 headers: getRequestHeaders(),438 })439 .then((result) =>440 resolve({441 ...result,442 mainFile,443 uploadingArt,444 })445 );446 });447 })448 .catch((err) => {449 reject(err);450 });451 }).then((resp) => resp);452 },453 setCraftMedia(craft_id, filetype, url, filename, orientation) {454 return axios.post(455 `${Env.APIURL}/api/playingCraft/setCraftMedia/${craft_id}`,456 {457 type: filetype,458 filetype,459 url,460 filename,461 orientation,462 },463 {464 headers: getRequestHeaders(),465 }466 );467 },468 setCraftMediaPurchase(craft_id, purchase_id, type) {469 return axios.post(470 `${Env.APIURL}/api/playingCraft/${craft_id}/setCraftMedia/purchase/${purchase_id}`,471 {472 type,473 },474 {475 headers: getRequestHeaders(),476 }477 );478 },479 setCraftThumbnail(craft_id, url) {480 return axios.post(481 `${Env.APIURL}/api/playingCraft/setCraftThumbnail/${craft_id}`,482 {483 url,484 name,485 },486 {487 headers: getRequestHeaders(),488 }489 );490 },491 setStoreType(craft_id, type) {492 return axios.post(493 `${Env.APIURL}/api/playingCraft/setStoreType/${craft_id}`,494 {495 type,496 },497 {498 headers: getRequestHeaders(),499 }500 );501 },502 addCraftItem(503 craft_id,504 store_option,505 purchase_option,506 price,507 in_app_file,508 files_for_export,509 quantity,510 royalty,511 non_transformative_royalty,512 adversting,513 number_of_ads_allowed514 ) {515 console.log({516 store_option,517 purchase_option,518 price,519 quantity,520 royalty,521 non_transformative_royalty,522 adversting,523 number_of_ads_allowed,524 in_app_file,525 files_for_export,526 });527 const result = axios.post(528 `${Env.APIURL}/api/playingCraft/addCraftItem/${craft_id}`,529 {530 store_option,531 purchase_option,532 price,533 quantity,534 royalty,535 non_transformative_royalty,536 adversting,537 number_of_ads_allowed,538 in_app_file,539 files_for_export,540 },541 {542 headers: getRequestHeaders(),543 }544 );545 console.log(result);546 return result;547 },548 editCraftItem(craft_item_id, purchase_option, in_app_file, files_for_export, field, value) {549 console.log({550 purchase_option,551 in_app_file,552 files_for_export,553 field,554 value,555 });556 const result = axios.post(557 `${Env.APIURL}/api/playingCraft/editCraftItem/${craft_item_id}`,558 {559 purchase_option,560 in_app_file,561 files_for_export,562 field,563 value,564 },565 {566 headers: getRequestHeaders(),567 }568 );569 console.log(result);570 return result;571 },572 setWebsiteLink(craft_id, link) {573 return axios.post(574 `${Env.APIURL}/api/playingCraft/setWebsiteLink/`,575 {576 craft_id,577 link,578 },579 {580 headers: getRequestHeaders(),581 }582 );583 },584 browseLink(id) {585 return axios.post(586 `${Env.APIURL}/api/playingCraft/browseLink/${id}`,587 {},588 {589 headers: getRequestHeaders(),590 }591 );592 },593 cloneCraft(id) {594 return axios.post(595 `${Env.APIURL}/api/playingCraft/cloneCraft/${id}`,596 {},597 {598 headers: getRequestHeaders(),599 }600 );601 },602 replaceCraft(id, new_id) {603 return axios.post(604 `${Env.APIURL}/api/playingCraft/replaceCraft`,605 {606 id,607 new_id,608 },609 {610 headers: getRequestHeaders(),611 }612 );613 },614 publishCraft(id, is_public) {615 return axios.post(616 `${Env.APIURL}/api/playingCraft/publishCraft/${id}`,617 {618 is_public,619 },620 {621 headers: getRequestHeaders(),622 }623 );624 },625 likeCraft(id) {626 return axios.post(627 `${Env.APIURL}/api/profile/likeCraft/${id}`,628 {},629 {630 headers: getRequestHeaders(),631 }632 );633 },634 unlikeCraft(id) {635 return axios.post(636 `${Env.APIURL}/api/profile/unlikeCraft/${id}`,637 {},638 {639 headers: getRequestHeaders(),640 }641 );642 },643 getCraftLikes(id) {644 return axios.post(645 `${Env.APIURL}/api/playingCraft/getCraftLikes/${id}`,646 {},647 {648 headers: getRequestHeaders(),649 }650 );651 },652 likeComment(id) {653 // console.log('id', id);654 return axios.post(655 `${Env.APIURL}/api/profile/likeComment/${id}`,656 {},657 {658 headers: getRequestHeaders(),659 }660 );661 },662 unlikeComment(id) {663 return axios.post(664 `${Env.APIURL}/api/profile/unlikeComment/${id}`,665 {},666 {667 headers: getRequestHeaders(),668 }669 );670 },671 setFeaturedCraft(id) {672 return axios.post(673 `${Env.APIURL}/api/playingCraft/setFeaturedCraft/${id}`,674 {},675 {676 headers: getRequestHeaders(),677 }678 );679 },680 unsetFeaturedCraft(id) {681 return axios.post(682 `${Env.APIURL}/api/playingCraft/unsetFeaturedCraft/${id}`,683 {},684 {685 headers: getRequestHeaders(),686 }687 );688 },689 createContestCraft(id, title, description) {690 return axios.post(691 `${Env.APIURL}/api/playingCraft/createContestCraft/${id}`,692 {693 title,694 description,695 },696 {697 headers: getRequestHeaders(),698 }699 );700 },701 getSpotlightData(limit = 0) {702 return axios.post(703 `${Env.APIURL}/api/playingCraft/getSpotlightData`,704 { limit },705 {706 headers: getRequestHeaders(),707 }708 );709 },710 getUserCraft(id, limit = 0) {711 return axios.post(712 `${Env.APIURL}/api/playingCraft/getUserCraft/${id}`,713 {714 limit,715 },716 {717 headers: getRequestHeaders(),718 }719 );720 },721 getUserStore(id, limit = 0) {722 return axios.post(723 `${Env.APIURL}/api/playingCraft/getUserStore/${id}`,724 {725 limit,726 },727 {728 headers: getRequestHeaders(),729 }730 );731 },732 addCraftPlay(id) {733 return axios.post(734 `${Env.APIURL}/api/playingCraft/addCraftPlay/${id}`,735 {},736 {737 headers: getRequestHeaders(),738 }739 );740 },741 setStoreOwner(id, userid) {742 return axios.post(743 `${Env.APIURL}/api/playingCraft/setStoreOwner/${id}`,744 {745 userid,746 },747 {748 headers: getRequestHeaders(),749 }750 );751 },752 getGenre() {753 return axios.post(754 `${Env.APIURL}/api/playingCraft/getGenre`,755 {},756 {757 headers: getRequestHeaders(),758 }759 );760 },761 makePrivate(id) {762 return axios.patch(763 `${Env.APIURL}/api/playingCraft/makePrivate/${id}`,764 {},765 {766 headers: getRequestHeaders(),767 }768 );769 },770 makePublic(id) {771 return axios.patch(772 `${Env.APIURL}/api/playingCraft/makePublic/${id}`,773 {},774 {775 headers: getRequestHeaders(),776 }777 );778 },779 makeHidden(id) {780 return axios.patch(781 `${Env.APIURL}/api/playingCraft/makeHidden/${id}`,782 {},783 {784 headers: getRequestHeaders(),785 }786 );787 },788 makeVisible(id) {789 return axios.patch(790 `${Env.APIURL}/api/playingCraft/makeVisible/${id}`,791 {},792 {793 headers: getRequestHeaders(),794 }795 );796 },797};...
ProfileService.js
Source:ProfileService.js
...11};12const generateUUID = async () => {13 return uuid.getRandomUUID();14};15function getRequestHeaders() {16 const state = store.getState();17 headers.Authorization = `Bearer ${state.user.token}`;18 return headers;19}20const ProfileService = {21 notification_permission(notification_type, status) {22 return axios.post(23 `${Env.APIURL}/api/notification_permission`,24 {25 notification_type,26 status,27 },28 {29 headers: getRequestHeaders(),30 }31 );32 },33 // readmessages(){34 // return axios.post(`${Env.APIURL}/api/readmessages`, {}, {35 // headers: getRequestHeaders()36 // });37 // },38 checkReadNotifications() {39 return axios.post(40 `${Env.APIURL}/api/readnotifications`,41 {},42 {43 headers: getRequestHeaders(),44 }45 );46 },47 getUserProfile(id) {48 if (!id) {49 const error = {50 response: {51 data: {52 error: 'Using of the wrong user id',53 },54 },55 };56 return Promise.reject(error);57 }58 return axios.post(59 `${Env.APIURL}/api/profile/getUserProfile/${id}`,60 {},61 {62 headers: getRequestHeaders(),63 }64 );65 },66 getUserInfo(key) {67 return axios.post(68 `${Env.APIURL}/api/profile/getUserInfo`,69 {70 key,71 },72 {73 headers: getRequestHeaders(),74 }75 );76 },77 resendSms(id) {78 return axios.post(79 `${Env.APIURL}/api/profile/resendSms`,80 {81 id,82 },83 {84 headers: getRequestHeaders(),85 }86 );87 },88 changeForgotPassword(id, password) {89 return axios.post(90 `${Env.APIURL}/api/profile/changeForgotPassword`,91 {92 id,93 password,94 },95 {96 headers: getRequestHeaders(),97 }98 );99 },100 getFollow(id) {101 return axios.post(102 `${Env.APIURL}/api/profile/getFollow/${id}`,103 {},104 {105 headers: getRequestHeaders(),106 }107 );108 },109 follow(targetId) {110 return axios.post(111 `${Env.APIURL}/api/profile/follow/${targetId}`,112 {},113 {114 headers: getRequestHeaders(),115 }116 );117 },118 unFollow(targetId) {119 return axios.post(120 `${Env.APIURL}/api/profile/unfollow/${targetId}`,121 {},122 {123 headers: getRequestHeaders(),124 }125 );126 },127 updateProfile(profile) {128 return axios.post(129 `${Env.APIURL}/api/profile/updateUserProfile`,130 {131 bio: profile.bio,132 location: profile.location,133 website_url: profile.website_url,134 instagram_url: profile.instagram_url,135 facebook_url: profile.facebook_url,136 twitter_url: profile.twitter_url,137 snapchat_url: profile.snapchat_url,138 behance_url: profile.behance_url,139 linkedin_url: profile.linkedin_url,140 avatar: profile.avatar,141 usertype: profile.usertype,142 },143 {144 headers: getRequestHeaders(),145 }146 );147 },148 updateProfileAvatar(avatar) {149 return axios.post(150 `${Env.APIURL}/api/profile/updateUserProfile`,151 {152 avatar,153 },154 {155 headers: getRequestHeaders(),156 }157 );158 },159 changeUsername(username) {160 const state = store.getState();161 return axios.post(162 `${Env.APIURL}/api/profile/changeUsername`,163 {164 username,165 },166 {167 headers: getRequestHeaders(),168 }169 );170 },171 changePassword(password, newPassword) {172 return axios.post(173 `${Env.APIURL}/api/profile/changePassword`,174 {175 cur_password: password,176 new_password: newPassword,177 },178 {179 headers: getRequestHeaders(),180 }181 );182 },183 changePhone(phone) {184 return axios.post(185 `${Env.APIURL}/api/profile/changePhone`,186 {187 phone,188 },189 {190 headers: getRequestHeaders(),191 }192 );193 },194 changeEmail(email) {195 return axios.post(196 `${Env.APIURL}/api/profile/changeEmail`,197 {198 email,199 },200 {201 headers: getRequestHeaders(),202 }203 );204 },205 requestVerify(username, fullname, knownas, idphoto) {206 return axios.post(207 `${Env.APIURL}/api/profile/requestVerify`,208 {209 username,210 fullname,211 knownas,212 idphoto,213 },214 {215 headers: getRequestHeaders(),216 }217 );218 },219 getVerifyRequest() {220 return axios.get(`${Env.APIURL}/api/verification-request`, {221 headers: getRequestHeaders(),222 });223 },224 removeVerifyRequest(verification_request_id) {225 return axios.delete(`${Env.APIURL}/api/verification-request/${verification_request_id}`, {226 headers: getRequestHeaders(),227 });228 },229 verifyUser(user_id) {230 return axios.patch(231 `${Env.APIURL}/api/user/${user_id}/verify`,232 {},233 {234 headers: getRequestHeaders(),235 }236 );237 },238 unVerifyUser(user_id) {239 return axios.patch(240 `${Env.APIURL}/api/user/${user_id}/unverify`,241 {},242 {243 headers: getRequestHeaders(),244 }245 );246 },247 banUser(user_id) {248 return axios.patch(249 `${Env.APIURL}/api/user/${user_id}/ban`,250 {},251 {252 headers: getRequestHeaders(),253 }254 );255 },256 unBanUser(user_id) {257 return axios.patch(258 `${Env.APIURL}/api/user/${user_id}/unban`,259 {},260 {261 headers: getRequestHeaders(),262 }263 );264 },265 deleteUser(user_id) {266 return axios.delete(`${Env.APIURL}/api/user/${user_id}`, {267 headers: getRequestHeaders(),268 });269 },270 getBlock() {271 return axios.post(272 `${Env.APIURL}/api/profile/getBlock`,273 {},274 {275 headers: getRequestHeaders(),276 }277 );278 },279 blockUser(blockId) {280 return axios.post(281 `${Env.APIURL}/api/profile/blockUser`,282 {283 block_id: blockId,284 },285 {286 headers: getRequestHeaders(),287 }288 );289 },290 unBlockUser(blockId) {291 return axios.post(292 `${Env.APIURL}/api/profile/unBlockUser`,293 {294 block_id: blockId,295 },296 {297 headers: getRequestHeaders(),298 }299 );300 },301 reportUser(content, target) {302 return axios.post(303 `${Env.APIURL}/api/report/reportUser/${target}`,304 {305 report_content: content,306 },307 {308 headers: getRequestHeaders(),309 }310 );311 },312 getUserReport() {313 return axios.post(314 `${Env.APIURL}/api/report/getUserReport`,315 {},316 {317 headers: getRequestHeaders(),318 }319 );320 },321 removeUserReport(report_id) {322 return axios.post(323 `${Env.APIURL}/api/report/removeUserReport`,324 {325 report_id,326 },327 {328 headers: getRequestHeaders(),329 }330 );331 },332 getSetting() {333 return axios.post(334 `${Env.APIURL}/api/profile/getSetting`,335 {},336 {337 headers: getRequestHeaders(),338 }339 );340 },341 getPushnotificationSetting() {342 return axios.post(343 `${Env.APIURL}/api/profile/getPushnotificationSetting`,344 {},345 {346 headers: getRequestHeaders(),347 }348 );349 },350 updateSetting(params) {351 return axios.post(352 `${Env.APIURL}/api/profile/updateSetting`,353 {354 explicit_content: params.explicitContent,355 remove_text: params.removeText,356 allow_dm: params.allowDm,357 allow_collab: params.allowCollab,358 allow_profile: params.allowProfile,359 },360 {361 headers: getRequestHeaders(),362 }363 );364 },365 async uploadAvatar(url, name, type) {366 const file = {367 uri: url,368 name,369 type,370 };371 const state = store.getState();372 const { id } = state.user;373 const uuidName = await generateUUID();374 const key = `avatars/${id}_${uuidName}`;375 console.log(file);376 return new Promise((resolve, reject) => {377 const options = {378 type: 'multipart',379 method: 'POST',380 headers: {381 'content-type': type, // server requires a content-type header382 },383 url: Env.S3URL,384 field: 'file',385 path: url,386 parameters: {387 ...S3Policy.generate({388 keyPrefix: 'avatars/',389 bucket: Env.bucket,390 region: Env.region,391 accessKey: Env.accessKey,392 secretKey: Env.secretKey,393 successActionStatus: 201,394 key,395 date: new Date(),396 contentType: type,397 }),398 },399 };400 // console.log({ options });401 Upload.startUpload(options)402 .then(async (uploadId) => {403 // console.log(`options:`, options);404 Upload.addListener('progress', uploadId, (data) => {405 // console.log(`Progress:`, data.progress);406 });407 Upload.addListener('error', uploadId, (data) => {408 // console.log(`Error: `, data.error);409 reject();410 });411 Upload.addListener('cancelled', uploadId, (data) => {412 // console.log(`Cancelled!`, data);413 reject();414 });415 Upload.addListener('completed', uploadId, (data) => {416 // data includes responseCode: number and responseBody: Object417 const body = {418 url: `/${key}`,419 filename: name,420 filetype: type.split('/')[0],421 };422 resolve(body);423 });424 })425 .catch((err) => {426 reject();427 });428 }).then((resp) => resp);429 },430 async uploadImage(url, name, type) {431 const file = {432 uri: url,433 name,434 type,435 };436 const uuidName = await generateUUID();437 const key = `pictures/${moment().format('MM_DD_YYYY')}/${uuidName}`;438 console.log(file);439 return new Promise((resolve, reject) => {440 const options = {441 type: 'multipart',442 method: 'POST',443 headers: {444 'content-type': 'multipart', // type, // server requires a content-type header445 },446 url: Env.S3URL,447 field: 'file',448 path: url,449 parameters: {450 ...S3Policy.generate({451 keyPrefix: 'pictures/',452 bucket: Env.bucket,453 region: Env.region,454 accessKey: Env.accessKey,455 secretKey: Env.secretKey,456 successActionStatus: 201,457 key,458 date: new Date(),459 contentType: type,460 }),461 },462 };463 // console.log({ options });464 Upload.startUpload(options)465 .then(async (uploadId) => {466 // console.log(`options:`, uploadId);467 Upload.addListener('progress', uploadId, (data) => {468 // console.log(`Progress:`, data.progress);469 });470 Upload.addListener('error', uploadId, (data) => {471 // console.log(`Error: `, data.error);472 reject();473 });474 Upload.addListener('cancelled', uploadId, (data) => {475 // console.log(`Cancelled!`, data);476 reject();477 });478 Upload.addListener('completed', uploadId, (data) => {479 // data includes responseCode: number and responseBody: Object480 const body = {481 url: `/${key}`,482 filename: name,483 filetype: type.split('/')[0],484 };485 resolve(body);486 });487 })488 .catch((err) => {489 reject();490 });491 }).then((resp) => resp);492 },493 getContactUsers(phones) {494 return axios.post(`${Env.APIURL}/api/profile/getContactUsers`, {495 phones,496 });497 },498 getMyCart() {499 return axios.post(500 `${Env.APIURL}/api/profile/getMyCart`,501 {},502 {503 headers: getRequestHeaders(),504 }505 );506 },507 getMyPurchase(user_id, store_option) {508 return axios.post(509 `${Env.APIURL}/api/profile/getMyPurchase`,510 {511 user_id,512 store_option,513 },514 {515 headers: getRequestHeaders(),516 }517 );518 },519 getMyWishlist(craft_id) {520 return axios.post(521 `${Env.APIURL}/api/profile/getMyWishlist`,522 {523 craft_id,524 },525 {526 headers: getRequestHeaders(),527 }528 );529 },530 getCraftFromWishlistById() {531 return axios.post(532 `${Env.APIURL}/api/profile/getCraftFromWishlistById`,533 {},534 {535 headers: getRequestHeaders(),536 }537 );538 },539 getContributedCraftlist(id, limit = 0) {540 return axios.post(541 `${Env.APIURL}/api/profile/getContributedCraftlist`,542 {543 id,544 limit,545 },546 {547 headers: getRequestHeaders(),548 }549 );550 },551 getFollowNumbers(id) {552 return axios.post(553 `${Env.APIURL}/api/profile/getFollowNumbers/${id}`,554 {},555 {556 headers: getRequestHeaders(),557 }558 );559 },560 setFeaturedUser(id) {561 return axios.post(562 `${Env.APIURL}/api/profile/setFeaturedUser/${id}`,563 {},564 {565 headers: getRequestHeaders(),566 }567 );568 },569 unsetFeaturedUser(id) {570 return axios.post(571 `${Env.APIURL}/api/profile/unsetFeaturedUser/${id}`,572 {},573 {574 headers: getRequestHeaders(),575 }576 );577 },578};...
api.service.ts
Source:api.service.ts
...37 return parameters.map(x => `${x.key}=${x.value}`).join('&');38 }39 //#region Users40 saveUser = async (user: User): Promise<LoggedUserModel> =>41 await this.post('users/create', user, await this.getRequestHeaders());42 login = async (user: Login): Promise<LoggedUserModel> =>43 await this.post('users/login', user, await this.getRequestHeaders());44 users = async (filter: UsersFilter): Promise<User[]> =>45 await this.post('users/all-users', filter, await this.getRequestHeaders());46 getUser = async (id: string): Promise<User> =>47 await this.get(`users/get?${ApiService.getUrlQueryParameters({ id })}`, await this.getRequestHeaders());48 //#endregion49 //#region ProductsList50 saveProduct = async (product: Product): Promise<any> =>51 await this.post('productsregister/create', product, await this.getRequestHeaders());52 deleteProduct = async (id: string): Promise<any> =>53 await this.post(`productsregister/delete?${ApiService.getUrlQueryParameters({ id })}`, {}, await this.getRequestHeaders());54 listProduct = async (filters?: FiltersProduct): Promise<Product[]> => {55 filters = filters ? filters : new FiltersProduct();56 return await this.post('productsList/list', filters, await this.getRequestHeaders());57 }58 //#endregion59 //#region Category60 listCategories = async (filters?: FiltersCategory): Promise<ProductCategoryOutput[]> => {61 filters = filters ? filters : new FiltersCategory();62 return await this.post('categories/get-categories', filters, await this.getRequestHeaders());63 }64 categories = async (filters?: FiltersCategory): Promise<Category[]> => {65 filters = filters ? filters : new FiltersCategory();66 return await this.post('categories/list', filters, await this.getRequestHeaders());67 }68 getCategory = async (id: string): Promise<User> =>69 await this.get(`categories/get?${ApiService.getUrlQueryParameters({ id })}`, await this.getRequestHeaders());70 saveCategory = async (input: Category): Promise<User> =>71 await this.post(`categories/save`, input, await this.getRequestHeaders());72 migrateCategory = async (input: CategoryMigrationInput): Promise<User> =>73 await this.post(`categories/migration`, input, await this.getRequestHeaders());74 //#endregion75 //#region Sales76 getSaleTotal = async (input: string[]): Promise<number> =>77 await this.post(`sales/total`, input, await this.getRequestHeaders());78 saveSale = async (input: SaleInput): Promise<void> =>79 await this.post(`sales/create`, input, await this.getRequestHeaders());80 getSales = async (input: FiltersSale): Promise<SaleOutput[]> =>81 await this.post(`sales/get`, input, await this.getRequestHeaders());82 //#endregion83}84export class UrlQueryParameter {85 key: string;86 value: string;...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err){4 console.log(err);5 }else{6 console.log(data);7 }8});9{10 "responseHeaders": {11 "Content-Type": "text/html; charset=UTF-8",12 }13}14{15 "responseHeaders": {16 "Content-Type": "text/html; charset=UTF-8",17 }18}19Get Response Headers (JSONP)20foo({21 "responseHeaders": {22 "Content-Type": "text/html; charset
Using AI Code Generation
1var headers = wpt.getRequestHeaders();2console.log(headers);3var header = wpt.getRequestHeader("Content-Type");4console.log(header);5wpt.setRequestHeader("Content-Type", "application/json");6var headers = {"Content-Type": "application/json"};7wpt.setRequestHeader(headers);8### [setRequestHeader](
Using AI Code Generation
1var requestHeaders = wpt.getRequestHeaders();2var headers = "";3for (var key in requestHeaders) {4";5}6wpt.setResponseHeader("X-Request-Headers", headers);7wpt.setResponseHeader("X-Request-Method", wpt.getRequestMethod());8wpt.setResponseHeader("X-Request-URL", wpt.getRequestUrl());9wpt.setResponseHeader("X-Request-Body", wpt.getRequestBody());10wpt.setResponseHeader("X-Request-Query", wpt.getRequestQuery());11wpt.setResponseHeader("X-Request-Protocol", wpt.getRequestProtocol());12wpt.setResponseHeader("X-Request-Host", wpt.getRequestHost());13wpt.setResponseHeader("X-Request-Port", wpt.getRequestPort());14wpt.setResponseHeader("X-Request-Path", wpt.getRequestPath());15wpt.setResponseHeader("X-Request-Auth", wpt.getRequestAuth());16wpt.setResponseHeader("X-Request-Remote-Address", wpt.getRequestRemoteAddress());17wpt.setResponseHeader("X-Request-Remote-Port", wpt.getRequestRemotePort());18wpt.setResponseHeader("X-Request-Local-Address", wpt.getRequestLocalAddress());19wpt.setResponseHeader("X-Request-Local-Port", wpt.getRequestLocalPort());20wpt.setResponseHeader("X-Request-Content-Length", wpt.getRequestContentLength());21wpt.setResponseHeader("X-Request-Content-Type", wpt.getRequestContentType());22wpt.setResponseHeader("X-Request-Connection", wpt.getRequestConnection());23wpt.setResponseHeader("X-Request-User-Agent", wpt.getRequestUserAgent());24wpt.setResponseHeader("X-Request-Referer", wpt.getRequestReferer());25wpt.setResponseHeader("X-Request-Query-String", wpt.getRequestQueryString());26wpt.setResponseHeader("X-Request-Content-Encoding", wpt.getRequestContentEncoding());27wpt.setResponseHeader("X-Request-Accept-Encoding", wpt.getRequestAcceptEncoding());28wpt.setResponseHeader("X-Request-Transfer-Encoding", wpt.getRequestTransferEncoding());29wpt.setResponseHeader("X-Request-Expect", wpt.getRequestExpect());30wpt.setResponseHeader("X-Request-Upgrade-Insecure-Requests", wpt.getRequestUpgradeInsecureRequests());
Using AI Code Generation
1var headers = wpt.getRequestHeaders();2var headers = [{name: 'header1', value: 'value1'}, {name: 'header2', value: 'value2'}];3wpt.setRequestHeaders(headers);4wpt.setRequestHeader('header1', 'value1');5wpt.setRequestHeader('header1', 'value1');6wpt.setRequestHeader('header1', 'value1');7wpt.setRequestHeader('header1', 'value1');8wpt.setRequestHeader('header1', 'value1');9wpt.setRequestHeader('header1', 'value1');10wpt.setRequestHeader('header1', 'value1');11wpt.setRequestHeader('header1', 'value1');12wpt.setRequestHeader('header1', 'value1');13wpt.setRequestHeader('header1', 'value1');14wpt.setRequestHeader('header1', 'value1');15wpt.setRequestHeader('header1', 'value1');16wpt.setRequestHeader('header1', 'value1');17wpt.setRequestHeader('header1', 'value1');
Using AI Code Generation
1var headers = wpt.getRequestHeaders();2var headerString = "Request Headers: " + JSON.stringify(headers);3wpt.log(headerString);4var headers = { 'X-Test-Header': 'test-value' };5wpt.setRequestHeader(headers);6wpt.log("Request Headers set");7wpt.setRequestHeader({ 'X-Test-Header': 'test-value', 'X-Test-Header2': 'test-value2' });8wpt.setRequestHeader({ 'X-Test-Header': 'test,value' });9wpt.setRequestHeader({ 'X-Test-Header': 'test:value' });10wpt.setRequestHeader({ 'X-Test-Header': 'test"value' });11wpt.setRequestHeader({ 'X-Test-Header': 'test"value' });12wpt.setRequestHeader({ 'X-Test-Header': 'test\value' });13wpt.setRequestHeader({ 'X-Test-Header': 'test/value' });14wpt.setRequestHeader({ 'X-Test-Header': 'test?value' });
Using AI Code Generation
1var headers = wpt.getRequestHeaders();2console.log(headers);3### wpt.setOptions(options)4wpt.setOptions({5});6### wpt.setScript(script)7wpt.setScript('document.documentElement.innerHTML = "Hello world";');8### wpt.setTestType(testType)9wpt.setTestType('repeatView');10### wpt.startTest(url, callback)11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17### wpt.startTestAndWait(url, callback)18 if (err) {19 console.log(err);
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!!