Best JavaScript code snippet using wpt
App.js
Source:App.js
1import React, { Component } from 'react'2import momenttz from 'moment-timezone'3import moment from 'moment'4import dateFormat from 'dateformat'5import {6 login,7 routes,8 trips,9 tripRequests,10 approveRequest,11 rejectRequest,12 scheduleTrip,13 unscheduleTrip,14 config,15 clientSearch,16 programs,17 placeSearch,18 placesOnDemand,19 purposes,20 statusTypes,21 wheelchairTypes,22 addTrip,23 allVehicles,24 allDrivers,25 allRoutes,26 saveFleetmanager,27 savePlace28} from 'paraplan-react'29export default class App extends Component {30 constructor(props) {31 super(props)32 this.initialState = {33 key: '',34 restUrl: '',35 success: false,36 errorMessage: '',37 clientId: '',38 clientCanRequestTrips: false,39 requestEmail: 'timhibbard@engraph.com',40 requestPassword: 'tim',41 requestUTC: momenttz.tz(momenttz.tz.guess()).utcOffset() / 60,42 requestDevice: 'paraplan-react-example',43 requestVersion: '0.0.2',44 requestRouteDate: dateFormat(Date.now(), 'yyyy-mm-dd'),45 // tripStartDate: '1582693200',46 // tripEndDate: '1582779600',47 tripStartDate: new Date(new Date().setHours(0, 0, 0, 0)).getTime() / 1000,48 tripEndDate: new Date(new Date().setHours(48, 0, 0, 0)).getTime() / 1000,49 routes: [],50 dispatcherTrips: [],51 tripRequests: [],52 config: {},53 clients: [],54 clientSearchString: '',55 programs: [],56 places: [],57 placesSearchString: '',58 purposes: [],59 statusTypes: [],60 wheelchairTypes: [],61 allVehicles: [],62 allDrivers: [],63 allRoutes: [],64 fleetManagerId: '',65 newPlaceId: ''66 }67 this.state = this.initialState68 this.handleChange = this.handleChange.bind(this)69 }70 schedule(trip, fleetmanager) {71 const { key, restUrl, requestDevice } = this.state72 var requestObject = {73 key: key,74 restUrl: restUrl,75 device: requestDevice,76 fleetManagerId: fleetmanager.fleetmanagerID,77 trip: trip78 }79 console.log(requestObject)80 scheduleTrip(requestObject)81 .then(response => {82 var tripId = response.entity.tripId83 var fleetmanager = response.entity.fleetmanager84 console.log(response.trip)85 this.setState({86 success: response.success,87 dispatcherTrips: this.state.dispatcherTrips.map(el =>88 el.tripId === tripId ? { ...el, fleetmanager } : el89 )90 })91 })92 .catch(reason => {93 this.setState({94 success: reason.success,95 errorMessage: reason.errorMessage96 })97 })98 }99 unschedule(trip) {100 const { key, restUrl, requestDevice } = this.state101 var requestObject = {102 key: key,103 restUrl: restUrl,104 device: requestDevice,105 trip: trip106 }107 console.log(requestObject)108 unscheduleTrip(requestObject)109 .then(response => {110 var tripId = response.entity.tripId111 var fleetmanager = response.entity.fleetmanager112 console.log(response.trip)113 this.setState({114 success: response.success,115 dispatcherTrips: this.state.dispatcherTrips.map(el =>116 el.tripId === tripId ? { ...el, fleetmanager } : el117 )118 })119 })120 .catch(reason => {121 this.setState({122 success: reason.success,123 errorMessage: reason.errorMessage124 })125 })126 }127 createNewPlace() {128 const { key, restUrl, requestDevice } = this.state129 var place = {130 name: 'delete me',131 address1: '340 Rocky Slope Rd',132 address2: 'Suite 200',133 city: 'Greenville',134 state: 'SC',135 zip: '29607'136 }137 var requestObject = {138 key: key,139 restUrl: restUrl,140 device: requestDevice,141 place: place142 }143 console.log(requestObject)144 savePlace(requestObject)145 .then(response => {146 console.log(response.databaseId)147 this.setState({ newPlaceId: response.databaseId })148 })149 .catch(reason => {150 console.log(reason.errorMessage)151 this.setState({152 success: reason.success,153 errorMessage: reason.errorMessage154 })155 })156 }157 saveFleetmanager() {158 const { key, restUrl, requestDevice } = this.state159 var fm = {160 driverID: 157,161 routeId: 102,162 endTime: '/Date(-2209093200000+0000)/',163 startTime: '/Date(-2209141800000+0000)/',164 vehicleID: 311,165 fleetmanagerID: 10463166 }167 var requestObject = {168 key: key,169 restUrl: restUrl,170 device: requestDevice,171 fleetmanager: fm172 }173 console.log(requestObject)174 saveFleetmanager(requestObject)175 .then(response => {176 console.log(response.fleetmanagerId)177 this.setState({ fleetManagerId: response.fleetmanagerId })178 })179 .catch(reason => {180 console.log(reason.errorMessage)181 this.setState({182 success: reason.success,183 errorMessage: reason.errorMessage184 })185 })186 }187 approveTripRequest(request) {188 const { key, restUrl, requestDevice } = this.state189 var requestObject = {190 key: key,191 restUrl: restUrl,192 device: requestDevice,193 tripRequest: request194 }195 approveRequest(requestObject)196 .then(response => {197 var tripStatus = response.request.tripStatus198 var importTripID = response.request.importTripID199 console.log(response.stops)200 console.log(response.request)201 this.setState({202 success: response.success,203 tripRequests: this.state.tripRequests.map(el =>204 el.importTripID === importTripID ? { ...el, tripStatus } : el205 )206 })207 })208 .catch(reason => {209 this.setState({210 success: reason.success,211 errorMessage: reason.errorMessage212 })213 })214 }215 rejectTripRequest(request) {216 const { key, restUrl, requestDevice } = this.state217 var requestObject = {218 key: key,219 restUrl: restUrl,220 device: requestDevice,221 tripRequest: request,222 rejectReason: 'Overcapacity and something else'223 }224 rejectRequest(requestObject)225 .then(response => {226 var tripStatus = response.entity.tripStatus227 var importTripID = response.entity.importTripID228 this.setState({229 success: response.success,230 tripRequests: this.state.tripRequests.map(el =>231 el.importTripID === importTripID ? { ...el, tripStatus } : el232 )233 })234 })235 .catch(reason => {236 this.setState({237 success: reason.success,238 errorMessage: reason.errorMessage239 })240 })241 }242 showRequests() {243 const {244 key,245 restUrl,246 requestDevice,247 tripStartDate,248 tripEndDate249 } = this.state250 console.log(tripStartDate)251 console.log(tripEndDate)252 var request = {253 key: key,254 restUrl: restUrl,255 device: requestDevice,256 startDateTime: tripStartDate,257 endDateTime: tripEndDate258 }259 tripRequests(request)260 .then(response => {261 console.log(response)262 this.setState({263 success: response.success,264 tripRequests: response.list265 })266 })267 .catch(reason => {268 this.setState({269 success: reason.success,270 errorMessage: reason.errorMessage271 })272 })273 }274 showTrips() {275 const {276 key,277 restUrl,278 requestDevice,279 tripStartDate,280 tripEndDate281 } = this.state282 var request = {283 key: key,284 restUrl: restUrl,285 device: requestDevice,286 startTime: tripStartDate,287 endTime: tripEndDate288 }289 this.collectRoutes()290 trips(request)291 .then(response => {292 this.setState({293 success: response.success,294 dispatcherTrips: response.list295 })296 })297 .catch(reason => {298 this.setState({299 success: reason.success,300 errorMessage: reason.errorMessage301 })302 })303 }304 collectRoutes() {305 const { key, restUrl, requestDevice, requestRouteDate } = this.state306 var request = {307 key: key,308 restUrl: restUrl,309 device: requestDevice,310 tripDate: requestRouteDate311 }312 routes(request)313 .then(response => {314 this.setState({315 success: response.success,316 routes: response.list317 })318 })319 .catch(reason => {320 this.setState({321 success: reason.success,322 errorMessage: reason.errorMessage323 })324 })325 }326 getConfig() {327 const { key, restUrl, requestDevice } = this.state328 var request = {329 key: key,330 restUrl: restUrl,331 device: requestDevice332 }333 config(request)334 .then(response => {335 this.setState({336 success: response.success,337 config: response.entity338 })339 })340 .catch(reason => {341 this.setState({342 success: reason.success,343 errorMessage: reason.errorMessage344 })345 })346 }347 getClients() {348 const { key, restUrl, requestDevice, clientSearchString } = this.state349 var request = {350 key: key,351 restUrl: restUrl,352 device: requestDevice,353 search: clientSearchString354 }355 clientSearch(request)356 .then(response => {357 this.setState({358 success: response.success,359 clients: response.list360 })361 })362 .catch(reason => {363 this.setState({364 success: reason.success,365 errorMessage: reason.errorMessage366 })367 })368 }369 searchPlaces() {370 const { key, restUrl, requestDevice, placesSearchString } = this.state371 var request = {372 key: key,373 restUrl: restUrl,374 device: requestDevice,375 search: placesSearchString376 }377 placeSearch(request)378 .then(response => {379 this.setState({380 success: response.success,381 places: response.list382 })383 })384 .catch(reason => {385 this.setState({386 success: reason.success,387 errorMessage: reason.errorMessage388 })389 })390 }391 getPrograms() {392 const { key, restUrl, requestDevice } = this.state393 var request = {394 key: key,395 restUrl: restUrl,396 device: requestDevice397 }398 programs(request)399 .then(response => {400 this.setState({401 success: response.success,402 programs: response.list403 })404 })405 .catch(reason => {406 this.setState({407 success: reason.success,408 errorMessage: reason.errorMessage409 })410 })411 }412 getStatusTypes() {413 const { key, restUrl, requestDevice } = this.state414 var request = {415 key: key,416 restUrl: restUrl,417 device: requestDevice418 }419 statusTypes(request)420 .then(response => {421 this.setState({422 success: response.success,423 statusTypes: response.list424 })425 })426 .catch(reason => {427 this.setState({428 success: reason.success,429 errorMessage: reason.errorMessage430 })431 })432 }433 getWheelchairTypes() {434 const { key, restUrl, requestDevice } = this.state435 var request = {436 key: key,437 restUrl: restUrl,438 device: requestDevice439 }440 wheelchairTypes(request)441 .then(response => {442 this.setState({443 success: response.success,444 wheelchairTypes: response.list445 })446 })447 .catch(reason => {448 this.setState({449 success: reason.success,450 errorMessage: reason.errorMessage451 })452 })453 }454 getOnDemandPlaces() {455 const { key, restUrl, requestDevice } = this.state456 var request = {457 key: key,458 restUrl: restUrl,459 device: requestDevice460 }461 placesOnDemand(request)462 .then(response => {463 this.setState({464 success: response.success,465 places: response.list466 })467 })468 .catch(reason => {469 this.setState({470 success: reason.success,471 errorMessage: reason.errorMessage472 })473 })474 }475 getPurposes() {476 const { key, restUrl, requestDevice } = this.state477 var request = {478 key: key,479 restUrl: restUrl,480 device: requestDevice481 }482 purposes(request)483 .then(response => {484 this.setState({485 success: response.success,486 purposes: response.list487 })488 })489 .catch(reason => {490 this.setState({491 success: reason.success,492 errorMessage: reason.errorMessage493 })494 })495 }496 getVehicles() {497 const { key, restUrl, requestDevice } = this.state498 var request = {499 key: key,500 restUrl: restUrl,501 device: requestDevice502 }503 allVehicles(request)504 .then(response => {505 this.setState({506 success: response.success,507 allVehicles: response.list508 })509 })510 .catch(reason => {511 this.setState({512 success: reason.success,513 errorMessage: reason.errorMessage514 })515 })516 }517 getDrivers() {518 const { key, restUrl, requestDevice } = this.state519 var request = {520 key: key,521 restUrl: restUrl,522 device: requestDevice523 }524 allDrivers(request)525 .then(response => {526 this.setState({527 success: response.success,528 allDrivers: response.list529 })530 })531 .catch(reason => {532 this.setState({533 success: reason.success,534 errorMessage: reason.errorMessage535 })536 })537 }538 getRoutes() {539 const { key, restUrl, requestDevice } = this.state540 var request = {541 key: key,542 restUrl: restUrl,543 device: requestDevice544 }545 allRoutes(request)546 .then(response => {547 this.setState({548 success: response.success,549 allRoutes: response.list550 })551 })552 .catch(reason => {553 this.setState({554 success: reason.success,555 errorMessage: reason.errorMessage556 })557 })558 }559 addTripToAPI() {560 const { key, restUrl, requestDevice } = this.state561 var request = {562 key: key,563 restUrl: restUrl,564 device: requestDevice,565 trip: {566 client: {567 id: 19282568 },569 pickUpPlace: {570 databaseId: 35604571 },572 dropOffPlace: {573 databaseId: 34409574 },575 scheduledPickUpTime: moment()576 .add(5, 'minutes')577 .unix(),578 scheduledDropOffTime: moment()579 .add(30, 'minutes')580 .unix(),581 appointmentTime: moment()582 .add(5, 'minutes')583 .unix(),584 program: {585 databaseID: 53586 }587 }588 }589 addTrip(request)590 .then(response => {591 this.setState({592 success: response.success,593 errorMessage: 'new tripid is ' + response.entity.tripId594 })595 })596 .catch(reason => {597 this.setState({598 success: reason.success,599 errorMessage: reason.errorMessage600 })601 })602 }603 loginToAPI() {604 const {605 requestEmail,606 requestPassword,607 requestUTC,608 requestDevice,609 requestVersion610 } = this.state611 var request = {612 email: requestEmail,613 password: requestPassword,614 utcOffset: requestUTC,615 device: requestDevice,616 version: requestVersion617 }618 login(request)619 .then(response => {620 this.setState({621 success: response.success,622 errorMessage: response.errorMessage,623 key: response.Key,624 restUrl: response.RESTUrl,625 clientId: response.ClientID,626 clientCanRequestTrips: response.ClientCanRequestTrips627 })628 })629 .catch(reason => {630 this.setState({631 success: reason.success,632 errorMessage: reason.errorMessage633 })634 })635 }636 handleChange(event) {637 this.setState({ [event.target.name]: event.target.value })638 }639 componentDidMount() {640 // this.loginToAPI()641 }642 render() {643 const {644 success,645 errorMessage,646 key,647 restUrl,648 clientId,649 clientCanRequestTrips,650 routes,651 dispatcherTrips,652 tripRequests,653 config,654 clients,655 programs,656 places,657 purposes,658 statusTypes,659 wheelchairTypes,660 allVehicles,661 allDrivers,662 allRoutes,663 fleetManagerId,664 newPlaceId665 } = this.state666 const labelStyle = {667 padding: '10px',668 display: 'inline-block'669 }670 const inputStyle = {671 width: '200px'672 }673 const buttonStyle = {674 width: '200px',675 display: 'block',676 padding: '10px',677 margin: '10px',678 backgroundColor: '#2d9eaf'679 }680 return (681 <React.Fragment>682 <label style={labelStyle}>683 Email:684 <input685 style={inputStyle}686 type='text'687 name='requestEmail'688 value={this.state.requestEmail}689 onChange={this.handleChange}690 />691 </label>692 <br />693 <label style={labelStyle}>694 Password:695 <input696 style={inputStyle}697 type='text'698 name='requestPassword'699 value={this.state.requestPassword}700 onChange={this.handleChange}701 />702 </label>703 <br />704 <button style={buttonStyle} onClick={() => this.loginToAPI()}>705 Login706 </button>707 <br />708 Success = {String(success)}709 <br />710 ErrorMessage = {errorMessage}711 <br />712 Key = {key}713 <br />714 URL = {restUrl}715 <br />716 ClientID = {clientId}717 <br />718 FleetManagerID = {fleetManagerId}719 <br />720 New Place ID = {newPlaceId}721 <br />722 Can Request Trips = {String(clientCanRequestTrips)}723 <br />724 <br />725 <br />726 <button style={buttonStyle} onClick={() => this.collectRoutes()}>727 Get Routes728 </button>729 <button style={buttonStyle} onClick={() => this.showTrips()}>730 Get Trips731 </button>732 <button style={buttonStyle} onClick={() => this.showRequests()}>733 Get Requests734 </button>735 <button style={buttonStyle} onClick={() => this.getConfig()}>736 Get Config737 </button>738 <input739 style={inputStyle}740 type='text'741 name='clientSearchString'742 value={this.state.clientSearchString}743 onChange={this.handleChange}744 />745 <button style={buttonStyle} onClick={() => this.getClients()}>746 Search Clients747 </button>748 <button style={buttonStyle} onClick={() => this.getPrograms()}>749 Show Programs750 </button>751 <button style={buttonStyle} onClick={() => this.getStatusTypes()}>752 Show Status Types753 </button>754 <button style={buttonStyle} onClick={() => this.getWheelchairTypes()}>755 Show Wheelchair Types756 </button>757 <input758 style={inputStyle}759 type='text'760 name='placesSearchString'761 value={this.state.placesSearchString}762 onChange={this.handleChange}763 />764 <button style={buttonStyle} onClick={() => this.searchPlaces()}>765 Search Places766 </button>767 <button style={buttonStyle} onClick={() => this.createNewPlace()}>768 New Place769 </button>770 <button style={buttonStyle} onClick={() => this.getOnDemandPlaces()}>771 Show On Demand Spots772 </button>773 <button style={buttonStyle} onClick={() => this.getPurposes()}>774 Trip Purposes775 </button>776 <button style={buttonStyle} onClick={() => this.getVehicles()}>777 Vehicles778 </button>779 <button style={buttonStyle} onClick={() => this.getDrivers()}>780 Drivers781 </button>782 <button style={buttonStyle} onClick={() => this.getRoutes()}>783 Routes784 </button>785 <button style={buttonStyle} onClick={() => this.addTripToAPI()}>786 Add Trip787 </button>788 <button style={buttonStyle} onClick={() => this.saveFleetmanager()}>789 Save Fleetmanager790 </button>791 {config && JSON.stringify(config, null, 2) !== '{}' ? (792 <div>793 <pre>{JSON.stringify(config, null, 2)}</pre>794 </div>795 ) : (796 ''797 )}798 <ul>799 {allVehicles.map((v, i) => {800 return <li key={v.databaseID}>{v.year + ' ' + v.make}</li>801 })}802 {allDrivers.map((d, i) => {803 return <li key={d.databaseID}>{d.firstName + ' ' + d.lastName}</li>804 })}805 {allRoutes.map((r, i) => {806 return <li key={r.databaseID}>{r.name}</li>807 })}808 {wheelchairTypes.map((wc, i) => {809 return <li key={i}>{wc.wheelchairName}</li>810 })}811 {statusTypes.map((statusType, i) => {812 return (813 <li key={i}>814 {statusType.name + ': ' + statusType.isSchedulable}815 </li>816 )817 })}818 {purposes.map((purpose, i) => {819 return (820 <li key={purpose.id}>821 {purpose.name +822 ': ' +823 purpose.duration +824 ' (' +825 purpose.id +826 ')'}827 </li>828 )829 })}830 {places.map((place, i) => {831 return (832 <li key={place.databaseId}>833 {place.name +834 ': ' +835 place.address1 +836 ' (' +837 place.databaseId +838 ')'}839 </li>840 )841 })}842 {programs.map((program, i) => {843 return (844 <li key={program.databaseID}>845 {program.programName + ': ' + program.programDescription}846 </li>847 )848 })}849 {clients.map((client, i) => {850 return (851 <li key={client.id}>852 {client.name}853 {client.email && client.email !== '' ? ' ' + client.email : ''}854 </li>855 )856 })}857 {routes.map((route, i) => {858 return (859 <li key={route.fleetmanagerID}>860 {route.routeName}861 {route.gps862 ? ' GPS: ' + route.gps.lat + ', ' + route.gps.lng863 : ''}864 </li>865 )866 })}867 {dispatcherTrips.map((trip, i) => {868 return (869 <li key={trip.tripId}>870 {trip.client.name}:{' '}871 {trip.fleetmanager.routeName === ''872 ? 'No Assigned Route'873 : trip.fleetmanager.routeName}874 <button875 style={buttonStyle}876 onClick={() => this.unschedule(trip)}877 >878 Unschedule879 </button>880 {routes.map((route, i) => {881 return (882 <button883 style={buttonStyle}884 key={route.fleetmanagerID}885 onClick={() => this.schedule(trip, route)}886 >887 Assign to {route.routeName} ({route.fleetmanagerID})888 </button>889 )890 })}891 </li>892 )893 })}894 {tripRequests && tripRequests.length895 ? tripRequests.map((trip, i) => {896 return (897 <li key={trip.importTripID}>898 {trip.clientFirstName} {trip.tripStatus}{' '}899 {moment.unix(trip.pickUpTimeEpoch).format('ll')}900 <button901 style={buttonStyle}902 onClick={() => this.approveTripRequest(trip)}903 >904 Approve905 </button>906 <button907 style={buttonStyle}908 onClick={() => this.rejectTripRequest(trip)}909 >910 Reject911 </button>912 </li>913 )914 })915 : ''}916 </ul>917 </React.Fragment>918 )919 }...
request-device.controller.ts
Source:request-device.controller.ts
1import {2 Count,3 CountSchema,4 Filter,5 FilterExcludingWhere,6 repository,7 Where,8} from '@loopback/repository';9import {10 post,11 param,12 get,13 getModelSchemaRef,14 patch,15 put,16 del,17 requestBody,18 response,19} from '@loopback/rest';20import {RequestDevice} from '../models';21import {RequestDeviceRepository} from '../repositories';22import {RequestDevice as RequestDeviceType} from './request-device-graphQL-model';23import {graphQLHelper} from './graphQL-helper';24export class RequestDeviceController {25 constructor(26 @repository(RequestDeviceRepository)27 public requestDeviceRepository: RequestDeviceRepository,28 ) {}29 @post('/request-devices')30 @response(200, {31 description: 'RequestDevice model instance',32 content: {'application/json': {schema: getModelSchemaRef(RequestDevice)}},33 })34 async create(35 @requestBody({36 content: {37 'application/json': {38 schema: getModelSchemaRef(RequestDevice, {39 title: 'NewRequestDevice',40 exclude: ['id'],41 }),42 },43 },44 })45 requestDevice: Omit<RequestDevice, 'id'>,46 ): Promise<RequestDevice> {47 const instanceID = requestDevice.data[0]?.instanceID;48 const filter = {where: {'data.instanceID': instanceID}};49 const existingRecord = await this.requestDeviceRepository.findOne(filter);50 if (!existingRecord) {51 const data = requestDevice?.data?.[0];52 const requestDeviceType = new RequestDeviceType(data);53 const gQLHelper = new graphQLHelper();54 const {errors, data: gqlResponse} = await gQLHelper.startExecuteInsert(55 requestDeviceType,56 );57 if (errors) {58 console.error(errors);59 } else {60 console.log(gqlResponse);61 }62 return this.requestDeviceRepository.create(requestDevice);63 } else return existingRecord;64 }65 /* 66 @get('/request-devices/count')67 @response(200, {68 description: 'RequestDevice model count',69 content: {'application/json': {schema: CountSchema}},70 })71 async count(72 @param.where(RequestDevice) where?: Where<RequestDevice>,73 ): Promise<Count> {74 return this.requestDeviceRepository.count(where);75 }76 @get('/request-devices')77 @response(200, {78 description: 'Array of RequestDevice model instances',79 content: {80 'application/json': {81 schema: {82 type: 'array',83 items: getModelSchemaRef(RequestDevice, {includeRelations: true}),84 },85 },86 },87 })88 async find(89 @param.filter(RequestDevice) filter?: Filter<RequestDevice>,90 ): Promise<RequestDevice[]> {91 return this.requestDeviceRepository.find(filter);92 }93 @patch('/request-devices')94 @response(200, {95 description: 'RequestDevice PATCH success count',96 content: {'application/json': {schema: CountSchema}},97 })98 async updateAll(99 @requestBody({100 content: {101 'application/json': {102 schema: getModelSchemaRef(RequestDevice, {partial: true}),103 },104 },105 })106 requestDevice: RequestDevice,107 @param.where(RequestDevice) where?: Where<RequestDevice>,108 ): Promise<Count> {109 return this.requestDeviceRepository.updateAll(requestDevice, where);110 }111 @get('/request-devices/{id}')112 @response(200, {113 description: 'RequestDevice model instance',114 content: {115 'application/json': {116 schema: getModelSchemaRef(RequestDevice, {includeRelations: true}),117 },118 },119 })120 async findById(121 @param.path.string('id') id: string,122 @param.filter(RequestDevice, {exclude: 'where'})123 filter?: FilterExcludingWhere<RequestDevice>,124 ): Promise<RequestDevice> {125 return this.requestDeviceRepository.findById(id, filter);126 }127 @patch('/request-devices/{id}')128 @response(204, {129 description: 'RequestDevice PATCH success',130 })131 async updateById(132 @param.path.string('id') id: string,133 @requestBody({134 content: {135 'application/json': {136 schema: getModelSchemaRef(RequestDevice, {partial: true}),137 },138 },139 })140 requestDevice: RequestDevice,141 ): Promise<void> {142 await this.requestDeviceRepository.updateById(id, requestDevice);143 }144 @put('/request-devices/{id}')145 @response(204, {146 description: 'RequestDevice PUT success',147 })148 async replaceById(149 @param.path.string('id') id: string,150 @requestBody() requestDevice: RequestDevice,151 ): Promise<void> {152 await this.requestDeviceRepository.replaceById(id, requestDevice);153 }154 @del('/request-devices/{id}')155 @response(204, {156 description: 'RequestDevice DELETE success',157 })158 async deleteById(@param.path.string('id') id: string): Promise<void> {159 await this.requestDeviceRepository.deleteById(id);160 }161*/...
test-devices.js
Source:test-devices.js
...47 const vrDevice = {};48 addXR(global, xrDevice);49 addVR(global, vrDevice);50 makeMobile(global);51 const device = await requestDevice(global, { cardboard: true, webvr: true });52 assert.equal(device, xrDevice);53 });54 it('returns wrapped VRDisplay if no native XRDevice exists', async function () {55 const global = new MockGlobalVR();56 const vrDevice = new MockVRDisplay();57 addVR(global, vrDevice);58 const device = await requestDevice(global, { cardboard: true, webvr: true });59 assert.equal(device.polyfill.display, vrDevice);60 assert.instanceOf(device, XRDevice);61 });62 it('returns wrapped CardboardVRDisplay if no native XRDevice or VRDisplay exists', async function () {63 const global = new MockGlobalVR();64 addVR(global);65 makeMobile(global);66 const device = await requestDevice(global, { cardboard: true, webvr: true });67 assert.instanceOf(device, XRDevice);68 assert.instanceOf(device.polyfill.display, MockVRDisplay);69 });70 it('returns wrapped CardboardVRDisplay if no native WebXR/WebVR implementations exists', async function () {71 const global = new MockGlobal();72 makeMobile(global);73 const device = await requestDevice(global, { cardboard: true, webvr: true });74 assert.instanceOf(device, XRDevice);75 assert.instanceOf(device.polyfill.display, MockVRDisplay);76 });77 it('returns wrapped CardboardVRDisplay if no native XRDevice and webvr disabled', async function () {78 const global = new MockGlobal();79 makeMobile(global);80 const vrDevice = new MockVRDisplay();81 addVR(global, vrDevice);82 const device = await requestDevice(global, { cardboard: true, webvr: false });83 assert.instanceOf(device, XRDevice);84 assert.instanceOf(device.polyfill.display, MockVRDisplay);85 });86 it('returns no devices if no native support and not on mobile', async function () {87 const global = new MockGlobal();88 const device = await requestDevice(global, { cardboard: true });89 assert.equal(device, null);90 });91 it('returns no devices if no native support and cardboard is false', async function () {92 const global = new MockGlobal();93 makeMobile(global);94 const device = await requestDevice(global, { cardboard: false });95 assert.equal(device, null);96 });...
Using AI Code Generation
1function test() {2 navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]})3 .then(device => {4 console.log("Device Name: " + device.name);5 console.log("Device ID: " + device.id);6 console.log("Device UUIDs: " + device.uuids);7 console.log("Device Connected: " + device.gatt.connected);8 })9 .catch(error => {10 console.log("Error: " + error);11 });12}13function test() {14 navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]})15 .then(device => {16 console.log("Device Name: " + device.name);17 console.log("Device ID: " + device.id);18 console.log("Device UUIDs: " + device.uuids);19 console.log("Device Connected: " + device.gatt.connected);20 })21 .catch(error => {22 console.log("Error: " + error);23 });24}25function test() {26 navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]})27 .then(device => {28 console.log("Device Name: " + device.name);29 console.log("Device ID: " + device.id);30 console.log("Device UUIDs: " + device.uuids);31 console.log("Device Connected: " + device.gatt.connected);32 })33 .catch(error => {34 console.log("Error: " + error);35 });36}37function test() {38 navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]})39 .then(device => {40 console.log("Device Name: " + device.name);41 console.log("Device ID: " + device.id);42 console.log("Device UUIDs: " + device.uuids);43 console.log("Device Connected: " + device.gatt.connected);44 })45 .catch(error => {46 console.log("Error: " + error);47 });48}49function test() {50 navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]})51 .then(device => {
Using AI Code Generation
1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org');3api.requestDevice('Nexus 5', function(err, data) {4 if (err) {5 console.error(err);6 }7 else {8 console.log(data);9 }10});11var wpt = require('webpagetest');12var api = new wpt('www.webpagetest.org');13api.requestLocations(function(err, data) {14 if (err) {15 console.error(err);16 }17 else {18 console.log(data);19 }20});21var wpt = require('webpagetest');22var api = new wpt('www.webpagetest.org');23api.requestLocation('Dulles:Chrome', function(err, data) {24 if (err) {25 console.error(err);26 }27 else {28 console.log(data);29 }30});31var wpt = require('webpagetest');32var api = new wpt('www.webpagetest.org');33api.requestTesters('Dulles:Chrome', function(err, data) {34 if (err) {35 console.error(err);36 }37 else {38 console.log(data);39 }40});41var wpt = require('webpagetest');42var api = new wpt('www.webpagetest.org');43api.requestTesters('Dulles:Chrome', function(err, data) {44 if (err) {45 console.error(err);46 }47 else {48 console.log(data);49 }50});51var wpt = require('webpagetest');52var api = new wpt('www.webpagetest.org');53api.requestTestStatus('150708_4D_1c4d8e5b5a5f5d5b5a5f5d5b
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools();3wp.requestDevice('iPhone 6', function(err, device) {4 if (err) {5 console.log(err);6 } else {7 console.log(device);8 }9});10### new wptools([options])11### wptools.requestDevice(deviceName, callback)12### wptools.releaseDevice(deviceId, callback)13### wptools.runTest(url, [options], callback)
Using AI Code Generation
1var wptools = require('wptools');2wptools.requestDevice('iphone_5s', function(device) {3 console.log(device);4});5### requestDevice(device, callback)6MIT © [Sam Verschueren](
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools();3wp.requestDevice(function(err, data){4 if(err){5 console.log(err);6 }else{7 console.log(data);8 }9});10For more information about the API, please visit the [Wiki](
Using AI Code Generation
1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org');3api.requestDevice('Nexus 5', function(err, data) {4 console.log(data);5 api.getDevices(function(err, data) {6 console.log(data);7 api.releaseDevice('Nexus 5', function(err, data) {8 console.log(data);9 api.getDevices(function(err, data) {10 console.log(data);11 });12 });13 });14});
Using AI Code Generation
1function requestDevice() {2 var request = new XMLHttpRequest();3 request.setRequestHeader("Content-Type", "application/json");4 request.onreadystatechange = function () {5 if (request.readyState === 4) {6 }7 };8 var body = {9 "properties": {10 },11 };12 request.send(JSON.stringify(body));13}14function getDevice() {15 var request = new XMLHttpRequest();16 request.onreadystatechange = function () {17 if (request.readyState === 4) {18 }19 };20 request.send();21}22function updateDevice() {23 var request = new XMLHttpRequest();24 request.setRequestHeader("Content-Type", "application/json");25 request.onreadystatechange = function () {26 if (request.readyState === 4) {27 }28 };29 var body = {30 "properties": {31 },32 };33 request.send(JSON.stringify(body));34}35function deleteDevice() {36 var request = new XMLHttpRequest();37 request.onreadystatechange = function () {38 if (request.readyState === 4) {39 }40 };
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!!