How to use fulfill method in Playwright Python

Best Python code snippet using playwright-python

async-iteration-yield-star.js

Source:async-iteration-yield-star.js Github

copy

Full Screen

1var assert = function (result, expected, message = "") {2 if (result !== expected) {3 throw new Error('Error in assert. Expected "' + expected + '" but was "' + result + '":' + message );4 }5};6const Logger = function () {7 var log = [];8 this.logEvent = (type, value, done) => {9 log.push({ type, value, done});10 };11 this.logFulfilledEvent = (value, done) => {12 this.logEvent('fulfilled', value, done);13 };14 this.logRejectEvent = error => {15 this.logEvent('reject', error.toString(), true);16 };17 this.logCatchEvent = value => {18 this.logEvent('catch', value, true);19 };20 this.logCustomEvent = event => {21 this.logEvent('custom', event, false);22 };23 this.getLogger = () => log;24 this.clear = () => {25 log = [];26 }27};28const fulfillSpy = logger => result => logger.logFulfilledEvent(result.value, result.done);29const rejectSpy = logger => error => logger.logRejectEvent(error);30const catchSpy = logger => error => logger.logCatchEvent(error);31const customSpy = logger => event => logger.logCustomEvent(event);32const assertLogger = function (loggerObject) {33 const logger = loggerObject.getLogger();34 var _assertLogger = function () {35 let index = 0;36 const isNotOutOfLength = () => {37 assert(index < logger.length, true, `Index is greater then log length`); 38 }39 this.fullfilled = function (expectedValue, message = 'on fulfill') {40 isNotOutOfLength();41 const msg = `step: ${index} - ${message}`;42 let step = logger[index];43 assert(step.type, 'fulfilled', msg);44 assert(step.value, expectedValue, msg);45 assert(step.done, false, msg);46 index++;47 return this;48 };49 this.fullfilledDone = function (expectedValue, message = 'on fulfill with done true') {50 isNotOutOfLength();51 const msg = `step: ${index} - ${message}`;52 let step = logger[index];53 assert(step.type, 'fulfilled', msg);54 assert(step.value, expectedValue, msg);55 assert(step.done, true, msg);56 index++;57 return this;58 };59 this.rejected = function (error, message = 'on reject') {60 isNotOutOfLength();61 const msg = `step: ${index} - ${message}`;62 let step = logger[index];63 assert(step.type, 'reject', msg);64 assert(step.value, error.toString(), msg);65 assert(step.done, true, msg);66 index++;67 return this;68 };69 this.catched = function (expectedError, message = 'on catch') {70 isNotOutOfLength();71 const msg = `step: ${index} - ${message}`;72 let step = logger[index];73 assert(step.type, 'catch', msg);74 assert(step.value, expectedError, msg);75 assert(step.done, true, msg);76 index++;77 return this;78 };79 this.custom = function (expectedValue, message = 'on custom event') {80 const msg = `step: ${index} - ${message}`;81 let step = logger[index];82 assert(step.type, 'custom', msg);83 assert(step.value, expectedValue, msg);84 assert(step.done, false, msg);85 index++;86 return this;87 };88 this.isFinal = function (message = '') {89 assert(index, logger.length, `expected final step: ${message}`);90 }; 91 }; 92 93 return new _assertLogger();94};95const getPromise = promiseHolder => {96 return new Promise((resolve, reject) => {97 promiseHolder.resolve = resolve;98 promiseHolder.reject = reject;99 });100};101var logger = new Logger();102const someValue = 'some-value';103const errorMessage = 'error-message';104async function * foo(value) {105 let re = yield '1:' + value;106 re = yield '2:' + re;107 re = yield '3:' + re;108 return 'end foo:' + re;109}110async function * boo(value) {111 let reply = yield '0:' + value;112 reply = yield* foo(reply);113 yield '4:' + reply;114}115var b = boo('init');116b.next('0').then(fulfillSpy(logger));117b.next('1').then(fulfillSpy(logger));118b.next('2').then(fulfillSpy(logger));119b.next('3').then(fulfillSpy(logger));120b.next('4').then(fulfillSpy(logger));121b.next('5').then(fulfillSpy(logger));122drainMicrotasks();123assertLogger(logger)124 .fullfilled('0:init')125 .fullfilled('1:1')126 .fullfilled('2:2')127 .fullfilled('3:3')128 .fullfilled('4:end foo:4')129 .fullfilledDone(undefined)130 .isFinal();131logger.clear();132var b2 = boo(':value');133b2.next(':0').then(fulfillSpy(logger));134b2.next(':1').then(fulfillSpy(logger), rejectSpy(logger));135b2.return(someValue).then(fulfillSpy(logger), rejectSpy(logger));136b2.next(':2').then(fulfillSpy(logger));137b2.next(':3').then(fulfillSpy(logger));138b2.next(':4').then(fulfillSpy(logger));139drainMicrotasks();140assertLogger(logger)141 .fullfilled('0::value')142 .fullfilled('1::1')143 .fullfilledDone(someValue)144 .fullfilledDone(undefined)145 .fullfilledDone(undefined)146 .fullfilledDone(undefined)147 .isFinal();148logger.clear();149var b2 = boo('#value');150b2.next('#0').then(fulfillSpy(logger), rejectSpy(logger));151b2.next('#1').then(fulfillSpy(logger), rejectSpy(logger));152b2.next('#2').then(fulfillSpy(logger), rejectSpy(logger));153b2.throw(new Error(errorMessage)).then(fulfillSpy(logger), rejectSpy(logger));154b2.next('#3').then(fulfillSpy(logger), rejectSpy(logger));155b2.next('#4').then(fulfillSpy(logger), rejectSpy(logger));156drainMicrotasks();157assertLogger(logger)158 .fullfilled('0:#value')159 .fullfilled('1:#1')160 .fullfilled('2:#2')161 .rejected(new Error(errorMessage))162 .fullfilledDone(undefined)163 .fullfilledDone(undefined)164 .isFinal();165async function * bar() {166 yield '1';167 yield '2';168 throw new Error(errorMessage);169 yield '3';170 return 'end foo';171}172async function * baz() {173 yield '0';174 yield* bar();175 yield '4';176}177logger.clear();178var bz1 = baz();179bz1.next().then(fulfillSpy(logger), rejectSpy(logger));180bz1.next().then(fulfillSpy(logger), rejectSpy(logger));181bz1.next().then(fulfillSpy(logger), rejectSpy(logger));182bz1.next().then(fulfillSpy(logger), rejectSpy(logger));183bz1.next().then(fulfillSpy(logger), rejectSpy(logger));184drainMicrotasks();185assertLogger(logger)186 .fullfilled('0')187 .fullfilled('1')188 .fullfilled('2')189 .rejected(new Error(errorMessage))190 .fullfilledDone(undefined)191 .isFinal();192logger.clear();193let promiseHolder = {};194async function *joo() {195 yield '1';196 yield getPromise(promiseHolder);197}198async function *goo () {199 yield '0';200 yield* joo();201 yield '3';202}203let g = goo();204g.next().then(fulfillSpy(logger), rejectSpy(logger));205g.next().then(fulfillSpy(logger), rejectSpy(logger));206g.next().then(fulfillSpy(logger), rejectSpy(logger));207g.next().then(fulfillSpy(logger), rejectSpy(logger));208g.next().then(fulfillSpy(logger), rejectSpy(logger));209drainMicrotasks();210assertLogger(logger)211 .fullfilled('0')212 .fullfilled('1')213 .isFinal();214promiseHolder.resolve('2');215drainMicrotasks();216assertLogger(logger)217 .fullfilled('0')218 .fullfilled('1')219 .fullfilled('2')220 .fullfilled('3')221 .fullfilledDone(undefined)222 .isFinal();223logger.clear();224g = goo();225g.next().then(fulfillSpy(logger), rejectSpy(logger));226g.next().then(fulfillSpy(logger), rejectSpy(logger));227g.next().then(fulfillSpy(logger), rejectSpy(logger));228g.next().then(fulfillSpy(logger), rejectSpy(logger));229g.next().then(fulfillSpy(logger), rejectSpy(logger));230drainMicrotasks();231assertLogger(logger)232 .fullfilled('0')233 .fullfilled('1')234 .isFinal();235promiseHolder.reject('#2');236drainMicrotasks();237assertLogger(logger)238 .fullfilled('0')239 .fullfilled('1')240 .rejected('#2')241 .fullfilledDone(undefined)242 .fullfilledDone(undefined)243 .isFinal();244logger.clear();245g = goo();246g.next().then(fulfillSpy(logger), rejectSpy(logger));247g.next().then(fulfillSpy(logger), rejectSpy(logger));248g.return(someValue).then(fulfillSpy(logger), rejectSpy(logger));249g.next().then(fulfillSpy(logger), rejectSpy(logger));250g.next().then(fulfillSpy(logger), rejectSpy(logger));251drainMicrotasks();252assertLogger(logger)253 .fullfilled('0')254 .fullfilled('1')255 .fullfilledDone(someValue)256 .fullfilledDone(undefined)257 .fullfilledDone(undefined)258 .isFinal();259logger.clear();260g = goo();261g.next().then(fulfillSpy(logger), rejectSpy(logger));262g.next().then(fulfillSpy(logger), rejectSpy(logger));263g.next().then(fulfillSpy(logger), rejectSpy(logger));264g.return(someValue).then(fulfillSpy(logger), rejectSpy(logger));265g.next().then(fulfillSpy(logger), rejectSpy(logger));266g.next().then(fulfillSpy(logger), rejectSpy(logger));267drainMicrotasks();268assertLogger(logger)269 .fullfilled('0')270 .fullfilled('1')271 .isFinal();272promiseHolder.resolve('#2');273drainMicrotasks();274assertLogger(logger)275 .fullfilled('0')276 .fullfilled('1')277 .fullfilled('#2')278 .fullfilledDone(someValue)279 .fullfilledDone(undefined)280 .fullfilledDone(undefined)281 .isFinal();282logger.clear();283g = goo();284g.next().then(fulfillSpy(logger), rejectSpy(logger));285g.next().then(fulfillSpy(logger), rejectSpy(logger));286g.next().then(fulfillSpy(logger), rejectSpy(logger));287g.return(someValue).then(fulfillSpy(logger), rejectSpy(logger));288g.next().then(fulfillSpy(logger), rejectSpy(logger));289g.next().then(fulfillSpy(logger), rejectSpy(logger));290drainMicrotasks();291assertLogger(logger)292 .fullfilled('0')293 .fullfilled('1')294 .isFinal();295promiseHolder.reject('#2');296drainMicrotasks();297assertLogger(logger)298 .fullfilled('0')299 .fullfilled('1')300 .rejected('#2')301 .fullfilledDone(someValue)302 .fullfilledDone(undefined)303 .fullfilledDone(undefined)304 .isFinal();305logger.clear();306g = goo();307g.next().then(fulfillSpy(logger), rejectSpy(logger));308g.next().then(fulfillSpy(logger), rejectSpy(logger));309g.throw(new Error(errorMessage)).then(fulfillSpy(logger), rejectSpy(logger));310g.next().then(fulfillSpy(logger), rejectSpy(logger));311g.next().then(fulfillSpy(logger), rejectSpy(logger));312drainMicrotasks();313assertLogger(logger)314 .fullfilled('0')315 .fullfilled('1')316 .rejected(new Error(errorMessage))317 .fullfilledDone(undefined)318 .fullfilledDone(undefined)319 .isFinal();320promiseHolder.resolve('#2');321drainMicrotasks();322assertLogger(logger)323 .fullfilled('0')324 .fullfilled('1')325 .rejected(new Error(errorMessage))326 .fullfilledDone(undefined)327 .fullfilledDone(undefined)328 .isFinal();329logger.clear();330g = goo();331g.next().then(fulfillSpy(logger), rejectSpy(logger));332g.next().then(fulfillSpy(logger), rejectSpy(logger));333g.next().then(fulfillSpy(logger), rejectSpy(logger));334g.throw(new Error(errorMessage)).then(fulfillSpy(logger), rejectSpy(logger));335g.next().then(fulfillSpy(logger), rejectSpy(logger));336g.next().then(fulfillSpy(logger), rejectSpy(logger));337drainMicrotasks();338assertLogger(logger)339 .fullfilled('0')340 .fullfilled('1')341 .isFinal();342promiseHolder.resolve('#2');343drainMicrotasks();344assertLogger(logger)345 .fullfilled('0')346 .fullfilled('1')347 .fullfilled('#2')348 .rejected(new Error(errorMessage))349 .fullfilledDone(undefined)350 .fullfilledDone(undefined)351 .isFinal();352logger.clear();353g = goo();354g.next().then(fulfillSpy(logger), rejectSpy(logger));355g.next().then(fulfillSpy(logger), rejectSpy(logger));356g.next().then(fulfillSpy(logger), rejectSpy(logger));357g.throw(new Error(errorMessage)).then(fulfillSpy(logger), rejectSpy(logger));358g.next().then(fulfillSpy(logger), rejectSpy(logger));359g.next().then(fulfillSpy(logger), rejectSpy(logger));360drainMicrotasks();361assertLogger(logger)362 .fullfilled('0')363 .fullfilled('1')364 .isFinal();365promiseHolder.reject('#2');366drainMicrotasks();367assertLogger(logger)368 .fullfilled('0')369 .fullfilled('1')370 .rejected('#2')371 .rejected(new Error(errorMessage))372 .fullfilledDone(undefined)373 .fullfilledDone(undefined)374 .isFinal();375logger.clear();376async function *koo() {377 yield '1';378 await getPromise(promiseHolder);379}380async function *loo () {381 yield '0';382 yield* joo();383 yield '3';384}385let l = loo();386l.next().then(fulfillSpy(logger), rejectSpy(logger));387l.next().then(fulfillSpy(logger), rejectSpy(logger));388l.next().then(fulfillSpy(logger), rejectSpy(logger));389l.next().then(fulfillSpy(logger), rejectSpy(logger));390l.next().then(fulfillSpy(logger), rejectSpy(logger));391drainMicrotasks();392 assertLogger(logger)393 .fullfilled("0")394 .fullfilled("1")395 .isFinal();396promiseHolder.resolve('#2');397drainMicrotasks();398assertLogger(logger)399 .fullfilled('0')400 .fullfilled('1')401 .fullfilled('#2')402 .fullfilled("3")403 .fullfilledDone(undefined)404 .isFinal();405logger.clear();406l = loo();407l.next().then(fulfillSpy(logger), rejectSpy(logger));408l.next().then(fulfillSpy(logger), rejectSpy(logger));409l.next().then(fulfillSpy(logger), rejectSpy(logger));410l.next().then(fulfillSpy(logger), rejectSpy(logger));411l.next().then(fulfillSpy(logger), rejectSpy(logger));412drainMicrotasks();413assertLogger(logger)414 .fullfilled("0")415 .fullfilled("1")416 .isFinal();417promiseHolder.reject('#2');418drainMicrotasks();419assertLogger(logger)420 .fullfilled('0')421 .fullfilled('1')422 .rejected('#2')423 .fullfilledDone(undefined)424 .fullfilledDone(undefined)425 .isFinal();426logger.clear();427let asyncIter = {428 [Symbol.asyncIterator]() { return this; },429 next (value) {430 customSpy(logger)('next:' + value);431 return { value: value, done: 'iter:Finish' === value };432 },433 throw (error) {434 customSpy(logger)('throw:' + error);435 return error;436 },437 return(value) {438 customSpy(logger)('return:' + value);439 return { value: value, done: true };440 }441 };442async function *moo () {443 yield '0';444 yield* asyncIter;445 yield '3';446}447let m = moo('Init');448m.next('A').then(fulfillSpy(logger), rejectSpy(logger));449m.next('B').then(fulfillSpy(logger), rejectSpy(logger));450m.next('C').then(fulfillSpy(logger), rejectSpy(logger));451m.next('D').then(fulfillSpy(logger), rejectSpy(logger));452m.next('E').then(fulfillSpy(logger), rejectSpy(logger));453m.next('iter:Finish').then(fulfillSpy(logger), rejectSpy(logger));454m.next('Finish').then(fulfillSpy(logger), rejectSpy(logger));455drainMicrotasks();456assertLogger(logger)457 .custom('next:undefined')458 .fullfilled('0')459 .custom('next:C')460 .fullfilled(undefined)461 .custom('next:D')462 .fullfilled('C')463 .custom('next:E')464 .fullfilled('D')465 .custom('next:iter:Finish')466 .fullfilled('E')467 .fullfilled('3')468 .fullfilledDone(undefined)469 .isFinal();470logger.clear();471m = moo('Init');472m.next('A').then(fulfillSpy(logger), rejectSpy(logger));473m.next('B').then(fulfillSpy(logger), rejectSpy(logger));474m.return('C').then(fulfillSpy(logger), rejectSpy(logger));475m.next('D').then(fulfillSpy(logger), rejectSpy(logger));476m.next('E').then(fulfillSpy(logger), rejectSpy(logger));477m.next('iter:Finish').then(fulfillSpy(logger), rejectSpy(logger));478m.next('Finish').then(fulfillSpy(logger), rejectSpy(logger));479drainMicrotasks();480assertLogger(logger)481 .custom('next:undefined')482 .fullfilled('0')483 .custom('return:C')484 .fullfilled(undefined)485 .fullfilledDone('C')486 .fullfilledDone(undefined)487 .fullfilledDone(undefined)488 .fullfilledDone(undefined)489 .fullfilledDone(undefined)490 .isFinal();491logger.clear();492m = moo('Init');493m.next('A').then(fulfillSpy(logger), rejectSpy(logger));494m.next('B').then(fulfillSpy(logger), rejectSpy(logger));495m.throw(new Error(errorMessage)).then(fulfillSpy(logger), rejectSpy(logger));496m.next('D').then(fulfillSpy(logger), rejectSpy(logger));497m.next('E').then(fulfillSpy(logger), rejectSpy(logger));498m.next('iter:Finish').then(fulfillSpy(logger), rejectSpy(logger));499m.next('Finish').then(fulfillSpy(logger), rejectSpy(logger));500drainMicrotasks();501assertLogger(logger)502 .custom('next:undefined')503 .fullfilled('0')504 .custom('throw:' + new Error(errorMessage))505 .fullfilled(undefined)506 .custom('next:D')507 .fullfilled(undefined)508 .custom('next:E')509 .fullfilled('D')510 .custom('next:iter:Finish')511 .fullfilled('E')512 .fullfilled('3')513 .fullfilledDone(undefined)514 .isFinal();515logger.clear();516async function* noo() {517 try {518 await Promise.reject("doop");519 } finally {520 yield* [1, 2, 3]; // Is this line reachable in this implementation?521 }522}523const n = noo();524n.next().then(fulfillSpy(logger), rejectSpy(logger));525n.next().then(fulfillSpy(logger), rejectSpy(logger));526n.next().then(fulfillSpy(logger), rejectSpy(logger));527n.next().then(fulfillSpy(logger), rejectSpy(logger));528n.next().then(fulfillSpy(logger), rejectSpy(logger));529drainMicrotasks();530assertLogger(logger)531 .fullfilled(1)532 .fullfilled(2)533 .fullfilled(3)...

Full Screen

Full Screen

Quote.js

Source:Quote.js Github

copy

Full Screen

1var Sequelize = require('sequelize');2var configs = require("../config/configs");3var leadsInfoSchema = require("../mysql/Lead_Info");4var quoteComponent = require("../components/Quote");5var quoteDetailSchema = require("../mysql/Quote_Details");6var SAschema = require("../mysql/ServiceAgreement");7var Q = require('q');8var mysqlCredentials = configs.getMysqlCredentials();9var sequelize = require("../mysql/sequelize");10var quoteSchema = sequelize.define('quote',{11 id: {type:Sequelize.INTEGER,primaryKey:true, autoIncrement: true},12 leads_id: {type:Sequelize.INTEGER},13 created_by: {type:Sequelize.INTEGER},14 created_by_type: {type:Sequelize.STRING},15 status: {type:Sequelize.STRING},16 quote_no: {type:Sequelize.INTEGER},17 date_quoted: {type:Sequelize.DATE},18 date_posted: {type:Sequelize.DATE},19 ran: {type: Sequelize.STRING}20},{21 freezeTableName : true,22 timestamps: false,23 classMethods:24 {25 getLeadsID:function(id,leads_id){26 var willFulfillDeferred = Q.defer();27 var willFulfill = willFulfillDeferred.promise;28 if(id){29 quoteSchema.findOne({30 attributes:[31 'leads_id','created_by','created_by_type',32 'status','date_quoted','date_posted','ran'33 ],34 where:{35 id : id36 }37 }).then(function(foundObject){38 willFulfillDeferred.resolve(foundObject);39 });40 }41 else if(leads_id)42 {43 quoteSchema.findAll({44 attributes:[45 'leads_id','created_by','created_by_type',46 'status','date_quoted','date_posted','ran'47 ],48 where:{49 leads_id : leads_id50 }51 }).then(function(foundObject){52 willFulfillDeferred.resolve(foundObject);53 });54 }55 else{56 var sql = "SELECT (q.id) as quote_id,q.date_quoted,(l.id) as leads_id,CONCAT(l.fname,' ',l.lname) as fullname,l.email ,l.status,SUM(IF(q.status = 'new', 1,0)) AS 'new_count',"+57 "SUM(IF(q.status = 'posted', 1,0)) AS 'posted_count',"+58 "SUM(IF(q.status = 'draft', 1,0)) AS 'draft_count',"59 +"SUM(IF(q.status = 'deleted', 1,0)) AS 'deleted_count',"60 +"SUM(IF(sa.accepted = 'no', 1,0)) AS 'sa_count_pending' ,"61 +"SUM(IF(sa.accepted = 'yes', 1,0)) AS 'sa_count_accepted' "62 +"FROM leads l "63 +"LEFT JOIN quote q ON q.leads_id = l.id "64 +"LEFT JOIN service_agreement sa ON sa.quote_id = q.id "65 +"WHERE l.status NOT IN ('inactive' , 'REMOVED') "66 +"GROUP BY l.id ORDER by l.id DESC";67 var sql1 = "SELECT * FROM leads";68 sequelize.query(sql69 , { type: sequelize.QueryTypes.SELECT}).then(function(users) {70 if(users)71 {72 willFulfillDeferred.resolve(users);73 }74 users = null;75 });76 }77 return willFulfill;78 },79 searchLead:function(params)80 {81 var willFulfillDeferred = Q.defer();82 var willFulfill = willFulfillDeferred.promise;83 if(!params.filter)84 {85 var sql="SELECT (q.id) as quote_id,q.date_quoted,(l.id) as leads_id,l.fname,l.lname,CONCAT(l.fname,' ',l.lname) as fullname,l.email ,l.status,SUM(IF(q.status = 'new', 1,0)) AS 'new_count',"+86 "SUM(IF(q.status = 'posted', 1,0)) AS 'posted_count',"+87 "SUM(IF(q.status = 'draft', 1,0)) AS 'draft_count',"88 +"SUM(IF(q.status = 'deleted', 1,0)) AS 'deleted_count',"89 // +"SUM(IF(q.status = 'accepted', 1,0)) AS 'accepted_count',"90 +"SUM(IF(sa.accepted = 'no', 1,0)) AS 'sa_count_pending' ,"91 +"SUM(IF(sa.accepted = 'yes', 1,0)) AS 'sa_count_accepted' "92 +"FROM leads l "93 +"LEFT JOIN quote q ON q.leads_id = l.id "94 +"LEFT JOIN service_agreement sa ON sa.quote_id = q.id "95 +"WHERE l.status NOT IN ('inactive' , 'REMOVED') "96 +"AND q.date_quoted BETWEEN '"+params.startDate+"' AND '"+params.endDate+"' "97 +"GROUP BY l.id ORDER by q.id DESC";98 }99 else100 {101 if(params.startDate && params.endDate)102 {103 var sql="SELECT (q.id) as quote_id,q.date_quoted,(l.id) as leads_id,l.fname,l.lname,CONCAT(l.fname,' ',l.lname) as fullname,l.email ,l.status,SUM(IF(q.status = 'new', 1,0)) AS 'new_count',"+104 "SUM(IF(q.status = 'posted', 1,0)) AS 'posted_count',"+105 "SUM(IF(q.status = 'draft', 1,0)) AS 'draft_count',"106 // +"SUM(IF(q.status = 'accepted', 1,0)) AS 'accepted_count',"107 +"SUM(IF(sa.accepted = 'no', 1,0)) AS 'sa_count_pending' ,"108 +"SUM(IF(sa.accepted = 'yes', 1,0)) AS 'sa_count_accepted' "109 +"FROM leads l "110 +"LEFT JOIN quote q ON q.leads_id = l.id "111 +"LEFT JOIN service_agreement sa ON sa.quote_id = q.id "112 +"WHERE l.status NOT IN ('inactive' , 'REMOVED') "113 +"AND q.date_quoted BETWEEN '"+params.startDate+"' AND '"+params.endDate+"' "114 +"AND CONCAT_WS('',q.id, l.id, l.fname,l.lname,CONCAT(l.fname,' ',l.lname),l.email,l.status) LIKE '%"+params.filter+"%' "115 +"GROUP BY l.id ORDER by q.id DESC";116 }117 else118 {119 var sql="SELECT (q.id) as quote_id,q.date_quoted,(l.id) as leads_id,l.fname,l.lname,CONCAT(l.fname,' ',l.lname) as fullname,l.email ,l.status,SUM(IF(q.status = 'new', 1,0)) AS 'new_count',"+120 "SUM(IF(q.status = 'posted', 1,0)) AS 'posted_count',"+121 "SUM(IF(q.status = 'draft', 1,0)) AS 'draft_count',"122 // +"SUM(IF(q.status = 'accepted', 1,0)) AS 'accepted_count',"123 +"SUM(IF(sa.accepted = 'no', 1,0)) AS 'sa_count_pending' ,"124 +"SUM(IF(sa.accepted = 'yes', 1,0)) AS 'sa_count_accepted' "125 +"FROM leads l "126 +"LEFT JOIN quote q ON q.leads_id = l.id "127 +"LEFT JOIN service_agreement sa ON sa.quote_id = q.id "128 +"WHERE l.status NOT IN ('inactive' , 'REMOVED') "129 +"AND l.id="+params.filter+" "130 +"GROUP BY l.id ORDER by q.id DESC";131 }132 }133 sequelize.query(sql134 , { type: sequelize.QueryTypes.SELECT}).then(function(searchData) {135 willFulfillDeferred.resolve(searchData);136 });137 return willFulfill;138//139 },140 getQuotebyLead:function(params){141 var willFulfillDeferred = Q.defer();142 var willFulfill = willFulfillDeferred.promise;143 var status="";144 if(params.status){status=params.status;}145 if(params.status == "no" || params.status == "yes" )146 {147 var sql = "SELECT * FROM quote q LEFT JOIN service_agreement sa on sa.quote_id = q.id "148 +"WHERE q.leads_id ="+params.leads_id+" AND sa.accepted='"+params.status+"' ORDER BY sa.service_agreement_id DESC";149 sequelize.query(sql150 , { type: sequelize.QueryTypes.SELECT}).then(function(searchData) {151 willFulfillDeferred.resolve(searchData);152 });153 return willFulfill;154 }155 quoteSchema.findAll({156 where:{157 leads_id : params.leads_id,158 status:status159 },160 order: [161 ['id', 'DESC']162 ]163 }).then(function(foundObject){164 willFulfillDeferred.resolve(foundObject);165 });166 return willFulfill;167 },168 getTotalQuote:function(leads_id){169 var willFulfillDeferred = Q.defer();170 var willFulfill = willFulfillDeferred.promise;171 if(leads_id)172 {173 quoteSchema.findAndCountAll({174 where:{175 leads_id : leads_id176 }177 }).then(function(foundObject){178 willFulfillDeferred.resolve(foundObject);179 });180 }181 else {182 quoteSchema.findAndCountAll({183 }).then(function(foundObject){184 willFulfillDeferred.resolve(foundObject);185 });186 }187 return willFulfill;188 },189 insertQuote:function(params){190 var willFulfillDeferred = Q.defer();191 var willFulfill = willFulfillDeferred.promise;192 quoteSchema.create({193 created_by: params.created_by,194 created_by_type: params.created_by_type,195 leads_id: params.leads_id,196 date_quoted: new Date(),197 ran: params.ran,198 status: "draft"199 }).then(function(data){200 if(data){201 data.updateAttributes({202 quote_no: data.id203 }).then(function(result){204 result.id = data.id;205 willFulfillDeferred.resolve(result);206 });207 }208 });209 return willFulfill;210 },211 updateQuote:function(params){212 var willFulfillDeferred = Q.defer();213 var willFulfill = willFulfillDeferred.promise;214 if(!params.status)215 {216 quoteSchema.update({217 status: "new"218 },{219 where:{220 id: params.quote_id,221 status:"draft"222 }223 }).then(function(updatedData){224 willFulfillDeferred.resolve(updatedData);225 });226 }227 else {228 if(params.status == "posted")229 {230 quoteSchema.update({231 status: params.status,232 date_posted:new Date()233 },{234 where:{235 id: params.quote_id236 }237 }).then(function(updatedData){238 willFulfillDeferred.resolve(updatedData);239 });240 }else241 {242 quoteSchema.update({243 status: params.status244 },{245 where:{246 id: params.quote_id247 }248 }).then(function(updatedData){249 willFulfillDeferred.resolve(updatedData);250 });251 }252 }253 return willFulfill;254 },255 acceptQuote:function(params)256 {257 var willFulfillDeferred = Q.defer();258 var willFulfill = willFulfillDeferred.promise;259 quoteSchema.update({260 status: "accepted"261 },{262 where:{263 id: params264 }265 }).then(function(updatedData){266 willFulfillDeferred.resolve(updatedData);267 });268 return willFulfill;269 },270 getStaffSalary:function(params)271 {272 var willFulfillDeferred = Q.defer();273 var willFulfill = willFulfillDeferred.promise;274 if(params.partTime)275 {276 sql = "SELECT p.code FROM products p INNER JOIN staff_rate s ON s.part_time_product_id = p.id WHERE s.userid ="+params.userid;277 }278 else279 {280 sql = "SELECT p.code FROM products p INNER JOIN staff_rate s ON s.product_id = p.id WHERE s.userid ="+params.userid;281 }282 sequelize.query(sql283 , { type: sequelize.QueryTypes.SELECT}).then(function(price) {284 willFulfillDeferred.resolve(price);285 });286 return willFulfill;287 },288 dataForSync:function(offset)289 {290 var willFulfillDeferred = Q.defer();291 var willFulfill = willFulfillDeferred.promise;292 quoteSchema.findOne({293 limit:1,294 offset:offset295 }).then(function(foundObject){296 willFulfillDeferred.resolve(foundObject);297 });298 return willFulfill;299 },300 getQuoteID:function(ran)301 {302 var willFulfillDeferred = Q.defer();303 var willFulfill = willFulfillDeferred.promise;304 quoteSchema.findOne({305 attributes:['id'],306 where:{307 ran:ran308 }309 }).then(function(foundObject){310 willFulfillDeferred.resolve(foundObject);311 });312 return willFulfill;313 },314 getQuoteByLeads:function(leads_id)315 {316 var willFulfillDeferred = Q.defer();317 var willFulfill = willFulfillDeferred.promise;318 quoteSchema.findAll({319 attributes:[320 'id','created_by','created_by_type',321 'status','date_quoted','date_posted','ran'322 ],323 where:{324 leads_id : leads_id325 }326 }).then(function(foundObject){327 willFulfillDeferred.resolve(foundObject);328 });329 return willFulfill;330 },331 getQuoteData:function(params)332 {333 var willFulfillDeferred = Q.defer();334 var willFulfill = willFulfillDeferred.promise;335 if(params.id)336 {337 quoteSchema.findOne({338 attributes:[339 'id','created_by','created_by_type',340 'status','date_quoted','date_posted','ran'341 ],342 where:{343 id:{$eq:params.id,$notIn:[sequelize.literal('SELECT quote_id FROM quote_sync_mongo')]}344 }345 }).then(function(foundObject){346 willFulfillDeferred.resolve(foundObject);347 });348 }349 else350 {351 quoteSchema.findAll({352 attributes:[353 'id','created_by','created_by_type',354 'status','date_quoted','date_posted','ran'355 ],356 offset:((params.page-1)*params.limit),357 limit : params.limit,358 where:{359 id:{$notIn:[sequelize.literal('SELECT quote_id FROM quote_sync_mongo')]}360 },361 order: [362 ['id', 'DESC']363 ]364 }).then(function(foundObject){365 willFulfillDeferred.resolve(foundObject);366 });367 }368 return willFulfill;369 },370 countTotalQuote:function(params)371 {372 var willFulfillDeferred = Q.defer();373 var willFulfill = willFulfillDeferred.promise;374 if(params.id)375 {376 quoteSchema.count({377 where:{378 id:{$eq:params.id,$notIn:[sequelize.literal('SELECT quote_id FROM quote_sync_mongo')]}379 }380 }).then(function(foundObject){381 willFulfillDeferred.resolve(foundObject);382 });383 }384 else385 {386 quoteSchema.count({387 where:{388 id:{$notIn:[sequelize.literal('SELECT quote_id FROM quote_sync_mongo')]}389 }390 }).then(function(foundObject){391 willFulfillDeferred.resolve(foundObject);392 });393 }394 return willFulfill;395 },396 insertSyncMongo:function(params)397 {398 var willFulfillDeferred = Q.defer();399 var willFulfill = willFulfillDeferred.promise;400 sql="INSERT INTO quote_sync_mongo(date_synced,quote_id)VALUES(NOW(),"+params+")";401 sequelize.query(sql402 , { type: sequelize.QueryTypes.INSERT}).then(function(data) {403 willFulfillDeferred.resolve(data);404 });405 return willFulfill;406 },407 deleteSync:function(id)408 {409 var willFulfillDeferred = Q.defer();410 var willFulfill = willFulfillDeferred.promise;411 sql="DELETE FROM quote_sync_mongo WHERE quote_id="+id;412 sequelize.query(sql413 ,{ type: sequelize.QueryTypes.DELETE}).then(function(data) {414 willFulfillDeferred.resolve(data);415 });416 return willFulfill;417 }418 },419 instanceMethods:420 {421 getDetails:function()422 {423 var willFulfillDeferred = Q.defer();424 var willFulfill = willFulfillDeferred.promise;425 var me = this;426 try {427 quoteDetailSchema.getQuoteDetails(this.id).then(function(details){428 me.quote_details = details;429 willFulfillDeferred.resolve(details);430 });431 }catch(e)432 {433 console.log("details null");434 willFulfillDeferred.resolve(false);435 }436 return willFulfill;437 },438 getSA:function()439 {440 var willFulfillDeferred = Q.defer();441 var willFulfill = willFulfillDeferred.promise;442 var me = this;443 try {444 SAschema.getServiceAgreement(this.id).then(function(service_agreement){445 me.sa = service_agreement;446 willFulfillDeferred.resolve(service_agreement);447 });448 }449 catch(e)450 {451 console.log("sa null");452 willFulfillDeferred.resolve(false);453 }454 return willFulfill;455 },456 structureQuoteData:function()457 {458 var temp = {};459 var quote = this;460 var quote_details = this.quote_details;461 var service_agreement = this.sa;462 temp.quote = quote;463 temp.details = quote_details;464 temp.sa = service_agreement;465 return temp;466 }467 }468});469//Only call this function sequelize.sync(); if table does not exists470//IMPORTANT:471//COMMENT OUT OR REMOVE after deployment472//May cause system failure for mysql473// sequelize.sync();...

Full Screen

Full Screen

Lead_Info.js

Source:Lead_Info.js Github

copy

Full Screen

1var Sequelize = require('sequelize');2var configs = require("../config/configs");3var Q = require('q');4var mysqlCredentials = configs.getMysqlCredentials();5var mongoose = require('mongoose');6var Schema = mongoose.Schema;7var configs = require("../config/configs");8var Q = require('q');9var mongoCredentials = configs.getMongoCredentials();10var quoteSchema = require("../mysql/Quote");11var Admin_Info = require("../mysql/Admin_Info");12var quoteMongoSchema = require("../models/QuoteModel");13var quoteComponent = require("../components/Quote");14var sequelize = require("../mysql/sequelize");15var adminInfoSchema = require("../mysql/Admin_Info");16var leadInfoSchema = sequelize.define('leads',{17 id: {type:Sequelize.INTEGER,primaryKey:true, autoIncrement: true},18 fname: {type: Sequelize.STRING},19 lname: {type: Sequelize.STRING},20 email: {type: Sequelize.STRING},21 hiring_coordinator_id: {type: Sequelize.INTEGER},22 last_updated_date: {type: Sequelize.DATE},23 company_name: {type: Sequelize.STRING},24 company_address: {type: Sequelize.STRING},25 mobile: {type: Sequelize.STRING},26 officenumber: {type: Sequelize.STRING},27 status: {type: Sequelize.STRING},28 csro_id: {type: Sequelize.STRING},29 business_partner_id: {type: Sequelize.STRING},30 abn_number: {type: Sequelize.STRING},31 },32 {33 freezeTableName : true,34 timestamps: false,35 classMethods:36 {37 fetchSingleClientsInfoWithAttributes:function(where, attributes){38 var willFulfillDeferred = Q.defer();39 var willFulfill = willFulfillDeferred.promise;40 leadInfoSchema.findOne({41 attributes:attributes,42 where:where43 }).then(function(foundObject){44 willFulfillDeferred.resolve(foundObject);45 });46 return willFulfill;47 },48 getTotalActiveStaff:function(client_id){49 var willFulfillDeferred = Q.defer();50 var willFulfill = willFulfillDeferred.promise;51 var sql = "SELECT COUNT(id)AS total_active FROM subcontractors WHERE status IN('ACTIVE', 'suspended') AND leads_id="+client_id;52 sequelize.query(sql , { type: sequelize.QueryTypes.SELECT}).then(function(result) {53 if(result)54 {55 willFulfillDeferred.resolve(result);56 }57 });58 return willFulfill;59 },60 getClientInfo:function(client_id)61 {62 var willFulfillDeferred = Q.defer();63 var willFulfill = willFulfillDeferred.promise;64 var sql = "SELECT * FROM leads WHERE id="+client_id;65 sequelize.query(sql , { type: sequelize.QueryTypes.SELECT}).then(function(client) {66 if(client)67 {68 willFulfillDeferred.resolve(client);69 }70 });71 return willFulfill;72 },73 getLeadsInfo:function($leads_id){74 var willFulfillDeferred = Q.defer();75 var willFulfill = willFulfillDeferred.promise;76 if($leads_id)77 {78 leadInfoSchema.find({79 attributes:80 ['fname','lname','email','mobile','company_address','company_name','status','hiring_coordinator_id'],81 where:82 {83 id:$leads_id84 }85 }).then(function(foundObject){86 willFulfillDeferred.resolve(foundObject);87 });88 }89 else90 {91 leadInfoSchema.findAll({92 attributes:93 ['id','fname','lname','email','mobile','company_address','company_name','status'],94 where:95 {96 status:{$notIn:['inactive' , 'REMOVED']}97 },98 order:99 [100 ['id', 'DESC']101 ]102 }).then(function(result){103 willFulfillDeferred.resolve(result);104 });105 }106 return willFulfill;107 },108 updateLeads:function(params){109 var willFulfillDeferred = Q.defer();110 var willFulfill = willFulfillDeferred.promise;111 leadInfoSchema.update({112 last_updated_date: new Date()113 },{114 where:{115 id:params116 }117 }).then(function(data){118 willFulfillDeferred.resolve(data);119 });120 return willFulfill;121 },122 countAllLeads:function(params)123 {124 var willFulfillDeferred = Q.defer();125 var willFulfill = willFulfillDeferred.promise;126 leadInfoSchema.findAndCountAll({127 attributes:128 ['id','fname','lname','email','mobile','company_address','company_name','status'],129 where:130 {131 status:{$notIn:['inactive' , 'REMOVED']}132 },133 order:134 [135 ['id', 'DESC']136 ]137 }).then(function(result){138 willFulfillDeferred.resolve(result);139 });140 return willFulfill;141 },142 countData:function(leads_id)143 {144 var willFulfillDeferred = Q.defer();145 var willFulfill = willFulfillDeferred.promise;146 var where = {status:{$notIn:['inactive' , 'REMOVED']}};147 if(leads_id)148 {149 where = {id:leads_id,status:{$notIn:['inactive' , 'REMOVED']}}150 }151 leadInfoSchema.count({152 where:where153 }).then(function(foundObject){154 willFulfillDeferred.resolve(foundObject);155 });156 return willFulfill;157 },158 countSolr:function(leads_id)159 {160 var willFulfillDeferred = Q.defer();161 var willFulfill = willFulfillDeferred.promise;162 var where = {status:{$notIn:['inactive' , 'REMOVED']}};163 if(leads_id)164 {165 where = {166 id:{$eq:leads_id,$notIn:[sequelize.literal('SELECT leads_id FROM quote_solr_sync')]},167 status:{$notIn:['inactive' , 'REMOVED']}168 }169 }170 else171 {172 where = {173 id:{$notIn:[sequelize.literal('SELECT leads_id FROM quote_solr_sync')]},174 status:{$notIn:['inactive' , 'REMOVED']}175 }176 }177 leadInfoSchema.count({178 where:where179 }).then(function(foundObject){180 willFulfillDeferred.resolve(foundObject);181 });182 return willFulfill;183 },184 getOffsetLeadsData:function(params)185 {186 var willFulfillDeferred = Q.defer();187 var willFulfill = willFulfillDeferred.promise;188 if(params.leads_id)189 {190 leadInfoSchema.find({191 attributes:192 ['id','fname','lname','email','mobile','company_address','company_name','status','hiring_coordinator_id'],193 where:194 {195 id:params.leads_id,196 status:{$notIn:['inactive' , 'REMOVED']}197 }198 }).then(function(foundObject){199 willFulfillDeferred.resolve(foundObject);200 });201 }202 else203 {204 leadInfoSchema.findAll({205 attributes:206 ['id','fname','lname','email','mobile','company_address','company_name','status'],207 offset:((params.page-1)*params.limit),208 limit : params.limit,209 where:210 {211 status:{$notIn:['inactive' , 'REMOVED']}212 },213 order:214 [215 ['id', 'DESC']216 ]217 }).then(function(result){218 willFulfillDeferred.resolve(result);219 });220 }221 return willFulfill;222 },223 idForSolrSync:function(params)224 {225 var willFulfillDeferred = Q.defer();226 var willFulfill = willFulfillDeferred.promise;227 if(params.leads_id)228 {229 leadInfoSchema.find({230 attributes:231 ['id','fname','lname','email','mobile','company_address','company_name','status','hiring_coordinator_id'],232 where:233 {234 id:{$eq:params.leads_id,$notIn:[sequelize.literal('SELECT leads_id FROM quote_solr_sync')]},235 status:{$notIn:['inactive' , 'REMOVED']}236 }237 }).then(function(foundObject){238 willFulfillDeferred.resolve(foundObject);239 });240 }241 else242 {243 leadInfoSchema.findAll({244 attributes:245 ['id','fname','lname','email','mobile','company_address','company_name','status'],246 offset:((params.page-1)*params.limit),247 limit : params.limit,248 where:249 {250 id:{$notIn:[sequelize.literal('SELECT leads_id FROM quote_solr_sync')]},251 status:{$notIn:['inactive' , 'REMOVED']}252 },253 order:254 [255 ['id', 'DESC']256 ]257 }).then(function(result){258 willFulfillDeferred.resolve(result);259 });260 }261 return willFulfill;262 },263 checkSolr:function(id)264 {265 var willFulfillDeferred = Q.defer();266 var willFulfill = willFulfillDeferred.promise;267 sql="SELECT COUNT(*) as count FROM quote_solr_sync WHERE leads_id="+id;268 sequelize.query(sql269 ,{ type: sequelize.QueryTypes.SELECT}).then(function(data) {270 willFulfillDeferred.resolve(data[0].count);271 });272 return willFulfill;273 },274 saveSolr:function(id)275 {276 var willFulfillDeferred = Q.defer();277 var willFulfill = willFulfillDeferred.promise;278 sql="INSERT INTO quote_solr_sync(leads_id,date_synced) VALUES("+id+",NOW())";279 sequelize.query(sql280 ,{ type: sequelize.QueryTypes.INSERT}).then(function(data) {281 willFulfillDeferred.resolve(data);282 });283 return willFulfill;284 },285 delSolr:function(id)286 {287 var willFulfillDeferred = Q.defer();288 var willFulfill = willFulfillDeferred.promise;289 sql="DELETE FROM quote_solr_sync WHERE leads_id="+id;290 sequelize.query(sql291 ,{ type: sequelize.QueryTypes.DELETE}).then(function(data) {292 willFulfillDeferred.resolve(data);293 });294 return willFulfill;295 }296 },297 instanceMethods:298 {299 getQuote:function()300 {301 var willFulfillDeferred = Q.defer();302 var willFulfill = willFulfillDeferred.promise;303 var me = this;304 var leads = [];305 var promises = [];306 function delay() {307 return Q.delay(100);308 }309 try {310 quoteSchema.getQuoteByLeads(this.id).then(function(quote){311 if(quote)312 {313 for (var i = 0; i < quote.length; i++)314 {315 item = quote[i];316 var per_quote_promises = [];317 var promise_quote_details = item.getDetails();318 var promise_quote_sa = item.getSA();319 per_quote_promises.push(promise_quote_details);320 per_quote_promises.push(delay());321 per_quote_promises.push(promise_quote_sa);322 per_quote_promises.push(delay());323 per_leads_promises_promise = Q.allSettled(per_quote_promises);324 promises.push(per_leads_promises_promise);325 promises.push(delay);326 }327 var allPromise = Q.all(promises);328 allPromise.then(function (results) {329 console.log("Promise Done!");330 for(var i = 0 ; i < quote.length ; i++ )331 {332 leads.push(quote[i].structureQuoteData());333 }334 me.leads_quote = leads;335 willFulfillDeferred.resolve(leads);336 return willFulfill;337 });338 }339 else340 {341 console.log("null quote");342 willFulfillDeferred.resolve(false);343 }344 });345 }346 catch(e)347 {348 console.log(e);349 willFulfillDeferred.resolve(false);350 }351 return willFulfill;352 },353 getQuoteMongo:function()354 {355 this.db = mongoose.createConnection("mongodb://"+mongoCredentials.host+":"+mongoCredentials.port+"/prod",mongoCredentials.options);356 var quote = this.db.model('Quote',quoteMongoSchema);357 var willFulfillDeferred = Q.defer();358 var willFulfill = willFulfillDeferred.promise;359 var leads_id = this.id;360 var me = this;361 this.db.once('open', function () {362 var filter = {leads_id:parseInt(leads_id)};363 try {364 quote.find(filter).lean().sort({"quote_id" : -1}).exec(function(err, quote_data){365 var posted = 0,366 draft = 0,367 New = 0,368 deleted = 0,369 sa_accepted = 0,370 sa_pending = 0;371 if(err)372 {373 willFulfillDeferred.reject(err);374 me.db.close();375 }376 if(quote_data && quote_data.length > 0)377 {378 function getCountStatus(i)379 {380 if(i < quote_data.length)381 {382 data = quote_data[i];383 sa =(data.service_agreement.length > 0 ? data.service_agreement[0] : null);384 if(data.status == "posted"){posted = posted + 1;}385 else if(data.status == "draft"){draft = draft + 1;}386 else if(data.status == "new"){New = New + 1;}387 else if(data.status == "deleted"){deleted = deleted + 1;}388 else{}389 if(sa)390 {391 if(sa.accepted == "yes"){sa_accepted = sa_accepted + 1}392 else if(sa.accepted == "no"){sa_pending = sa_pending + 1}393 // sa.acceptedCount = sa_accepted;394 // sa.pendingCount = sa_pending;395 }396 if(!me.sync)397 {398 quoteComponent.whosThis(data.created_by,data.created_by_type).then(function(admin){399 data.created_by = {400 admin_id : (admin.admin_id ? admin.admin_id : admin.agent_no ? admin.agent_no : null),401 admin_fname: (admin.admin_fname ? admin.admin_fname : admin.fname ? admin.fname : ""),402 admin_lname: (admin.admin_lname ? admin.admin_lname : admin.lname ? admin.lname : ""),403 admin_email:(admin.admin_email ? admin.admin_email : admin.email ? admin.email : ""),404 signature_no: (admin.signature_contact_nos ? admin.signature_contact_nos : ""),405 signature_company: (admin.signature_company ? admin.signature_company : "")406 }407 getCountStatus(i+1);408 });409 }410 else411 {412 getCountStatus(i+1);413 }414 }415 else416 {417 me.leads_quote = quote_data;418 me.countData = {419 postedCount : posted,420 draftCount : draft,421 newCount : New,422 deletedCount : deleted,423 acceptedCount : sa_accepted,424 pendingCount : sa_pending425 }426 willFulfillDeferred.resolve(me);427 }428 }429 getCountStatus(0);430 }431 else432 {433 me.leads_quote = [];434 me.countData = {435 postedCount : posted,436 draftCount : draft,437 newCount : New,438 deletedCount : deleted,439 acceptedCount : sa_accepted,440 pendingCount : sa_pending441 }442 willFulfillDeferred.resolve(me);443 }444 me.db.close();445 });446 }447 catch(e)448 {449 console.log(e);450 }451 });452 return willFulfill;453 },454 structLeadsData:function()455 {456 var temp = {};457 var leads = this;458 var quote_data = this.leads_quote;459 var countData = this.countData;460 temp.leads = leads;461 temp.quote_data = quote_data;462 temp.count_data = countData;463 return temp;464 }465 }466 });467leadInfoSchema.belongsTo(Admin_Info, {foreignKey:"hiring_coordinator_id", targetKey: "admin_id"});468//Only call this function sequelize.sync(); if table does not exists469//IMPORTANT:470//COMMENT OUT OR REMOVE after deployment471//May cause system failure for mysql472// sequelize.sync();...

Full Screen

Full Screen

BleManager.js

Source:BleManager.js Github

copy

Full Screen

...14 (error, data) => {15 if (error) {16 reject(error);17 } else {18 fulfill(data);19 }20 }21 );22 });23 }24 readRSSI(peripheralId) {25 return new Promise((fulfill, reject) => {26 bleManager.readRSSI(peripheralId, (error, rssi) => {27 if (error) {28 reject(error);29 } else {30 fulfill(rssi);31 }32 });33 });34 }35 refreshCache(peripheralId) {36 return new Promise((fulfill, reject) => {37 bleManager.refreshCache(peripheralId, (error, result) => {38 if (error) {39 reject(error);40 } else {41 fulfill(result);42 }43 });44 });45 }46 retrieveServices(peripheralId, services) {47 return new Promise((fulfill, reject) => {48 bleManager.retrieveServices(49 peripheralId,50 services,51 (error, peripheral) => {52 if (error) {53 reject(error);54 } else {55 fulfill(peripheral);56 }57 }58 );59 });60 }61 write(peripheralId, serviceUUID, characteristicUUID, data, maxByteSize) {62 if (maxByteSize == null) {63 maxByteSize = 20;64 }65 return new Promise((fulfill, reject) => {66 bleManager.write(67 peripheralId,68 serviceUUID,69 characteristicUUID,70 data,71 maxByteSize,72 error => {73 if (error) {74 reject(error);75 } else {76 fulfill();77 }78 }79 );80 });81 }82 writeWithoutResponse(83 peripheralId,84 serviceUUID,85 characteristicUUID,86 data,87 maxByteSize,88 queueSleepTime89 ) {90 if (maxByteSize == null) {91 maxByteSize = 20;92 }93 if (queueSleepTime == null) {94 queueSleepTime = 10;95 }96 return new Promise((fulfill, reject) => {97 bleManager.writeWithoutResponse(98 peripheralId,99 serviceUUID,100 characteristicUUID,101 data,102 maxByteSize,103 queueSleepTime,104 error => {105 if (error) {106 reject(error);107 } else {108 fulfill();109 }110 }111 );112 });113 }114 connect(peripheralId) {115 return new Promise((fulfill, reject) => {116 bleManager.connect(peripheralId, error => {117 if (error) {118 reject(error);119 } else {120 fulfill();121 }122 });123 });124 }125 createBond(peripheralId,peripheralPin=null) {126 return new Promise((fulfill, reject) => {127 bleManager.createBond(peripheralId,peripheralPin, error => {128 if (error) {129 reject(error);130 } else {131 fulfill();132 }133 });134 });135 }136 removeBond(peripheralId) {137 return new Promise((fulfill, reject) => {138 bleManager.removeBond(peripheralId, error => {139 if (error) {140 reject(error);141 } else {142 fulfill();143 }144 });145 });146 }147 disconnect(peripheralId, force = true) {148 return new Promise((fulfill, reject) => {149 bleManager.disconnect(peripheralId, force, error => {150 if (error) {151 reject(error);152 } else {153 fulfill();154 }155 });156 });157 }158 startNotification(peripheralId, serviceUUID, characteristicUUID) {159 return new Promise((fulfill, reject) => {160 bleManager.startNotification(161 peripheralId,162 serviceUUID,163 characteristicUUID,164 error => {165 if (error) {166 reject(error);167 } else {168 fulfill();169 }170 }171 );172 });173 }174 startNotificationUseBuffer(175 peripheralId,176 serviceUUID,177 characteristicUUID,178 buffer179 ) {180 return new Promise((fulfill, reject) => {181 bleManager.startNotificationUseBuffer(182 peripheralId,183 serviceUUID,184 characteristicUUID,185 buffer,186 error => {187 if (error) {188 reject(error);189 } else {190 fulfill();191 }192 }193 );194 });195 }196 stopNotification(peripheralId, serviceUUID, characteristicUUID) {197 return new Promise((fulfill, reject) => {198 bleManager.stopNotification(199 peripheralId,200 serviceUUID,201 characteristicUUID,202 error => {203 if (error) {204 reject(error);205 } else {206 fulfill();207 }208 }209 );210 });211 }212 checkState() {213 bleManager.checkState();214 }215 start(options) {216 return new Promise((fulfill, reject) => {217 if (options == null) {218 options = {};219 }220 bleManager.start(options, error => {221 if (error) {222 reject(error);223 } else {224 fulfill();225 }226 });227 });228 }229 scan(serviceUUIDs, seconds, allowDuplicates, scanningOptions = {}) {230 return new Promise((fulfill, reject) => {231 if (allowDuplicates == null) {232 allowDuplicates = false;233 }234 // (ANDROID) Match as many advertisement per filter as hw could allow235 // dependes on current capability and availability of the resources in hw.236 if (scanningOptions.numberOfMatches == null) {237 scanningOptions.numberOfMatches = 3;238 }239 // (ANDROID) Defaults to MATCH_MODE_AGGRESSIVE240 if (scanningOptions.matchMode == null) {241 scanningOptions.matchMode = 1;242 }243 // (ANDROID) Defaults to SCAN_MODE_LOW_POWER on android244 if (scanningOptions.scanMode == null) {245 scanningOptions.scanMode = 0;246 }247 if (scanningOptions.reportDelay == null) {248 scanningOptions.reportDelay = 0;249 }250 bleManager.scan(251 serviceUUIDs,252 seconds,253 allowDuplicates,254 scanningOptions,255 error => {256 if (error) {257 reject(error);258 } else {259 fulfill();260 }261 }262 );263 });264 }265 stopScan() {266 return new Promise((fulfill, reject) => {267 bleManager.stopScan(error => {268 if (error != null) {269 reject(error);270 } else {271 fulfill();272 }273 });274 });275 }276 enableBluetooth() {277 return new Promise((fulfill, reject) => {278 bleManager.enableBluetooth(error => {279 if (error != null) {280 reject(error);281 } else {282 fulfill();283 }284 });285 });286 }287 disableBluetooth() {288 return new Promise((fulfill, reject) => {289 bleManager.disableBluetooth(error => {290 if (error != null) {291 reject(error);292 } else {293 fulfill();294 }295 });296 });297 }298 getConnectedPeripherals(serviceUUIDs) {299 return new Promise((fulfill, reject) => {300 bleManager.getConnectedPeripherals(serviceUUIDs, (error, result) => {301 if (error) {302 reject(error);303 } else {304 if (result != null) {305 fulfill(result);306 } else {307 fulfill([]);308 }309 }310 });311 });312 }313 getBondedPeripherals() {314 return new Promise((fulfill, reject) => {315 bleManager.getBondedPeripherals((error, result) => {316 if (error) {317 reject(error);318 } else {319 if (result != null) {320 fulfill(result);321 } else {322 fulfill([]);323 }324 }325 });326 });327 }328 getDiscoveredPeripherals() {329 return new Promise((fulfill, reject) => {330 bleManager.getDiscoveredPeripherals((error, result) => {331 if (error) {332 reject(error);333 } else {334 if (result != null) {335 fulfill(result);336 } else {337 fulfill([]);338 }339 }340 });341 });342 }343 removePeripheral(peripheralId) {344 return new Promise((fulfill, reject) => {345 bleManager.removePeripheral(peripheralId, error => {346 if (error) {347 reject(error);348 } else {349 fulfill();350 }351 });352 });353 }354 isPeripheralConnected(peripheralId, serviceUUIDs) {355 return this.getConnectedPeripherals(serviceUUIDs).then(result => {356 if (357 result.find(p => {358 return p.id === peripheralId;359 })360 ) {361 return true;362 } else {363 return false;364 }365 });366 }367 requestConnectionPriority(peripheralId, connectionPriority) {368 return new Promise((fulfill, reject) => {369 bleManager.requestConnectionPriority(370 peripheralId,371 connectionPriority,372 (error, status) => {373 if (error) {374 reject(error);375 } else {376 fulfill(status);377 }378 }379 );380 });381 }382 requestMTU(peripheralId, mtu) {383 return new Promise((fulfill, reject) => {384 bleManager.requestMTU(peripheralId, mtu, (error, mtu) => {385 if (error) {386 reject(error);387 } else {388 fulfill(mtu);389 }390 });391 });392 }393}...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python 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