How to use cancelRejection method in Best

Best JavaScript code snippet using best

itemApprovalDetailsController.js

Source:itemApprovalDetailsController.js Github

copy

Full Screen

1(function () {2 "use strict";34 function itemApprovalDetailsController($rootScope, $scope, $http, CONSTANTS, $state, GenericService, commonDetailService, rejectReasonService, StatusService, growl) {5 var self = this;6 var itemId;7 var PrId;89 //Default Constructor10 function initializeController() {11 $rootScope.loginpage = true;1213 self.model = {14 SelectedItems: []15 };16 17 StatusService.GetStatus().then(function(status){18 self.model.statusList = status;19 });2021 rejectReasonService.GetReason().then(function(reason) {22 self.model.rejectReasons = reason;23 });2425 self.model.NavigateToBack = NavigateToBack;26 self.model.RejectionPopup = RejectionPopup;27 self.model.SelectItem = SelectItem;28 self.model.SelectAllItems = SelectAllItems;29 self.model.SaveApproval = SaveApproval;30 self.model.SaveAcceptReject = SaveAcceptReject;31 self.model.ModalDismiss = ModalDismiss;32 self.model.isDisable = isDisable;33 GetPurchaseRequest(commonDetailService.getDataId());34 }3536 var setStatus = function (x){37 var status = self.model.statusList.find(function(obj){38 return obj.status == x;39 });40 41 return status.id;42 }4344 var GetPurchaseRequest = function (purchaseId) {45 commonDetailService.setDataId(null);46 PrId = purchaseId;47 var URI = CONSTANTS.PROCUREMENT.PURCHASE.ITEM_APPROVAL.DETAILS_API + purchaseId;4849 $rootScope.startLoader();50 GenericService.serviceAction("GET", URI, {}).then(51 function (response) {52 self.model.approvalItems = response.data;53 self.model.requestItems = JSON.parse(JSON.stringify(response.data.items));54 self.model.approvalItems.items.forEach(function(item){55 item.isDisabled = true;56 });57 self.model.reasons = self.model.rejectReasons;58 $rootScope.stopLoader();59 },60 function (err) {61 $rootScope.stopLoader();62 growl.error(err.data.message);63 });64 }65 66 var ModalDismiss = function (popupName) {67 var popup = angular.element('#' + popupName);68 popup.modal('hide');69 }7071 var RejectionPopup = function (item) {72 if (item.isReject) {73 itemId = item.id;74 self.model.action = 'Open';75 var popup = angular.element('#qtyaccepatReject');76 popup.modal('show');77 self.model.rejectReason = self.model.reasons[0];78 } else {79 CancelRejection(item);80 }81 }8283 var CancelRejection = function (item) {84 var prevRequest = self.model.requestItems.find(function(prevItem){85 return prevItem.id == item.id;86 });87 88 if (prevRequest) {89 item.rejectReasonId = prevRequest.rejectReasonId;90 }91 }9293 var SaveAcceptReject = function () {94 if (ValidateRejection()) {95 var rejectItemId = itemId;96 self.model.SelectedItems.forEach(function(item){97 if (item.id == rejectItemId) {98 // item.statusId = setStatus('Reject');99 item.rejectReasonId = self.model.rejectReason.id;100 item.rejectNote = self.model.rejectNote;101 }102 ModalDismiss('qtyaccepatReject');103 });104 }105 }106107 var ValidateApproval = function () {108 var isValid = true;109110 if (!self.model.SelectedItems || self.model.SelectedItems.length == 0) {111 growl.error('Select Items to Update and Save');112 isValid = false;113 }114115 return isValid;116 }117118 var ValidateRejection = function () {119 var isValid = true;120 if (!self.model.rejectReason) {121 isValid = false;122 growl.error('Please Select Reason to Reject');123 }124125 return isValid;126 }127128 var SaveApproval = function () {129 if (ValidateApproval()) {130 var URI = CONSTANTS.PROCUREMENT.PURCHASE.ITEM_APPROVAL.SAVE_API + PrId;131132 var data = {133 "items": []134 }135136 $rootScope.startLoader();137138 self.model.approvalItems.items.forEach(function (item) {139 if (item.isSelected) {140 if (item.isReject) {141 data.items.push({142 "id": item.id,143 "statusId": setStatus('Reject'),144 "rejectReasonId": item.rejectReasonId,145 "rejectNote": item.rejectNote146 });147 }148 else {149 data.items.push({150 "id": item.id,151 "statusId": setStatus('Approved'),152 "rejectReasonId": self.model.reasons[0].id,153 "rejectNote": null154 });155 }156157 var statusHash = {};158 data.statusId = null;159 data.approvalStatusId = null;160161 data.items.forEach(function(rec) {162 var statusId = rec.statusId;163 statusHash[statusId] = true;164 });165166 var statuses = Object.keys(statusHash);167 if(statuses.length > 1) {168 data.statusId = setStatus('Pending');169 data.approvalStatusId = setStatus('Partially Approved');170 } else if(statuses[0] == 5) {171 data.statusId = setStatus('Pending');172 data.approvalStatusId = setStatus('Approved');173 } else if(statuses[0] == 7) {174 data.statusId = setStatus('Closed');175 data.approvalStatusId = setStatus('Reject');176 } else {177 data.statusId = setStatus('Pending');178 data.approvalStatusId = setStatus('Partially Approved');179 }180 }181 });182183 // angular.forEach(self.model.SelectedItems, function (item) {184 // var newItem = {185 // "id": item.id,186 // "rejectReasonId": item.rejectReasonId ? item.rejectReasonId : "1",187 // "rejectNote": item.rejectNote,188 // "statusId": item.statusId189 // }190191 // data.items.push(newItem);192193 // var statusHash = {};194 // data.statusId = null;195 // data.approvalStatusId = null;196197 // data.items.forEach(function(rec) {198 // var statusId = rec.statusId;199 // statusHash[statusId] = true;200 // });201202 // var statuses = Object.keys(statusHash);203 // if(statuses.length > 1) {204 // data.statusId = setStatus('Pending');205 // data.approvalStatusId = setStatus('Partially Approved');206 // } else if(statuses[0] == 5) {207 // data.statusId = setStatus('Pending');208 // data.approvalStatusId = setStatus('Approved');209 // } else if(statuses[0] == 7) {210 // data.statusId = setStatus('Closed');211 // data.approvalStatusId = setStatus('Reject');212 // } else {213 // data.statusId = setStatus('Pending');214 // data.approvalStatusId = setStatus('Partially Approved');215 // }216 // });217218 GenericService.serviceAction("PATCH", URI, data).then(219 function(response){220 $rootScope.stopLoader();221 growl.success(response.data.message);222 NavigateToBack();223 }, function (err) {224 $rootScope.stopLoader();225 growl.error(err.data.message);226 });227 }228 }229230 var NavigateToBack = function () {231 $state.go('itemApproval');232 }233234 var isSelected = function (item) {235 return item.isSelected;236 }237238 var SelectAllItems = function () {239 if (self.model.selectAllRows) {240 self.model.approvalItems.items.forEach(function (item) {241 if (!isDisable(item)) {242 item.isSelected = true;243 item.isDisabled = false;244 self.model.SelectedItems.push(item.id);245 }246 });247 } else {248 self.model.SelectedItems = [];249 self.model.approvalItems.items.forEach(function (item) {250 CancelRejection(item);251 item.isSelected = false;252 item.isDisabled = true;253 item.isReject = false;254 });255 }256 }257258 var SelectItem = function (item) {259 var items = self.model.SelectedItems;260261 if (item.isSelected) {262 items.push(item);263 item.isDisabled = false;264 } else {265 item.isDisabled = true;266 item.isReject = false;267 CancelRejection(item);268 var index = items.indexOf(item);269 if (index > -1) {270 items.splice(index, 1);271 }272 }273274 if (self.model.approvalItems.items.every(isSelected)) {275 self.model.selectAllRows = true;276 } else {277 self.model.selectAllRows = false;278 }279 }280281 var isDisable = function (item) {282 if (item.statusId == 5 || item.statusId == 7 || item.statusId == 9 || item.statusId == 8) {283 return true;284 }285 return false;286 }287288 initializeController();289 }290291 function config($stateProvider) {292 $stateProvider.state("itemApprovalDetails", {293 url: "/itemApprovalDetails",294 templateUrl: 'views/procurement/purchase/item-approval-details.html',295 controller: "ItemApprovalDetails.Controller",296 controllerAs: "vm"297 });298 }299300 angular301 .module("myApp")302 .config(config)303 .controller("ItemApprovalDetails.Controller", itemApprovalDetailsController); ...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1import React, { PureComponent, Fragment } from 'react';2import { withRouter } from 'next/router';3import { Query, graphql, withApollo } from 'react-apollo';4import _flowRight from 'lodash/flowRight';5import _get from 'lodash/get';6import Head from 'next/head';7import { message } from 'antd';8import { Loading } from '~/components';9import GeneralErrorPage from '~/routes/GeneralErrorPage';10import { usePrivateApp } from '~/util/authUtils';11import AppointmentConfirmationView from './view';12import {13 getAppointmentsQuery,14 acceptOrRejectAppointmentRequestMutation,15} from './queries';16const VALID_STATUSES = [17 'ACTIVE',18 'REJECTED_BY_PATIENT',19 'PENDING_PATIENT_APPROVAL',20];21class AppointmentConfirmationPage extends PureComponent {22 constructor(props) {23 super(props);24 const { router } = this.props;25 const urlParams = router.query;26 this.appointmentId = urlParams.appointmentId;27 this.state = {28 showModal: false,29 isModalSubmitting: false,30 isCardSubmitting: false,31 status: 'PENDING_PATIENT_APPROVAL',32 };33 }34 acceptAppointmentRequest = async () => {35 this.setState({ isCardSubmitting: true });36 const {37 acceptOrRejectAppointmentRequestMutation: acceptOrRejectAppointmentRequest,38 } = this.props;39 try {40 await acceptOrRejectAppointmentRequest({41 variables: {42 input: {43 accept: true,44 appointmentId: this.appointmentId,45 },46 },47 });48 this.setState({49 showModal: false,50 status: 'ACTIVE',51 });52 } catch (err) {53 if (err.message.includes('Forbidden')) {54 message.error(55 'Forbidden: User is not allowed to do the action.',56 557 );58 }59 } finally {60 this.setState({ isCardSubmitting: false });61 }62 };63 rejectAppointmentRequest = () => {64 this.setState({ showModal: true });65 };66 confirmRejection = async () => {67 this.setState({ isModalSubmitting: true });68 const {69 acceptOrRejectAppointmentRequestMutation: acceptOrRejectAppointmentRequest,70 } = this.props;71 try {72 await acceptOrRejectAppointmentRequest({73 variables: {74 input: {75 accept: false,76 appointmentId: this.appointmentId,77 },78 },79 });80 this.setState({81 showModal: false,82 status: 'REJECTED_BY_PATIENT',83 });84 } catch (err) {85 if (err.message.includes('Forbidden')) {86 message.error(87 'Forbidden: User is not allowed to do the action.',88 589 );90 }91 } finally {92 this.setState({ isModalSubmitting: false });93 }94 };95 cancelRejection = () => {96 this.setState({ showModal: false });97 };98 render() {99 const { appointmentId } = this;100 if (!appointmentId) {101 throw new Error('Must specify appointmentId');102 }103 return (104 <Fragment>105 <Head>Laguro</Head>106 <Query107 query={getAppointmentsQuery}108 variables={{ id: appointmentId }}109 onCompleted={data =>110 this.setState({111 status: _get(data, 'getAppointment.status', ''),112 })113 }114 >115 {({ loading, error, data }) => {116 const {117 showModal,118 isModalSubmitting,119 isCardSubmitting,120 } = this.state;121 const appointment = _get(data, 'getAppointment');122 if (loading) return <Loading />;123 if (124 error ||125 !appointment ||126 !VALID_STATUSES.includes(appointment.status)127 )128 return <GeneralErrorPage />;129 const { status } = this.state;130 return (131 <AppointmentConfirmationView132 appointment={appointment}133 showModal={showModal}134 status={status}135 isCardSubmitting={isCardSubmitting}136 isModalSubmitting={isModalSubmitting}137 onAccept={this.acceptAppointmentRequest}138 onReject={this.rejectAppointmentRequest}139 onConfirmRejection={this.confirmRejection}140 onCancelRejection={this.cancelRejection}141 confirmAppointmentRequestRejection={142 this.confirmAppointmentRequestRejection143 }144 />145 );146 }}147 </Query>148 </Fragment>149 );150 }151}152const withPrivateApp = WrappedComponent => props => {153 const { isRouteAccessible } = usePrivateApp();154 return isRouteAccessible ? <WrappedComponent {...props} /> : null;155};156export default _flowRight(157 withPrivateApp,158 withRouter,159 withApollo,160 graphql(acceptOrRejectAppointmentRequestMutation, {161 name: 'acceptOrRejectAppointmentRequestMutation',162 options: {163 context: {164 clientName: 'appointment',165 },166 },167 })...

Full Screen

Full Screen

articles.ts

Source:articles.ts Github

copy

Full Screen

...29 }30 reject(id: number): Promise<Article> {31 return this.$axios.$post(`${this.path}/${id}/reject`)32 }33 cancelRejection(id: number): Promise<Article> {34 return this.$axios.$post(`${this.path}/${id}/cancelRejection`)35 }36 cancelPublication(id: number): Promise<Article> {37 return this.$axios.$post(`${this.path}/${id}/cancelPublication`)38 }39 publish(id: number): Promise<Article> {40 return this.$axios.$post(`${this.path}/${id}/publish`)41 }42 recently(): Promise<Article[]> {43 return this.$axios.$get(`${this.path}/visited`)44 }45 comments(id: number): Promise<Article[]> {46 return this.$axios.$get(`${this.path}/${id}/comments`)47 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestPromise = require('best-promise');2const promise = new BestPromise((resolve, reject) => {3 setTimeout(() => {4 reject('error');5 }, 1000);6});7promise.then((value) => {8 console.log('resolved value:', value);9}, (error) => {10 console.log('rejected error:', error);11});12promise.cancelRejection();

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestPromise = require('./BestPromise');2const p = new BestPromise((resolve, reject) => {3 console.log('in executor');4 setTimeout(() => {5 console.log('in timeout');6 resolve('hello');7 }, 1000);8});9p.then((value) => {10 console.log('in then');11 console.log(value);12}).catch((err) => {13 console.log('in catch');14 console.log(err);15});16setTimeout(() => {17 p.cancelRejection('cancelled');18}, 500);19const BestPromise = require('./BestPromise');20const p = new BestPromise((resolve, reject) => {21 console.log('in executor');22 setTimeout(() => {23 console.log('in timeout');24 reject('hello');25 }, 1000);26});27p.then((value) => {28 console.log('in then');29 console.log(value);30}).catch((err) => {31 console.log('in catch');32 console.log(err);33});34setTimeout(() => {35 p.cancelRejection('cancelled');36}, 500);37const BestPromise = require('./BestPromise');38const p = new BestPromise((resolve, reject) => {39 console.log('in executor');40 setTimeout(() => {41 console.log('in timeout');42 reject('hello');43 }, 1000);44});45p.then((value) => {46 console.log('in then');47 console.log(value);48}).catch((err) => {49 console.log('in catch');50 console.log(err);51});52setTimeout(() => {53 p.cancelRejection('cancelled');54}, 1500);55const BestPromise = require('./BestPromise');56const p = new BestPromise((resolve, reject) => {57 console.log('in executor');58 setTimeout(() => {59 console.log('in timeout');60 reject('hello');61 }, 1000);62});63p.then((value) => {

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPromise = require('./bestPromise.js');2var p = new BestPromise(function (fulfill, reject) {3 setTimeout(function () {4 reject('REJECTED!');5 }, 300);6});7var cancel = p.cancelRejection();8p.then(null, function (err) {9 console.log(err);10 cancel();11});12var BestPromise = require('./bestPromise.js');13var p = new BestPromise(function (fulfill, reject) {14 setTimeout(function () {15 reject('REJECTED!');16 }, 300);17});18var cancel = p.cancelRejection();19p.then(null, function (err) {20 console.log(err);21 cancel();22});23var BestPromise = require('./bestPromise.js');24var p = new BestPromise(function (fulfill, reject) {25 setTimeout(function () {26 reject('REJECTED!');27 }, 300);28});29var cancel = p.cancelRejection();30p.then(null, function (err) {31 console.log(err);32 cancel();33 cancel();34});35var BestPromise = require('./bestPromise.js');36var p = new BestPromise(function (fulfill, reject) {37 setTimeout(function () {38 fulfill('FULFILLED!');39 }, 300);40});41var cancel = p.cancelRejection();42p.then(null, function (err) {43 console.log(err);44 cancel();45});46var BestPromise = require('./bestPromise.js');47var p = new BestPromise(function (fulfill, reject) {48 setTimeout(function () {49 reject('REJECTED!');50 }, 300);51});52var cancel = p.cancelRejection();53p.then(null, function (err) {54 console.log(err);55 cancel();56});57var BestPromise = require('./bestPromise.js');58var p = new BestPromise(function (fulfill, reject) {59 setTimeout(function () {60 reject('REJECTED!');61 },

Full Screen

Using AI Code Generation

copy

Full Screen

1let BestPromise = require('./BestPromise');2let promise = new BestPromise((resolve, reject) => {3 console.log('Promise is created');4 setTimeout(() => {5 console.log('Promise is resolved');6 resolve(100);7 }, 1000);8});9promise.then((result) => {10 console.log('Promise is fulfilled with ', result);11}, (err) => {12 console.log('Promise is rejected with ', err);13});14setTimeout(() => {15 promise.cancelRejection();16}, 500);17let BestPromise = require('./BestPromise');18let promise = new BestPromise((resolve, reject) => {19 console.log('Promise is created');20 setTimeout(() => {21 console.log('Promise is resolved');22 resolve(100);23 }, 1000);24});25promise.then((result) => {26 console.log('Promise is fulfilled with ', result);27}, (err) => {28 console.log('Promise is rejected with ', err);29});30setTimeout(() => {31 promise.cancelRejection();32}, 1500);33let BestPromise = require('./BestPromise');34let promise = new BestPromise((resolve, reject) => {35 console.log('Promise is created');36 setTimeout(() => {37 console.log('Promise is resolved');38 resolve(100);39 }, 1000);40});41promise.then((result) => {42 console.log('Promise is fulfilled with ', result);43}, (err) => {44 console.log('Promise is rejected with ', err);45});46setTimeout(() => {47 promise.cancelRejection();48}, 1500);49setTimeout(() => {50 promise.then((result) => {51 console.log('Promise is fulfilled with ', result);52 }, (err) => {53 console.log('Promise is rejected with ', err);54 });55}, 2000);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPromise = require('./promise.js');2var promise = new BestPromise(function(resolve, reject){3 setTimeout(function(){4 reject('Error');5 }, 2000);6});7promise.then(function(data){8 console.log('Success', data);9}, function(err){10 console.log('Error', err);11});12setTimeout(function(){13 promise.cancelRejection('Error');14}, 1000);15var BestPromise = require('./promise.js');16var promise = new BestPromise(function(resolve, reject){17 setTimeout(function(){18 reject('Error');19 }, 2000);20});21promise.then(function(data){22 console.log('Success', data);23}, function(err){24 console.log('Error', err);25});26setTimeout(function(){27 promise.cancelRejection('Error');28}, 3000);29var BestPromise = require('./promise.js');30var promise = new BestPromise(function(resolve, reject){31 setTimeout(function(){32 reject('Error');33 }, 2000);34});35promise.then(function(data){36 console.log('Success', data);37}, function(err){38 console.log('Error', err);39});40setTimeout(function(){41 promise.cancelRejection('Error');42}, 3000);43setTimeout(function(){44 promise.then(function(data){45 console.log('Success', data);46 }, function(err){47 console.log('Error', err);48 });49}, 4000);50var BestPromise = require('./promise.js');51var promise = new BestPromise(function(resolve, reject){52 setTimeout(function(){53 reject('Error');54 }, 2000);55});56promise.then(function(data){57 console.log('Success', data);58}, function(err){59 console.log('Error', err);60});61setTimeout(function(){62 promise.cancelRejection('Error');63}, 3000);64setTimeout(function(){65 promise.then(function(data){66 console.log('Success', data);67 }, function(err){68 console.log('Error', err);69 });70}, 4000);71setTimeout(function(){72 promise.then(function(data){73 console.log('Success', data);74 }, function(err){75 console.log('Error', err);76 });77}, 5000);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPromise = require('./bestpromise.js');2var p = new BestPromise(function(resolve,reject){3 setTimeout(function(){4 reject('This is a rejection');5 },2000);6});7p.then(function(data){8 console.log('This is a then handler');9 console.log('Data is: ' + data);10},function(err){11 console.log('This is a catch handler');12 console.log('Error is: ' + err);13});14setTimeout(function(){15 p.cancelRejection();16},1000);

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestBuy = require('./BestBuy');2const bestBuy = new BestBuy();3bestBuy.cancelRejection('5c4c4e4c8f6d0a6b9a6b9a6b');4const BestBuy = require('./BestBuy');5const bestBuy = new BestBuy();6bestBuy.cancelRejection('5c4c4e4c8f6d0a6b9a6b9a6b');7const BestBuy = require('./BestBuy');8const bestBuy = new BestBuy();9bestBuy.cancelRejection('5c4c4e4c8f6d0a6b9a6b9a6b');10const BestBuy = require('./BestBuy');11const bestBuy = new BestBuy();12bestBuy.cancelRejection('5c4c4e4c8f6d0a6b9a6b9a6b');13const BestBuy = require('./BestBuy');14const bestBuy = new BestBuy();15bestBuy.cancelRejection('5c4c4e4c8f6d0a6b9a6b9a6b');16const BestBuy = require('./BestBuy');17const bestBuy = new BestBuy();18bestBuy.cancelRejection('5c4c4e4c8f6d0a6b9a6b9a6b');19const BestBuy = require('./BestBuy');20const bestBuy = new BestBuy();21bestBuy.cancelRejection('5c4c4e4c8f6d0a6b9

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful