Best JavaScript code snippet using best
router.js
Source:router.js
1'use strict';2const express = require('express');3module.exports = function(dependencies) {4 const router = express.Router();5 const authorizationMW = dependencies('authorizationMW');6 const helperMW = dependencies('helperMW');7 const proxyMW = require('../proxy/middleware')(dependencies);8 const davMiddleware = dependencies('davserver').davMiddleware;9 const controller = require('./controller')(dependencies);10 const middleware = require('./middleware')(dependencies);11 /**12 * @swagger13 * /dav/api/addressbooks/{bookHome}.json:14 * post:15 * tags:16 * - Davproxy17 * description: Create an addressbook in the specified addressbook home18 * parameters:19 * - $ref: "#/parameters/davproxy_addressbook_book_home"20 * - $ref: "#/parameters/davproxy_addressbook_create"21 * responses:22 * 201:23 * $ref: "#/responses/davproxy_addressbook_create"24 * 401:25 * $ref: "#/responses/cm_401"26 * 500:27 * $ref: "#/responses/cm_500"28 */29 router.post(30 '/:bookHome.json',31 authorizationMW.requiresAPILogin,32 middleware.validateAddressbookCreation,33 proxyMW.generateNewToken,34 davMiddleware.getDavEndpoint,35 controller.createAddressbook36 );37 /**38 * @swagger39 * /dav/api/addressbooks/{bookHome}/{bookName}.json:40 * delete:41 * tags:42 * - Davproxy43 * description: Remove an addressbook in the specified addressbook home44 * parameters:45 * - $ref: "#/parameters/davproxy_addressbook_book_home"46 * - $ref: "#/parameters/davproxy_addressbook_book_name"47 * responses:48 * 204:49 * $ref: "#/responses/cm_204"50 * 401:51 * $ref: "#/responses/cm_401"52 * 500:53 * $ref: "#/responses/cm_500"54 */55 router.delete(56 '/:bookHome/:bookName.json',57 authorizationMW.requiresAPILogin,58 proxyMW.generateNewToken,59 davMiddleware.getDavEndpoint,60 controller.removeAddressbook61 );62 /**63 * @swagger64 * /dav/api/addressbooks/{bookHome}/{bookName}.json:65 * put:66 * tags:67 * - Davproxy68 * description: Update an addressbook in the specified addressbook home69 * parameters:70 * - $ref: "#/parameters/davproxy_addressbook_book_home"71 * - $ref: "#/parameters/davproxy_addressbook_book_name"72 * - $ref: "#/parameters/davproxy_addressbook_update"73 * responses:74 * 204:75 * $ref: "#/responses/cm_204"76 * 401:77 * $ref: "#/responses/cm_401"78 * 500:79 * $ref: "#/responses/cm_500"80 */81 router.put(82 '/:bookHome/:bookName.json',83 authorizationMW.requiresAPILogin,84 proxyMW.generateNewToken,85 davMiddleware.getDavEndpoint,86 controller.updateAddressbook87 );88 /**89 * @swagger90 * /dav/api/addressbooks/{bookHome}/{bookName}/{contactId}.vcf:91 * get:92 * tags:93 * - Davproxy94 * description: Gets contact of an user id95 * parameters:96 * - $ref: "#/parameters/davproxy_addressbook_book_home"97 * - $ref: "#/parameters/davproxy_addressbook_book_name"98 * - $ref: "#/parameters/davproxy_addressbook_contact_id"99 * responses:100 * 200:101 * $ref: "#/responses/davproxy_addressbook_update"102 * 401:103 * $ref: "#/responses/cm_401"104 * 500:105 * $ref: "#/responses/cm_500"106 */107 router.get(108 '/:bookHome/:bookName/:contactId.vcf',109 authorizationMW.requiresAPILogin,110 proxyMW.generateNewToken,111 davMiddleware.getDavEndpoint,112 controller.getContact113 );114 /**115 * @swagger116 * /addressbooks/{bookHome}/{bookName}/{contactId}.vcf:117 * put:118 * tags:119 * - Davproxy120 * description: Puts information to update contact121 * parameters:122 * - $ref: "#/parameters/davproxy_addressbook_book_home"123 * - $ref: "#/parameters/davproxy_addressbook_book_name"124 * - $ref: "#/parameters/davproxy_addressbook_contact_id"125 * - $ref: "#/parameters/davproxy_addressbook_contact"126 * responses:127 * 200:128 * $ref: "#/responses/davproxy_addressbook_update"129 * 401:130 * $ref: "#/responses/cm_401"131 * 500:132 * $ref: "#/responses/cm_500"133 */134 router.put(135 '/:bookHome/:bookName/:contactId.vcf',136 authorizationMW.requiresAPILogin,137 proxyMW.generateNewToken,138 davMiddleware.getDavEndpoint,139 controller.updateContact140 );141 /**142 * @swagger143 * /dav/api/addressbooks/{bookHome}/{bookName}/{contactId}.vcf:144 * delete:145 * tags:146 * - Davproxy147 * description: Delete a contact in a specific address book148 * parameters:149 * - $ref: "#/parameters/davproxy_addressbook_book_home"150 * - $ref: "#/parameters/davproxy_addressbook_book_name"151 * - $ref: "#/parameters/davproxy_addressbook_contact_id"152 * responses:153 * 204:154 * $ref: "#/responses/cm_204"155 * 401:156 * $ref: "#/responses/cm_401"157 * 403:158 * $ref: "#/responses/cm_403"159 * 404:160 * $ref: "#/responses/cm_404"161 * 500:162 * $ref: "#/responses/cm_500"163 */164 router.delete(165 '/:bookHome/:bookName/:contactId.vcf',166 authorizationMW.requiresAPILogin,167 proxyMW.generateNewToken,168 davMiddleware.getDavEndpoint,169 controller.deleteContact170 );171 /**172 * /addressbooks/{bookHome}/{bookName}/{contactId}.vcf:173 * move:174 * tags:175 * - Davproxy176 * description: Moves a contact177 * parameters:178 * - $ref: "#/parameters/davproxy_addressbook_book_home"179 * - $ref: "#/parameters/davproxy_addressbook_book_name"180 * - $ref: "#/parameters/davproxy_addressbook_contact_id"181 * - $ref: "#/parameters/davproxy_addressbook_destination"182 * responses:183 * 200:184 * $ref: "#/responses/cm_201"185 * 401:186 * $ref: "#/responses/cm_401"187 * 500:188 * $ref: "#/responses/cm_500"189 */190 router.move(191 '/:bookHome/:bookName/:contactId.vcf',192 authorizationMW.requiresAPILogin,193 middleware.requireDestinationInHeaders,194 proxyMW.generateNewToken,195 davMiddleware.getDavEndpoint,196 controller.moveContact197 );198 /**199 * @swagger200 * /addressbooks/{bookHome}/{bookName}.json:201 * get:202 * tags:203 * - Davproxy204 * description: Gets all contacts in book name205 * parameters:206 * - $ref: "#/parameters/davproxy_addressbook_book_home"207 * - $ref: "#/parameters/davproxy_addressbook_book_name"208 * - $ref: "#/parameters/davproxy_addressbook_contact_id"209 * - $ref: "#/parameters/davproxy_addressbook_user_id"210 * - $ref: "#/parameters/cm_search"211 * - $ref: "#/parameters/cm_limit"212 * - $ref: "#/parameters/cm_page"213 * responses:214 * 200:215 * $ref: "#/responses/davproxy_addressbook_contact"216 * 401:217 * $ref: "#/responses/cm_401"218 * 500:219 * $ref: "#/responses/cm_500"220 */221 router.get(222 '/:bookHome/:bookName.json',223 authorizationMW.requiresAPILogin,224 proxyMW.generateNewToken,225 davMiddleware.getDavEndpoint,226 controller.getContacts227 );228 router.propfind(229 '/:bookHome/:bookName.json',230 authorizationMW.requiresAPILogin,231 proxyMW.generateNewToken,232 davMiddleware.getDavEndpoint,233 controller.getAddressbook234 );235 /**236 * @swagger237 * /dav/api/addressbooks/{bookHome}.json:238 * get:239 * tags:240 * - Davproxy241 * description: List address books from a book home. <br>242 * At least one of these following queries is required and set to true. These queries are personal, subscribed, shared.243 * parameters:244 * - $ref: "#/parameters/davproxy_addressbook_book_home"245 * - $ref: "#/parameters/davproxy_addressbook_personal"246 * - $ref: "#/parameters/davproxy_addressbook_subscribed"247 * - $ref: "#/parameters/davproxy_addressbook_shared"248 * - $ref: "#/parameters/davproxy_addressbook_contacts_count"249 * responses:250 * 200:251 * $ref: "#/responses/davproxy_addressbook_address_books"252 * 401:253 * $ref: "#/responses/cm_401"254 * 500:255 * $ref: "#/responses/cm_500"256 */257 router.get(258 '/:bookHome.json',259 authorizationMW.requiresAPILogin,260 proxyMW.generateNewToken,261 davMiddleware.getDavEndpoint,262 controller.getAddressbooks263 );264 /**265 * @swagger266 * /dav/api/addressbooks/{bookHome}.json/contacts:267 * get:268 * tags:269 * - Davproxy270 * description: Gets all contacts that match a searching pattern. <br>271 * Query search is required, query bookName is optional. When bookName is set, it returns results belonging to this bookName only. <br>272 * parameters:273 * - $ref: "#/parameters/davproxy_addressbook_book_home"274 * - $ref: "#/parameters/davproxy_addressbook_book_name_query"275 * - $ref: "#/parameters/cm_search"276 * - $ref: "#/parameters/cm_limit"277 * - $ref: "#/parameters/cm_page"278 * responses:279 * 200:280 * $ref: "#/responses/davproxy_addressbook_contacts"281 * 400:282 * $ref: "#/responses/cm_400"283 * 401:284 * $ref: "#/responses/cm_401"285 * 500:286 * $ref: "#/responses/cm_500"287 */288 router.get(289 '/:bookHome.json/contacts',290 authorizationMW.requiresAPILogin,291 proxyMW.generateNewToken,292 davMiddleware.getDavEndpoint,293 helperMW.requireInQuery('search', null),294 controller.searchContacts295 );296 router.all('/*', authorizationMW.requiresAPILogin, proxyMW.generateNewToken, davMiddleware.getDavEndpoint, controller.defaultHandler);297 return router;...
controllers-connect.js
Source:controllers-connect.js
1angular.module('starter.controllers-connect', [])2.controller('ConnectCtrl', function(3 $scope, $state,4 Auth, Profile, Codes, Utils, StripeCharge) {5 // communicates with the DOM6 $scope.status = {7 loading: true,8 setupStripeConnect: true,9 setupStripeConnectMode: false,10 loadingStripeConnect: true,11 generateNewToken: false,12 loadingAuthToken: true,13 };14 15 $scope.$on('$ionicView.enter', function(e) {16 // global variables17 $scope.AuthData = Auth.AuthData;18 19 getStripeConnectAuth();20 generateFBAuthToken();21 });22 function getStripeConnectAuth() {23 StripeCharge.getStripeConnectAuth_value($scope.AuthData.uid)24 .then(function(SCData) {25 26 // bind to DOM27 $scope.SCData = SCData;28 $scope.status['loadingStripeConnect'] = false;29 30 // process the result31 if(SCData == null) {32 // stripe not setup, generate a new token33 $scope.status['setupStripeConnect'] = false; 34 $scope.status['generateNewToken'] = true;35 } else {36 // stripe connect has been setup, resolve37 $scope.status['setupStripeConnect'] = true;38 $scope.status['generateNewToken'] = false;39 };40 })41 .catch(function(error) {42 $scope.status['loadingStripeConnect'] = false;43 $scope.status['generateNewToken'] = true;44 }45 );46 };47 48 // generate the link to setup stripe connect49 function generateFBAuthToken() {50 StripeCharge.generateFBAuthToken($scope.AuthData.uid).then(51 function(fbAuthToken){52 // update the dynamic url for stripe connect53 $scope.status['authorize_url'] = STRIPE_URL_AUTHORIZE + "?userId=" + $scope.AuthData.uid + "&token=" + fbAuthToken;54 $scope.status['loadingAuthToken'] = false;55 },56 function(error){57 $scope.status['loadingAuthToken'] = false;58 }59 );60 };61 62 $scope.connectWithStripe = function() {63 $scope.setupSubNavCSS = "back-lightblue"64 $scope.status['setupStripeConnectMode'] = true;65 };66 67 $scope.refreshStripeConnectAuth = function() {68 getStripeConnectAuth();69 $scope.status['setupStripeConnectMode'] = false;70 };71 $scope.goTo = function(nextState) {72 $state.go(nextState);73 };...
middleware.js
Source:middleware.js
2var GRACE_PERIOD = 10000;3var FACTOR = 2;4module.exports = function(dependencies) {5 var tokenMW = dependencies('tokenMW');6 function generateNewToken(req, res, next) {7 return tokenMW.generateNewToken(req.query.graceperiod ? req.query.graceperiod * FACTOR : GRACE_PERIOD)(req, res, next);8 }9 // Due to the issue about raw-body, bodyParser and restreamer, we might want10 // to remove content-length header because the body might be changed in this11 // proxy before forwarding12 function removeContentLength(req, res, next) {13 if (req.headers) {14 delete req.headers['content-length'];15 }16 next();17 }18 return {19 generateNewToken: generateNewToken,20 removeContentLength: removeContentLength21 };...
Using AI Code Generation
1var BestBuy = function() {2}3BestBuy.prototype.generateNewToken = function() {4}5BestBuy.prototype.getProducts = function() {6}7BestBuy.prototype.getStores = function() {8}9BestBuy.prototype.getBlackFridayDeals = function() {10}11BestBuy.prototype.getProductsByCategory = function() {12}13BestBuy.prototype.getProductsByDepartment = function() {14}15BestBuy.prototype.getProductsBySku = function() {16}17BestBuy.prototype.getProductsByUpc = function() {18}19BestBuy.prototype.getProductsByManufacturer = function() {20}21BestBuy.prototype.getProductsByModel = function() {22}23BestBuy.prototype.getProductsByCategoryAndManufacturer = function() {24}25BestBuy.prototype.getProductsByCategoryAndModel = function() {26}27BestBuy.prototype.getProductsByCategoryAndUpc = function() {28}29BestBuy.prototype.getProductsByCategoryAndSku = function() {30}31BestBuy.prototype.getProductsByDepartmentAndManufacturer = function() {32}33BestBuy.prototype.getProductsByDepartmentAndModel = function() {34}35BestBuy.prototype.getProductsByDepartmentAndUpc = function() {36}37BestBuy.prototype.getProductsByDepartmentAndSku = function() {38}39BestBuy.prototype.getProductsByManufacturerAndModel = function() {
Using AI Code Generation
1const BestBuyApi = require('./BestBuyApi');2const bestBuyApi = new BestBuyApi();3bestBuyApi.generateNewToken()4.then((response) => {5 console.log(response);6})7.catch((error) => {8 console.log(error);9});10const BestBuyApi = require('./BestBuyApi');11const bestBuyApi = new BestBuyApi();12bestBuyApi.generateNewToken()13.then((response) => {14 console.log(response);15})16.catch((error) => {17 console.log(error);18});19const BestBuyApi = require('./BestBuyApi');20const bestBuyApi = new BestBuyApi();21bestBuyApi.generateNewToken()22.then((response) => {23 console.log(response);24})25.catch((error) => {26 console.log(error);27});28const BestBuyApi = require('./BestBuyApi');29const bestBuyApi = new BestBuyApi();30bestBuyApi.generateNewToken()31.then((response) => {32 console.log(response);33})34.catch((error) => {35 console.log(error);36});37const BestBuyApi = require('./BestBuyApi');
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!!