How to use handleError method in Best

Best JavaScript code snippet using best

git.js

Source:git.js Github

copy

Full Screen

...62 };63 modelObj.getAccount(data, (err, accountRecords) => {64 bl.mp.closeModel(soajs, modelObj);65 if (err) {66 return cb(bl.handleError(soajs, 602, err));67 }68 return cb(null, accountRecords);69 });70 },71 72 "get_by_owner": (soajs, inputmaskData, cb) => {73 let modelObj = bl.mp.getModel(soajs);74 let data = {75 owner: inputmaskData.owner,76 provider: inputmaskData.provider,77 token: inputmaskData.token78 };79 modelObj.getAccount(data, (err, accountRecord) => {80 bl.mp.closeModel(soajs, modelObj);81 if (err) {82 return cb(bl.handleError(soajs, 602, err));83 }84 return cb(null, accountRecord);85 });86 },87 88 "list": (soajs, inputmaskData, cb) => {89 let modelObj = bl.mp.getModel(soajs);90 modelObj.getAccounts((err, accountRecords) => {91 bl.mp.closeModel(soajs, modelObj);92 if (err) {93 return cb(bl.handleError(soajs, 602, err));94 }95 return cb(null, accountRecords);96 });97 },98 99 "getRepo": (soajs, inputmaskData, cb) => {100 let modelObj = bl.mp.getModel(soajs);101 let data = {102 id: inputmaskData.id103 };104 modelObj.getRepository(data, (err, repository) => {105 bl.mp.closeModel(soajs, modelObj);106 if (err) {107 return cb(bl.handleError(soajs, 602, err));108 }109 if (!repository) {110 return cb(bl.handleError(soajs, 405, err));111 }112 return cb(null, repository);113 });114 },115 116 "getRepoInfo": (soajs, inputmaskData, cb) => {117 let modelObj = bl.mp.getModel(soajs);118 let data = {119 id: inputmaskData.id120 };121 modelObj.getRepository(data, (err, repo) => {122 if (err) {123 bl.mp.closeModel(soajs, modelObj);124 return cb(bl.handleError(soajs, 602, err));125 }126 if (!repo) {127 bl.mp.closeModel(soajs, modelObj);128 return cb(bl.handleError(soajs, 405, err));129 }130 data = {131 provider: repo.provider132 };133 134 if (!repo.source || repo.source.length === 0) {135 bl.mp.closeModel(soajs, modelObj);136 return cb(bl.handleError(soajs, 409, err));137 }138 data.owner = repo.source[0].name;139 data.token = true;140 modelObj.getAccount(data, (err, accountRecord) => {141 bl.mp.closeModel(soajs, modelObj);142 if (err) {143 return cb(bl.handleError(soajs, 602, err));144 }145 if (!accountRecord) {146 return cb(bl.handleError(soajs, 404, null));147 }148 let response = {149 domain: repo.domain,150 repository: repo.repository,151 name: repo.name,152 owner: repo.owner,153 provider: repo.provider,154 access: accountRecord.access155 };156 if (accountRecord.token) {157 response.token = accountRecord.token;158 }159 return cb(null, response);160 });161 });162 },163 164 "getRepoFile": (soajs, inputmaskData, cb) => {165 let modelObj = bl.mp.getModel(soajs);166 let data = {167 id: inputmaskData.accountId168 };169 data.token = true;170 modelObj.getAccount(data, (err, account) => {171 if (err) {172 bl.mp.closeModel(soajs, modelObj);173 return cb(bl.handleError(soajs, 602, err));174 }175 if (!account) {176 bl.mp.closeModel(soajs, modelObj);177 return cb(bl.handleError(soajs, 403, err));178 }179 let driver = bl.mp.getDriver(account);180 181 if (!driver) {182 bl.mp.closeModel(soajs, modelObj);183 return cb(bl.handleError(soajs, 603, null));184 }185 data = {186 path: inputmaskData.filepath,187 branch: inputmaskData.branch,188 repository: inputmaskData.repo,189 config: data.config190 };191 driver.getFile(data, (error, fileContent) => {192 bl.mp.closeModel(soajs, modelObj);193 if (error) {194 195 return cb(bl.handleError(soajs, 604, error));196 }197 return cb(null, {198 content: fileContent.content,199 path: inputmaskData.filepath,200 repository: inputmaskData.repo,201 });202 });203 });204 },205 206 "getBranches": (soajs, inputmaskData, cb) => {207 let modelObj = bl.mp.getModel(soajs);208 let data = {209 id: inputmaskData.id210 };211 modelObj.getRepository(data, (err, repository) => {212 bl.mp.closeModel(soajs, modelObj);213 if (err) {214 return cb(bl.handleError(soajs, 602, err));215 }216 if (!repository) {217 return cb(bl.handleError(soajs, 405, err));218 }219 return cb(null, repository.branches ? repository.branches : []);220 });221 },222 223 "getBranch": (soajs, inputmaskData, cb) => {224 let modelObj = bl.mp.getModel(soajs);225 let data = {226 owner: [inputmaskData.owner],227 name: inputmaskData.repo,228 provider: [inputmaskData.provider]229 };230 modelObj.searchRepositories(data, (err, repos) => {231 bl.mp.closeModel(soajs, modelObj);232 if (err) {233 return cb(bl.handleError(soajs, 602, err));234 }235 if (!repos || repos.length === 0) {236 return cb(bl.handleError(soajs, 405, err));237 }238 let repo = repos[0];239 data = {240 provider: repo.provider241 };242 if (!repo.source || repo.source.length === 0) {243 bl.mp.closeModel(soajs, modelObj);244 return cb(bl.handleError(soajs, 409, err));245 }246 data.owner = repo.source[0].name;247 data.token = true;248 modelObj.getAccount(data, (err, accountRecord) => {249 bl.mp.closeModel(soajs, modelObj);250 if (err) {251 return cb(bl.handleError(soajs, 602, err));252 }253 if (!accountRecord) {254 return cb(bl.handleError(soajs, 404, null));255 }256 let driver = bl.mp.getDriver(accountRecord);257 if (!driver) {258 return cb(bl.handleError(soajs, 603, null));259 }260 data = {261 config: bl.localConfig,262 repository: repo.repository,263 branch: inputmaskData.branch,264 commit: true265 };266 driver.getBranch(data, (err, branch) => {267 if (err) {268 return cb(bl.handleError(soajs, 410, err));269 }270 branch.repo = {271 id: repo._id.toString()272 };273 return cb(null, branch);274 });275 });276 });277 },278 279 "getTags": (soajs, inputmaskData, cb) => {280 let modelObj = bl.mp.getModel(soajs);281 let data = {282 id: inputmaskData.id283 };284 modelObj.getRepository(data, (err, repo) => {285 if (err) {286 bl.mp.closeModel(soajs, modelObj);287 return cb(bl.handleError(soajs, 602, err));288 }289 if (!repo) {290 bl.mp.closeModel(soajs, modelObj);291 return cb(bl.handleError(soajs, 405, err));292 }293 data = {294 provider: repo.provider295 };296 297 if (!repo.source || repo.source.length === 0) {298 bl.mp.closeModel(soajs, modelObj);299 return cb(bl.handleError(soajs, 409, err));300 }301 data.owner = repo.source[0].name;302 data.token = true;303 modelObj.getAccount(data, (err, accountRecord) => {304 bl.mp.closeModel(soajs, modelObj);305 if (err) {306 return cb(bl.handleError(soajs, 602, err));307 }308 if (!accountRecord) {309 return cb(bl.handleError(soajs, 404, null));310 }311 let driver = bl.mp.getDriver(accountRecord);312 if (!driver) {313 return cb(bl.handleError(soajs, 603, null));314 }315 data = {316 config: bl.localConfig,317 repository: repo.repository,318 page: inputmaskData.page,319 size: inputmaskData.size,320 };321 driver.listTags(data, (err, tags) => {322 if (err) {323 return cb(bl.handleError(soajs, 403, err));324 }325 return cb(null, {326 tags: tags ? tags : []327 });328 });329 });330 });331 },332 333 "getTag": (soajs, inputmaskData, cb) => {334 let modelObj = bl.mp.getModel(soajs);335 let data = {336 id: inputmaskData.id337 };338 modelObj.getRepository(data, (err, repo) => {339 if (err) {340 bl.mp.closeModel(soajs, modelObj);341 return cb(bl.handleError(soajs, 602, err));342 }343 if (!repo) {344 bl.mp.closeModel(soajs, modelObj);345 return cb(bl.handleError(soajs, 405, err));346 }347 data = {348 provider: repo.provider349 };350 351 if (!repo.source || repo.source.length === 0) {352 bl.mp.closeModel(soajs, modelObj);353 return cb(bl.handleError(soajs, 409, err));354 }355 data.owner = repo.source[0].name;356 data.token = true;357 modelObj.getAccount(data, (err, accountRecord) => {358 bl.mp.closeModel(soajs, modelObj);359 if (err) {360 return cb(bl.handleError(soajs, 602, err));361 }362 if (!accountRecord) {363 return cb(bl.handleError(soajs, 404, null));364 }365 let driver = bl.mp.getDriver(accountRecord);366 if (!driver) {367 return cb(bl.handleError(soajs, 603, null));368 }369 data = {370 config: bl.localConfig,371 repository: repo.repository,372 tag: inputmaskData.tag373 };374 driver.getTag(data, (err, tag) => {375 if (err || !tag) {376 return cb(bl.handleError(soajs, 416, err));377 }378 return cb(null, tag);379 });380 });381 });382 },383 384 /**385 * Delete386 */387 388 "logout": (soajs, inputmaskData, cb) => {389 let modelObj = bl.mp.getModel(soajs);390 let data = {391 id: inputmaskData.id392 };393 data.token = true;394 modelObj.getAccount(data, (err, account) => {395 if (err) {396 bl.mp.closeModel(soajs, modelObj);397 return cb(bl.handleError(soajs, 602, err));398 }399 if (!account) {400 bl.mp.closeModel(soajs, modelObj);401 return cb(bl.handleError(soajs, 403, err));402 }403 account.password = inputmaskData.password;404 let driver = bl.mp.getDriver(account);405 if (!driver) {406 return cb(bl.handleError(soajs, 603, null));407 }408 data = {409 owner: account.owner410 };411 modelObj.checkActiveRepositories(data, (err, count) => {412 if (err) {413 bl.mp.closeModel(soajs, modelObj);414 return cb(bl.handleError(soajs, 602, err));415 }416 if (count > 0) {417 bl.mp.closeModel(soajs, modelObj);418 return cb(bl.handleError(soajs, 413, err));419 }420 async.auto({421 logout: function (callback) {422 let data = {423 config: bl.localConfig424 };425 driver.logout(data, callback);426 },427 deleteAccount: ['logout', function (results, callback) {428 let data = {429 _id: account._id430 };431 modelObj.deleteAccount(data, callback);432 }],433 removeRepositories: ['logout', function (results, callback) {434 let data = {435 owner: account.owner436 };437 modelObj.removeRepositories(data, callback);438 }]439 },440 function (err) {441 bl.mp.closeModel(soajs, modelObj);442 if (err) {443 return cb(bl.handleError(soajs, 602, err));444 }445 return cb(null, `Your account ${account.owner} has been successfully logged out!`);446 });447 });448 });449 },450 451 "deleteRepo": (soajs, inputmaskData, cb) => {452 let modelObj = bl.mp.getModel(soajs);453 let data = {454 id: inputmaskData.id455 };456 modelObj.getRepository(data, (err, repository) => {457 if (err) {458 bl.mp.closeModel(soajs, modelObj);459 return cb(bl.handleError(soajs, 602, err));460 }461 if (!repository) {462 bl.mp.closeModel(soajs, modelObj);463 return cb(bl.handleError(soajs, 405, err));464 }465 modelObj.deleteRepo(data, (err) => {466 bl.mp.closeModel(soajs, modelObj);467 if (err) {468 return cb(bl.handleError(soajs, 602, err));469 }470 return cb(null, "Repository Deleted!");471 });472 });473 },474 475 "deleteRepositories": (soajs, inputmaskData, cb) => {476 let modelObj = bl.mp.getModel(soajs);477 modelObj.deleteRepositories((err) => {478 bl.mp.closeModel(soajs, modelObj);479 if (err) {480 return cb(bl.handleError(soajs, 602, err));481 }482 return cb(null, "Leaf Repositories Deleted!");483 });484 },485 486 /**487 * Post488 */489 490 "login": (soajs, inputmaskData, cb) => {491 let modelObj = bl.mp.getModel(soajs);492 if (!(inputmaskData.username) && !(inputmaskData.token)) {493 return cb(bl.handleError(soajs, 602, null));494 }495 let driver = bl.mp.getDriver(inputmaskData);496 if (!driver) {497 return cb(bl.handleError(soajs, 603, null));498 }499 let data = {500 config: bl.localConfig501 };502 driver.login(data, (err, loginRecord) => {503 if (err) {504 bl.mp.closeModel(soajs, modelObj);505 return cb(bl.handleError(soajs, 604, err));506 }507 data = {508 provider: inputmaskData.provider,509 id: loginRecord.GID510 };511 modelObj.checkIfAccountExists(data, (err, count) => {512 if (err) {513 bl.mp.closeModel(soajs, modelObj);514 return cb(bl.handleError(soajs, 602, err));515 }516 if (count > 0) {517 bl.mp.closeModel(soajs, modelObj);518 return cb(bl.handleError(soajs, 402, null));519 }520 data = {521 config: bl.localConfig522 };523 524 modelObj.saveNewAccount(loginRecord, (err, final) => {525 if (err) {526 return cb(bl.handleError(soajs, 602, err));527 } else {528 soajs.log.info("Adding Repositories");529 soajs.inputmaskData.id = final.id.toString();530 lib.handleRepositories(bl, soajs, driver, modelObj, false, () => {531 bl.mp.closeModel(soajs, modelObj);532 });533 return cb(null, {534 id: final.id.toString(),535 message: "Repositories are being added..."536 });537 }538 });539 });540 });541 },542 543 "search": (soajs, inputmaskData, cb) => {544 let modelObj = bl.mp.getModel(soajs);545 async.parallel({546 search: function (callback) {547 modelObj.searchRepositories(inputmaskData, callback);548 },549 count: function (callback) {550 modelObj.countSearchRepositories(inputmaskData, callback);551 }552 }, function (err, results) {553 bl.mp.closeModel(soajs, modelObj);554 if (err) {555 return cb(bl.handleError(soajs, 602, err));556 }557 let response = {558 start: inputmaskData.skip ? inputmaskData.skip : 0,559 limit: inputmaskData.limit ? inputmaskData.limit : 100,560 size: results.search.length,561 repositories: results.search,562 count: results.count563 };564 565 return cb(null, response);566 });567 },568 569 /**570 * Put571 */572 573 "syncAccount": (soajs, inputmaskData, cb) => {574 let modelObj = bl.mp.getModel(soajs);575 let data = {576 id: inputmaskData.id577 };578 data.token = true;579 modelObj.getAccount(data, (err, accountRecord) => {580 if (err) {581 bl.mp.closeModel(soajs, modelObj);582 return cb(bl.handleError(soajs, 602, err));583 }584 if (!accountRecord) {585 bl.mp.closeModel(soajs, modelObj);586 return cb(bl.handleError(soajs, 404, null));587 }588 let driver = bl.mp.getDriver(accountRecord);589 if (!driver) {590 return cb(bl.handleError(soajs, 603, null));591 }592 soajs.log.info("Updating Repositories");593 lib.handleRepositories(bl, soajs, driver, modelObj, accountRecord.repositories ? accountRecord.repositories : {}, () => {594 bl.mp.closeModel(soajs, modelObj);595 });596 return cb(null, {597 message: "Repositories are being updated..."598 });599 });600 },601 602 "upgrade": (soajs, inputmaskData, cb) => {603 let modelObj = bl.mp.getModel(soajs);604 let data = {605 id: inputmaskData.id606 };607 data.token = true;608 modelObj.getAccount(data, (err, account) => {609 if (err) {610 bl.mp.closeModel(soajs, modelObj);611 return cb(bl.handleError(soajs, 602, err));612 }613 if (!account) {614 bl.mp.closeModel(soajs, modelObj);615 return cb(bl.handleError(soajs, 403, err));616 }617 if (account.owner !== inputmaskData.username) {618 bl.mp.closeModel(soajs, modelObj);619 return cb(bl.handleError(soajs, 406, err));620 }621 if (account.access === "private") {622 bl.mp.closeModel(soajs, modelObj);623 return cb(bl.handleError(soajs, 407, err));624 }625 account = Object.assign(account, inputmaskData);626 account.access = "private";627 soajs.inputmaskData.id = account._id.toString();628 let driver = bl.mp.getDriver(account);629 if (!driver) {630 bl.mp.closeModel(soajs, modelObj);631 return cb(bl.handleError(soajs, 603, null));632 }633 let data = {634 config: bl.localConfig635 };636 driver.login(data, (err, loginRecord) => {637 if (err) {638 bl.mp.closeModel(soajs, modelObj);639 return cb(bl.handleError(soajs, 403, err));640 }641 let opts = {642 _id: account._id,643 set: loginRecord644 };645 modelObj.upgradeAccount(opts, (err) => {646 if (err) {647 bl.mp.closeModel(soajs, modelObj);648 return cb(bl.handleError(soajs, 602, err));649 } else {650 soajs.log.info("Updating Repositories");651 lib.handleRepositories(bl, soajs, driver, modelObj, false, () => {652 bl.mp.closeModel(soajs, modelObj);653 });654 return cb(null, {655 id: soajs.inputmaskData.id,656 message: "Account Upgraded. Repositories are being updated..."657 });658 }659 });660 });661 });662 },663 664 "activateRepo": (soajs, inputmaskData, cb) => {665 let modelObj = bl.mp.getModel(soajs);666 async.parallel({667 account: function (callback) {668 let data = {669 provider: inputmaskData.provider,670 owner: inputmaskData.owner671 };672 data.token = true;673 modelObj.getAccount(data, callback);674 },675 repo: function (callback) {676 let data = {677 id: inputmaskData.id678 };679 modelObj.getRepository(data, callback);680 }681 }, function (err, results) {682 if (err) {683 bl.mp.closeModel(soajs, modelObj);684 return cb(bl.handleError(soajs, 602, err));685 }686 if (!results.account) {687 bl.mp.closeModel(soajs, modelObj);688 return cb(bl.handleError(soajs, 403, err));689 }690 691 let driver = bl.mp.getDriver(results.account);692 693 if (!driver) {694 bl.mp.closeModel(soajs, modelObj);695 return cb(bl.handleError(soajs, 603, null));696 }697 if (!results.repo) {698 bl.mp.closeModel(soajs, modelObj);699 return cb(bl.handleError(soajs, 405, err));700 }701 if (results.repo.active) {702 bl.mp.closeModel(soajs, modelObj);703 return cb(bl.handleError(soajs, 408, err));704 }705 let data = {706 config: bl.localConfig,707 repository: results.repo.repository708 };709 driver.listBranches(data, (error, branches) => {710 if (error) {711 bl.mp.closeModel(soajs, modelObj);712 return cb(bl.handleError(soajs, 602, err));713 }714 data = {715 branches: branches,716 active: true,717 _id: results.repo._id718 };719 modelObj.activateSyncRepo(data, (err) => {720 bl.mp.closeModel(soajs, modelObj);721 if (err) {722 return cb(bl.handleError(soajs, 602, err));723 }724 return cb(null, `Repository ${results.repo.repository} is active!`);725 });726 });727 });728 },729 730 "deactivateRepo": (soajs, inputmaskData, cb) => {731 let modelObj = bl.mp.getModel(soajs);732 let data = {733 id: inputmaskData.id734 };735 modelObj.getRepository(data, (err, repo) => {736 if (err) {737 bl.mp.closeModel(soajs, modelObj);738 return cb(bl.handleError(soajs, 602, err));739 }740 if (!repo) {741 bl.mp.closeModel(soajs, modelObj);742 return cb(bl.handleError(soajs, 405, err));743 }744 repo.active = false;745 let activeBranch = false;746 if (repo.branches && repo.branches.length > 0) {747 repo.branches.forEach((oneBranch) => {748 if (oneBranch.active) {749 activeBranch = true;750 }751 });752 }753 if (activeBranch) {754 bl.mp.closeModel(soajs, modelObj);755 return cb(bl.handleError(soajs, 414, err));756 }757 async.parallel([758 function (callback) {759 modelObj.removeRepository(repo, callback);760 },761 function (callback) {762 let opts = {763 provider: repo.provider,764 owner: repo.repository.split("/")[0],765 repo: repo.repository.split("/")[1],766 };767 lib.deleteCatalog_src(soajs, opts, callback);768 }769 ],770 (err) => {771 bl.mp.closeModel(soajs, modelObj);772 if (err) {773 return cb(bl.handleError(soajs, 602, err));774 }775 return cb(null, "Repository deactivated!");776 });777 });778 },779 780 "activateBranch": (soajs, inputmaskData, cb) => {781 let modelObj = bl.mp.getModel(soajs);782 783 async.parallel({784 account: function (callback) {785 let data = {786 provider: inputmaskData.provider,787 owner: inputmaskData.owner788 };789 data.token = true;790 return modelObj.getAccount(data, callback);791 },792 repo: function (callback) {793 let data = {794 id: inputmaskData.id795 };796 return modelObj.getRepository(data, callback);797 }798 }, function (err, results) {799 if (err) {800 bl.mp.closeModel(soajs, modelObj);801 return cb(bl.handleError(soajs, 602, err));802 }803 if (!results.account) {804 bl.mp.closeModel(soajs, modelObj);805 return cb(bl.handleError(soajs, 403, err));806 }807 808 let driver = bl.mp.getDriver(results.account);809 810 if (!driver) {811 bl.mp.closeModel(soajs, modelObj);812 return cb(bl.handleError(soajs, 603, null));813 }814 if (!results.repo) {815 bl.mp.closeModel(soajs, modelObj);816 return cb(bl.handleError(soajs, 405, err));817 }818 if (!results.repo.active) {819 bl.mp.closeModel(soajs, modelObj);820 return cb(bl.handleError(soajs, 409, err));821 }822 if (results.repo.branches && results.repo.branches.length > 0) {823 let found = false;824 for (let x = 0; x < results.repo.branches.length; x++) {825 if (results.repo.branches[x].name === inputmaskData.branch && results.repo.branches[x].active) {826 found = true;827 break;828 }829 }830 if (found) {831 bl.mp.closeModel(soajs, modelObj);832 return cb(bl.handleError(soajs, 412, err));833 }834 }835 let data = {836 config: bl.localConfig,837 repository: results.repo.repository,838 branch: inputmaskData.branch839 };840 driver.getBranch(data, (error, branch) => {841 if (err || !branch) {842 bl.mp.closeModel(soajs, modelObj);843 return cb(bl.handleError(soajs, 410, err));844 }845 let models = {846 modelObj847 };848 let opts = {849 repo: results.repo,850 branch: branch851 };852 lib.computeCatalog(bl, soajs, driver, models, opts, (err, response) => {853 bl.mp.closeModel(soajs, modelObj);854 if (err) {855 return cb(err);856 }857 return cb(null, response);858 });859 });860 });861 },862 863 "activateTag": (soajs, inputmaskData, cb) => {864 let modelObj = bl.mp.getModel(soajs);865 866 async.parallel({867 account: function (callback) {868 let data = {869 provider: inputmaskData.provider,870 owner: inputmaskData.owner871 };872 data.token = true;873 return modelObj.getAccount(data, callback);874 },875 repo: function (callback) {876 let data = {877 id: inputmaskData.id878 };879 return modelObj.getRepository(data, callback);880 }881 }, function (err, results) {882 if (err) {883 bl.mp.closeModel(soajs, modelObj);884 return cb(bl.handleError(soajs, 602, err));885 }886 if (!results.account) {887 bl.mp.closeModel(soajs, modelObj);888 return cb(bl.handleError(soajs, 403, err));889 }890 891 let driver = bl.mp.getDriver(results.account);892 893 if (!driver) {894 bl.mp.closeModel(soajs, modelObj);895 return cb(bl.handleError(soajs, 603, null));896 }897 if (!results.repo) {898 bl.mp.closeModel(soajs, modelObj);899 return cb(bl.handleError(soajs, 405, err));900 }901 if (!results.repo.active) {902 bl.mp.closeModel(soajs, modelObj);903 return cb(bl.handleError(soajs, 409, err));904 }905 if (results.repo.tags && results.repo.tags.length > 0) {906 let found = false;907 for (let x = 0; x < results.repo.tags.length; x++) {908 if (results.repo.tags[x].name === inputmaskData.tag && results.repo.tags[x].active) {909 found = true;910 break;911 }912 }913 if (found) {914 bl.mp.closeModel(soajs, modelObj);915 return cb(bl.handleError(soajs, 418, err));916 }917 }918 let data = {919 config: bl.localConfig,920 repository: results.repo.repository,921 tag: inputmaskData.tag922 };923 driver.getTag(data, (err, tag) => {924 if (err || !tag) {925 bl.mp.closeModel(soajs, modelObj);926 return cb(bl.handleError(soajs, 416, err));927 }928 let models = {929 modelObj930 };931 let opts = {932 repo: results.repo,933 tag: tag.name934 };935 lib.computeCatalog(bl, soajs, driver, models, opts, (err, response) => {936 bl.mp.closeModel(soajs, modelObj);937 if (err) {938 return cb(err);939 }940 return cb(null, response);941 });942 });943 });944 },945 946 "deactivateTag": (soajs, inputmaskData, cb) => {947 let modelObj = bl.mp.getModel(soajs);948 async.parallel({949 account: function (callback) {950 let data = {951 provider: inputmaskData.provider,952 owner: inputmaskData.owner953 };954 data.token = true;955 return modelObj.getAccount(data, callback);956 },957 repo: function (callback) {958 let data = {959 id: inputmaskData.id960 };961 return modelObj.getRepository(data, callback);962 }963 }, function (err, results) {964 if (err) {965 bl.mp.closeModel(soajs, modelObj);966 return cb(bl.handleError(soajs, 602, err));967 }968 if (!results.account) {969 bl.mp.closeModel(soajs, modelObj);970 return cb(bl.handleError(soajs, 403, err));971 }972 973 let driver = bl.mp.getDriver(results.account);974 975 if (!driver) {976 bl.mp.closeModel(soajs, modelObj);977 return cb(bl.handleError(soajs, 603, null));978 }979 if (!results.repo) {980 bl.mp.closeModel(soajs, modelObj);981 return cb(bl.handleError(soajs, 405, err));982 }983 if (!results.repo.active) {984 bl.mp.closeModel(soajs, modelObj);985 return cb(bl.handleError(soajs, 409, err));986 }987 if (results.repo.tags && results.repo.tags.length > 0) {988 let found = false;989 for (let x = 0; x < results.repo.tags.length; x++) {990 if (results.repo.tags[x].name === inputmaskData.tag && results.repo.tags[x].active) {991 found = true;992 break;993 }994 }995 if (!found) {996 bl.mp.closeModel(soajs, modelObj);997 return cb(bl.handleError(soajs, 416, err));998 }999 }1000 let opts = {1001 provider: results.repo.provider,1002 owner: results.repo.owner,1003 repo: results.repo.name1004 };1005 lib.getCatalogs(soajs, opts, (error, multiRepo) => {1006 if (error) {1007 return cb(bl.handleError(soajs, 605, error));1008 }1009 async.each(multiRepo, function (catalog, callback) {1010 let opts = {1011 "name": catalog.name,1012 "type": catalog.type,1013 "tag": inputmaskData.tag1014 };1015 lib.updateVersionTag(soajs, opts, callback);1016 }, function (error) {1017 if (error) {1018 bl.mp.closeModel(soajs, modelObj);1019 return cb(bl.handleError(soajs, 605, error));1020 }1021 let opts = {1022 name: inputmaskData.tag,1023 _id: results.repo._id,1024 active: false1025 };1026 modelObj.updateTags(opts, (err) => {1027 bl.mp.closeModel(soajs, modelObj);1028 if (err) {1029 return cb(bl.handleError(soajs, 602, err));1030 }1031 return cb(null, `Tag ${inputmaskData.tag} deactivated!`);1032 });1033 });1034 });1035 }1036 );1037 },1038 1039 "deactivateBranch": (soajs, inputmaskData, cb) => {1040 let modelObj = bl.mp.getModel(soajs);1041 async.parallel({1042 account: function (callback) {1043 let data = {1044 provider: inputmaskData.provider,1045 owner: inputmaskData.owner1046 };1047 data.token = true;1048 return modelObj.getAccount(data, callback);1049 },1050 repo: function (callback) {1051 let data = {1052 id: inputmaskData.id1053 };1054 return modelObj.getRepository(data, callback);1055 }1056 }, function (err, results) {1057 if (err) {1058 bl.mp.closeModel(soajs, modelObj);1059 return cb(bl.handleError(soajs, 602, err));1060 }1061 if (!results.account) {1062 bl.mp.closeModel(soajs, modelObj);1063 return cb(bl.handleError(soajs, 403, err));1064 }1065 1066 let driver = bl.mp.getDriver(results.account);1067 1068 if (!driver) {1069 bl.mp.closeModel(soajs, modelObj);1070 return cb(bl.handleError(soajs, 603, null));1071 }1072 if (!results.repo) {1073 bl.mp.closeModel(soajs, modelObj);1074 return cb(bl.handleError(soajs, 405, err));1075 }1076 if (!results.repo.active) {1077 bl.mp.closeModel(soajs, modelObj);1078 return cb(bl.handleError(soajs, 409, err));1079 }1080 if (results.repo.branches && results.repo.branches.length > 0) {1081 let found = false;1082 for (let x = 0; x < results.repo.branches.length; x++) {1083 if (results.repo.branches[x].name === inputmaskData.branch && results.repo.branches[x].active) {1084 found = true;1085 break;1086 }1087 }1088 if (!found) {1089 bl.mp.closeModel(soajs, modelObj);1090 return cb(bl.handleError(soajs, 410, err));1091 }1092 }1093 let opts = {1094 provider: results.repo.provider,1095 owner: results.repo.owner,1096 repo: results.repo.name1097 };1098 lib.getCatalogs(soajs, opts, (error, multiRepo) => {1099 if (error) {1100 return cb(bl.handleError(soajs, 605, error));1101 }1102 async.each(multiRepo, function (catalog, callback) {1103 let opts = {1104 "name": catalog.name,1105 "type": catalog.type,1106 "branch": inputmaskData.branch1107 };1108 lib.updateVersionBranch(soajs, opts, callback);1109 }, function (error) {1110 if (error) {1111 bl.mp.closeModel(soajs, modelObj);1112 return cb(bl.handleError(soajs, 605, error));1113 }1114 let opts = {1115 name: inputmaskData.branch,1116 _id: results.repo._id,1117 active: false1118 };1119 modelObj.updateBranches(opts, (err) => {1120 bl.mp.closeModel(soajs, modelObj);1121 if (err) {1122 return cb(bl.handleError(soajs, 602, err));1123 }1124 return cb(null, `Branch ${inputmaskData.branch} deactivated!`);1125 });1126 });1127 });1128 }1129 );1130 },1131 1132 "syncRepo": (soajs, inputmaskData, cb) => {1133 let modelObj = bl.mp.getModel(soajs);1134 async.parallel({1135 account: function (callback) {1136 let data = {1137 provider: inputmaskData.provider,1138 owner: inputmaskData.owner1139 };1140 data.token = true;1141 modelObj.getAccount(data, callback);1142 },1143 repo: function (callback) {1144 let data = {1145 id: inputmaskData.id1146 };1147 modelObj.getRepository(data, callback);1148 }1149 }, function (err, results) {1150 if (err) {1151 bl.mp.closeModel(soajs, modelObj);1152 return cb(bl.handleError(soajs, 602, err));1153 }1154 if (!results.account) {1155 bl.mp.closeModel(soajs, modelObj);1156 return cb(bl.handleError(soajs, 403, err));1157 }1158 1159 let driver = bl.mp.getDriver(results.account);1160 1161 if (!driver) {1162 bl.mp.closeModel(soajs, modelObj);1163 return cb(bl.handleError(soajs, 603, null));1164 }1165 if (!results.repo) {1166 bl.mp.closeModel(soajs, modelObj);1167 return cb(bl.handleError(soajs, 405, err));1168 }1169 if (!results.repo.active) {1170 bl.mp.closeModel(soajs, modelObj);1171 return cb(bl.handleError(soajs, 409, err));1172 }1173 let data = {1174 config: bl.localConfig,1175 repository: results.repo.repository1176 };1177 driver.listBranches(data, (error, branches) => {1178 if (error) {1179 bl.mp.closeModel(soajs, modelObj);1180 return cb(bl.handleError(soajs, 602, error));1181 }1182 data = {1183 _id: results.repo._id1184 };1185 if (results.repo.branches) {1186 let intersect = _.intersectionBy(results.repo.branches, branches, "name");1187 data.branches = _.unionBy(intersect, branches, "name");1188 } else {1189 data.branches = branches;1190 }1191 modelObj.activateSyncRepo(data, (err) => {1192 bl.mp.closeModel(soajs, modelObj);1193 if (err) {1194 return cb(bl.handleError(soajs, 602, err));1195 }1196 return cb(null, `Repository ${results.repo.repository} is synchronized!`);1197 });1198 });1199 });1200 },1201 1202 "syncBranch": (soajs, inputmaskData, cb) => {1203 let modelObj = bl.mp.getModel(soajs);1204 1205 async.parallel({1206 account: function (callback) {1207 let data = {1208 provider: inputmaskData.provider,1209 owner: inputmaskData.owner1210 };1211 data.token = true;1212 return modelObj.getAccount(data, callback);1213 },1214 repo: function (callback) {1215 let data = {1216 id: inputmaskData.id1217 };1218 return modelObj.getRepository(data, callback);1219 }1220 }, function (err, results) {1221 if (err) {1222 bl.mp.closeModel(soajs, modelObj);1223 return cb(bl.handleError(soajs, 602, err));1224 }1225 if (!results.account) {1226 bl.mp.closeModel(soajs, modelObj);1227 return cb(bl.handleError(soajs, 403, err));1228 }1229 1230 let driver = bl.mp.getDriver(results.account);1231 1232 if (!driver) {1233 bl.mp.closeModel(soajs, modelObj);1234 return cb(bl.handleError(soajs, 603, null));1235 }1236 if (!results.repo) {1237 bl.mp.closeModel(soajs, modelObj);1238 return cb(bl.handleError(soajs, 405, err));1239 }1240 if (!results.repo.active) {1241 bl.mp.closeModel(soajs, modelObj);1242 return cb(bl.handleError(soajs, 409, err));1243 }1244 if (results.repo.branches && results.repo.branches.length > 0) {1245 let found = false;1246 for (let x = 0; x < results.repo.branches.length; x++) {1247 if (results.repo.branches[x].name === inputmaskData.branch && results.repo.branches[x].active) {1248 found = true;1249 break;1250 }1251 }1252 if (!found) {1253 bl.mp.closeModel(soajs, modelObj);1254 return cb(bl.handleError(soajs, 415, err));1255 }1256 }1257 let data = {1258 config: bl.localConfig,1259 repository: results.repo.repository,1260 branch: inputmaskData.branch1261 };1262 driver.getBranch(data, (error, branch) => {1263 if (err || !branch) {1264 bl.mp.closeModel(soajs, modelObj);1265 return cb(bl.handleError(soajs, 410, err));1266 }1267 let models = {1268 modelObj1269 };1270 let opts = {1271 repo: results.repo,1272 branch: branch,1273 sync: true1274 };1275 lib.computeCatalog(bl, soajs, driver, models, opts, cb);1276 });1277 });1278 },1279};...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...27 }28 });29 },function(err){30 if(err){31 handleError(res,err,409,5);32 }33 else34 {35 handleSuccess(res);36 }37 });38 }else if(req.body.chapterMap){39 var mapping = req.body.chapterMap;40 async.each(mapping,function(item,callback){41 Chapters.update({_id: item.id}, {$set:{order: item.order}}, function (err, wRes) {42 if (err) {43 callback(err);44 } else {45 callback();46 }47 });48 },function(err){49 if(err){50 handleError(res,err,409,5);51 }52 else53 {54 handleSuccess(res);55 }56 });57 } else if(req.body.subChaptersMap){58 var mapping = req.body.subChaptersMap;59 async.each(mapping,function(item,callback){60 Subchapters.update({_id: item.id}, {$set:{order: item.order}}, function (err, wRes) {61 if (err) {62 callback(err);63 } else {64 callback();65 }66 });67 },function(err){68 if(err){69 handleError(res,err,409,5);70 }71 else72 {73 handleSuccess(res);74 }75 });76 } else if(req.body.slidesMap){77 var mapping = req.body.slidesMap;78 async.each(mapping,function(item,callback){79 Slides.update({_id: item.id}, {$set:{order: item.order}}, function (err, wRes) {80 if (err) {81 callback(err);82 } else {83 callback();84 }85 });86 },function(err){87 if(err){88 handleError(res,err,409,5);89 }90 else91 {92 handleSuccess(res);93 }94 });95 } else if(req.body.questionsMap){96 var mapping = req.body.questionsMap;97 async.each(mapping,function(item,callback){98 Questions.update({_id: item.id}, {$set:{order: item.order}}, function (err, wRes) {99 if (err) {100 callback(err);101 } else {102 callback();103 }104 });105 },function(err){106 if(err){107 handleError(res,err,409,5);108 }109 else110 {111 handleSuccess(res);112 }113 });114 } else115 handleError(res, null, 400, 6);116 });117 router.route('/admin/elearning/courses')118 .get(function (req, res) {119 if(req.query.id){120 Courses.findOne({_id: req.query.id}).populate('groupsID').exec(function (err, course) {121 if(err){122 handleError(res, err);123 }else{124 handleSuccess(res, course);125 }126 });127 }else{128 Courses.find({$query:{}, $orderby: {order: 1}}).deepPopulate("listChapters.listSubchapters.listSlides").exec(function (err, courses) {129 if(err){130 handleError(res, err);131 }else{132 handleSuccess(res, courses);133 }134 });135 }136 })137 .post(function (req, res) {138 if(!req.body.course){139 handleError(res, null, 400, 6);140 }else{141 try{142 var toAdd = new Courses(req.body.course);143 toAdd.save(function (err, saved) {144 if(err){145 handleError(res, err);146 }else{147 handleSuccess(res, saved);148 }149 });150 }catch(ex){151 handleError(res, ex);152 }153 }154 })155 .put(function (req, res) {156 if(req.body.imagePath){157 var info = req.body.imagePath;158 Courses.update({_id: req.query.id}, {$set:{image_path: info}}, function (err, wRes) {159 if (err) {160 handleError(res,err,500);161 } else {162 handleSuccess(res, {updated: wRes}, 3);163 }164 });165 }else if(req.body.status){166 Courses.findOne({_id: req.query.id}).deepPopulate("listChapters.listSubchapters.listSlides").exec(function (err, course) {167 if(err){168 handleError(res, err);169 }else{170 async.each(course.listChapters,function(chapter,callback1){171 async.each(chapter.listSubchapters,function(subchapter,callback2){172 async.each(subchapter.listSlides,function(slide,callback3){173 Slides.update({_id: slide._id},{$set:{enabled: req.body.status.isEnabled}}).exec(function (err, wRes) {174 if(err){175 callback3(err);176 }else{177 callback3();178 }179 });180 },function(err){181 if(err){182 handleError(res,err);183 }184 else185 {186 Subchapters.update({_id: subchapter._id},{$set:{enabled: req.body.status.isEnabled}}).exec(function (err, wRes) {187 if(err){188 callback2(err);189 }else{190 callback2();191 }192 });193 }194 });195 },function(err){196 if(err){197 handleError(res,err);198 }199 else200 {201 Chapters.update({_id: chapter._id},{$set:{enabled: req.body.status.isEnabled}}).exec(function (err, wRes) {202 if(err){203 callback1(err);204 }else{205 callback1();206 }207 });208 }209 });210 },function(err){211 if(err){212 handleError(res,err);213 }214 else215 {216 Courses.update({_id: req.query.id}, {$set:{enabled: req.body.status.isEnabled}}, function (err, wRes) {217 if (err) {218 handleError(res,err,500);219 } else {220 handleSuccess(res, {updated: wRes}, 3);221 }222 });223 }224 });225 }226 });227 }228 else{229 var data = req.body.course;230 data.last_updated = new Date();231 Courses.update({_id:req.query.id},{$set:data}, function(err, course) {232 if (err){233 console.log(err);234 handleError(res,err,500);235 }else{236 handleSuccess(res, {}, 3);237 }238 });239 }240 })241 .delete(function (req, res) {242 var idToDelete = ObjectId(req.query.id);243 if(idToDelete){244 //first we must delete the slides, then the subchapters, chapters and finally the course245 Courses.findOne({_id: idToDelete}).deepPopulate("listChapters.listSubchapters.listSlides.questions.answers").exec(function (err, course) {246 if(err){247 handleError(res, err);248 }else{249 async.each(course.listChapters,function(chapter,callback1){250 async.each(chapter.listSubchapters,function(subchapter,callback2){251 async.each(subchapter.listSlides,function(slide,callback3){252 async.each(slide.questions,function(question,callback4){253 Answers.remove({_id: {$in: question.answers}}).exec(function(err,resp){254 if(err){255 callback4(err);256 }else{257 callback4();258 }259 })260 },function(err){261 if(err){262 handleError(res,err);263 }264 else265 {266 Questions.remove({_id: {$in: slide.questions}}).exec(function(err,resp){267 if(err){268 callback3(err);269 }else{270 callback3();271 }272 })273 }274 });275 },function(err){276 if(err){277 handleError(res,err);278 }279 else280 {281 Slides.remove({_id: {$in: subchapter.listSlides}}).exec(function(err,resp){282 if(err){283 callback2(err);284 }else{285 callback2();286 }287 })288 }289 });290 },function(err){291 if(err){292 handleError(res,err);293 }294 else295 {296 Subchapters.remove({_id: {$in: chapter.listSubchapters}}).exec(function(err,resp){297 if(err){298 callback1(err);299 }else{300 callback1();301 }302 })303 }304 });305 },function(err){306 if(err){307 handleError(res,err);308 }309 else310 {311 Chapters.remove({_id: {$in: course.listChapters}}).exec(function(err,resp){312 if(err){313 handleError(res,err);314 }else{315 Courses.remove({_id: idToDelete}, function (err, wRes) {316 if(err){317 handleError(res, err);318 }else if(wRes == 0){319 handleError(res, null, 404, 51);320 }else{321 handleSuccess(res);322 }323 });324 }325 })326 }327 });328 }329 });330 }else{331 handleError(res, null, 400, 6);332 }333 });334 router.route('/admin/elearning/chapters')335 .get(function (req, res) {336 if(req.query.id){337 Chapters.findOne({_id: req.query.id}).exec(function (err, chapter) {338 if(err){339 handleError(res, err);340 }else{341 handleSuccess(res, chapter);342 }343 });344 }else{345 Chapters.find({}, function (err, chapters) {346 if(err){347 handleError(res, err);348 }else{349 handleSuccess(res, chapters);350 }351 });352 }353 })354 .post(function (req, res) {355 if(!req.body.chapter){356 handleError(res, null, 400, 6);357 }else{358 try{359 var toAdd = new Chapters(req.body.chapter);360 toAdd.save(function (err, saved) {361 if(err){362 handleError(res, err);363 }else{364 Courses.update({_id: req.body.courseId}, {$addToSet: {listChapters: saved._id}}, function (err, wres) {365 if(err){366 handleError(res,err,500);367 }else{368 handleSuccess(res, saved);369 }370 });371 }372 });373 }catch(ex){374 handleError(res, ex);375 }376 }377 })378 .put(function (req, res) {379 if(req.body.status){380 Chapters.update({_id: req.query.id},{$set:{enabled: req.body.status.isEnabled}}).exec(function (err, wRes) {381 if(err){382 handleError(res,err,500);383 }else{384 handleSuccess(res);385 }386 });387 }388 else {389 var data = req.body.chapter;390 data.last_updated = new Date();391 Chapters.update({_id: req.query.id}, {$set: data}, function (err, course) {392 if (err) {393 handleError(res, err, 500);394 } else {395 handleSuccess(res, {}, 3);396 }397 });398 }399 })400 .delete(function (req, res) {401 var idToDelete = ObjectId(req.query.id);402 if(idToDelete){403 //first we must delete the slides, then the subchapters, chapters and finally the course404 Chapters.findOne({_id: idToDelete}).deepPopulate("listSubchapters.listSlides.questions.answers").exec(function (err, chapter) {405 if(err){406 handleError(res, err);407 }else{408 async.each(chapter.listSubchapters,function(subchapter,callback2){409 async.each(subchapter.listSlides,function(slide,callback3){410 async.each(slide.questions,function(question,callback4){411 Answers.remove({_id: {$in: question.answers}}).exec(function(err,resp){412 if(err){413 callback4(err);414 }else{415 callback4();416 }417 })418 },function(err){419 if(err){420 handleError(res,err);421 }422 else423 {424 Questions.remove({_id: {$in: slide.questions}}).exec(function(err,resp){425 if(err){426 callback3(err);427 }else{428 callback3();429 }430 })431 }432 });433 },function(err){434 if(err){435 handleError(res,err);436 }437 else438 {439 Slides.remove({_id: {$in: subchapter.listSlides}}).exec(function(err,resp){440 if(err){441 callback2(err);442 }else{443 callback2();444 }445 })446 }447 });448 },function(err){449 if(err){450 handleError(res,err);451 }452 else453 {454 Subchapters.remove({_id: {$in: chapter.listSubchapters}}).exec(function(err,resp){455 if(err){456 handleError(res,err);457 }else{458 Courses.update({}, {$pull: {listChapters: idToDelete}}, {multi: true}).exec(function (err, wres) {459 if(err){460 handleError(res, err);461 }else{462 Chapters.remove({_id: idToDelete}, function (err, wRes) {463 if(err){464 handleError(res, err);465 }else if(wRes == 0){466 handleError(res, null, 404, 51);467 }else{468 handleSuccess(res);469 }470 });471 }472 });473 }474 })475 }476 });477 }478 });479 }else{480 handleError(res, null, 400, 6);481 }482 });483 router.route('/admin/elearning/subchapters')484 .get(function (req, res) {485 if(req.query.id){486 Subchapters.findOne({_id: req.query.id}).exec(function (err, course) {487 if(err){488 handleError(res, err);489 }else{490 handleSuccess(res, course);491 }492 });493 }else{494 Subchapters.find({}, function (err, courses) {495 if(err){496 handleError(res, err);497 }else{498 handleSuccess(res, courses);499 }500 });501 }502 })503 .post(function (req, res) {504 if(!req.body.subChapter){505 handleError(res, null, 400, 6);506 }else{507 try{508 var toAdd = new Subchapters(req.body.subChapter);509 toAdd.save(function (err, saved) {510 if(err){511 handleError(res, err);512 }else{513 Chapters.update({_id: req.body.chapterId}, {$addToSet: {listSubchapters: saved._id}}, function (err, wres) {514 if(err){515 handleError(res,err,500);516 }else{517 handleSuccess(res, saved);518 }519 });520 }521 });522 }catch(ex){523 handleError(res, ex);524 }525 }526 })527 .put(function (req, res) {528 if(req.body.status){529 Subchapters.update({_id: req.query.id},{$set:{enabled: req.body.status.isEnabled}}).exec(function (err, wRes) {530 if(err){531 handleError(res,err,500);532 }else{533 handleSuccess(res);534 }535 });536 }537 else {538 var data = req.body.subChapter;539 data.last_updated = new Date();540 Subchapters.update({_id: req.query.id}, {$set: data}, function (err, course) {541 if (err) {542 handleError(res, err, 500);543 } else {544 handleSuccess(res, {}, 3);545 }546 });547 }548 })549 .delete(function (req, res) {550 var idToDelete = ObjectId(req.query.id);551 if(idToDelete){552 //first we must delete the slides, then the subchapters, chapters and finally the course553 Subchapters.findOne({_id: idToDelete}).deepPopulate("listSlides.questions.answers").exec(function (err, subchapter) {554 if(err){555 handleError(res, err);556 }else{557 async.each(subchapter.listSlides,function(slide,callback3){558 async.each(slide.questions,function(question,callback4){559 Answers.remove({_id: {$in: question.answers}}).exec(function(err,resp){560 if(err){561 callback4(err);562 }else{563 callback4();564 }565 })566 },function(err){567 if(err){568 handleError(res,err);569 }570 else571 {572 Questions.remove({_id: {$in: slide.questions}}).exec(function(err,resp){573 if(err){574 callback3(err);575 }else{576 callback3();577 }578 })579 }580 });581 },function(err){582 if(err){583 handleError(res,err);584 }585 else586 {587 Slides.remove({_id: {$in: subchapter.listSlides}}).exec(function(err,resp){588 if(err){589 handleError(res,err);590 }else{591 Chapters.update({}, {$pull: {listSubchapters: idToDelete}}, {multi: true}).exec(function (err, wres) {592 if(err){593 handleError(res, err);594 }else{595 Subchapters.remove({_id: idToDelete}, function (err, wRes) {596 if(err){597 handleError(res, err);598 }else if(wRes == 0){599 handleError(res, null, 404, 51);600 }else{601 handleSuccess(res);602 }603 });604 }605 });606 }607 })608 }609 });610 }611 });612 }else{613 handleError(res, null, 400, 6);614 }615 });616 router.route('/admin/elearning/slides')617 .get(function (req, res) {618 if(req.query.id){619 Slides.findOne({_id: req.query.id}).deepPopulate('questions.answers',{620 whitelist: ['questions.answers'],621 populate : {622 'questions.answers' : {623 options: {624 sort: {625 "order": 1626 },627 select: 'ratio text',628 }629 }630 }631 }).exec(function (err, course) {632 if(err){633 handleError(res, err);634 }else{635 handleSuccess(res, course);636 }637 });638 }else{639 Slides.find({}, function (err, courses) {640 if(err){641 handleError(res, err);642 }else{643 handleSuccess(res, courses);644 }645 });646 }647 })648 .post(function (req, res) {649 if(!req.body.slide){650 handleError(res, null, 400, 6);651 }else{652 try{653 var toAdd = new Slides(req.body.slide);654 toAdd.save(function (err, saved) {655 if(err){656 handleError(res, err);657 }else{658 Subchapters.update({_id: req.body.id}, {$addToSet: {listSlides: saved._id}}, function (err, wres) {659 if(err){660 handleError(res,err,500);661 }else{662 handleSuccess(res, saved);663 }664 });665 }666 });667 }catch(ex){668 handleError(res, ex);669 }670 }671 })672 .put(function (req, res) {673 var data = req.body.slide;674 if(req.body.status){675 Slides.update({_id: req.query.id},{$set:{enabled: req.body.status.isEnabled}}).exec(function (err, wRes) {676 if(err){677 handleError(res,err,500);678 }else{679 handleSuccess(res);680 }681 });682 }683 else if(req.body.isSlide){684 data.last_updated = new Date();685 Slides.update({_id:req.query.id},{$set:data}, function(err, course) {686 if (err){687 handleError(res,err,500);688 }else{689 handleSuccess(res, {}, 3);690 }691 });692 }else{693 var questionsIds = [];694 async.each(data.questions,function(question,callback3){695 var answerIds = [];696 async.each(question.answers,function(answer,callback4){697 Answers.update({_id: answer._id},{$set: answer}, function(err, ans) {698 if (err){699 callback4(err);700 }else{701 answerIds.push(answer._id);702 callback4();703 }704 });705 },function(err){706 if(err){707 handleError(res,err);708 }709 else710 {711 question.answers = answerIds;712 Questions.update({_id: question._id},{$set: question}, function(err, quest) {713 if (err){714 callback3(err);715 }else{716 questionsIds.push(question._id);717 callback3();718 }719 });720 }721 });722 },function(err){723 if(err){724 handleError(res,err);725 }726 else727 {728 data.questions = questionsIds;729 Slides.update({_id:data._id},{$set:data}, function(err, slide) {730 if (err){731 handleError(res,err,500);732 }else{733 handleSuccess(res, {}, 3);734 }735 });736 }737 });738 }739 })740 .delete(function (req, res) {741 var idToDelete = ObjectId(req.query.id);742 if(idToDelete){743 Slides.findOne({_id: idToDelete}).deepPopulate("questions.answers").exec(function (err, slide) {744 if(err){745 handleError(res, err);746 }else{747 async.each(slide.questions,function(question,callback3){748 async.each(question.answers,function(answer,callback4){749 Answers.remove({_id: {$in: question.answers}}).exec(function(err,resp){750 if(err){751 callback4(err);752 }else{753 callback4();754 }755 })756 },function(err){757 if(err){758 handleError(res,err);759 }760 else761 {762 Questions.remove({_id: {$in: slide.questions}}).exec(function(err,resp){763 if(err){764 callback3(err);765 }else{766 callback3();767 }768 })769 }770 });771 },function(err){772 if(err){773 handleError(res,err);774 }775 else776 {777 Subchapters.update({}, {$pull: {listSlides: idToDelete}}, {multi: true}).exec(function (err, wres) {778 if(err){779 handleError(res, err);780 }else{781 Slides.remove({_id: idToDelete}, function (err, wRes) {782 if(err){783 handleError(res, err);784 }else if(wRes == 0){785 handleError(res, null, 404, 51);786 }else{787 handleSuccess(res);788 }789 });790 }791 });792 }793 });794 }795 });796 }else{797 handleError(res, null, 400, 6);798 }799 });800 router.route('/admin/elearning/questions')801 .post(function (req, res) {802 if(!req.body.question){803 handleError(res, null, 400, 6);804 }else{805 try{806 var toAdd = req.body.question;807 var answersIds = [];808 async.each(toAdd.answers,function(answer,callback4){809 var answerToAdd = new Answers(answer);810 answerToAdd.save(function (err, saved) {811 if(err){812 callback4(err);813 }else{814 answersIds.push(saved._id);815 callback4();816 }817 });818 },function(err){819 if(err){820 handleError(res,err);821 }822 else823 {824 toAdd.answers = answersIds;825 toAdd = new Questions(toAdd);826 toAdd.save(function (err, saved2) {827 if(err){828 handleError(res, err);829 }else{830 Slides.update({_id: req.body.id}, {$addToSet: {questions: saved2._id}}, function (err, wres) {831 if(err){832 handleError(res,err,500);833 }else{834 Questions.findOne({_id: saved2._id}).deepPopulate('answers',{835 whitelist: ['answers'],836 populate : {837 'answers' : {838 options: {839 sort: {840 "order": 1841 },842 select: 'ratio text',843 }844 }845 }846 }).exec(function(err, response){847 if(err){848 handleError(res,err);849 }850 else851 handleSuccess(res, response);852 })853 }854 });855 }856 });857 }858 });859 }catch(ex){860 handleError(res, ex);861 }862 }863 })864 .put(function (req, res) {865 var data = req.body.question;866 Questions.update({_id:req.query.id},{$set:data}, function(err, quest) {867 if (err){868 handleError(res,err,500);869 }else{870 handleSuccess(res, {}, 3);871 }872 });873 })874 .delete(function (req, res) {875 var idToDelete = ObjectId(req.query.id);876 if(idToDelete){877 Questions.findOne({_id: idToDelete}).exec(function (err, question) {878 if(err){879 handleError(res, err);880 }else{881 Answers.remove({_id: {$in: question.answers}}).exec(function(err,resp){882 if(err){883 handleError(res, err);884 }else{885 Slides.update({}, {$pull: {questions: idToDelete}}, {multi: true}).exec(function (err, wres) {886 if(err){887 handleError(res, err);888 }else{889 Questions.remove({_id: idToDelete}, function (err, wRes) {890 if(err){891 handleError(res, err);892 }else if(wRes == 0){893 handleError(res, null, 404, 51);894 }else{895 handleSuccess(res);896 }897 });898 }899 });900 }901 })902 }903 });904 }else{905 handleError(res, null, 400, 6);906 }907 });908 router.route('/admin/elearning/answers')909 .post(function (req, res) {910 if(!req.body.answer){911 handleError(res, null, 400, 6);912 }else{913 try{914 var toAdd = new Answers(req.body.answer);915 toAdd.save(function (err, saved) {916 if(err){917 handleError(res, err);918 }else{919 Questions.update({_id: req.body.id}, {$addToSet: {answers: saved._id}}, function (err, wres) {920 if(err){921 handleError(res,err,500);922 }else{923 handleSuccess(res, saved);924 }925 });926 }927 });928 }catch(ex){929 handleError(res, ex);930 }931 }932 })933 .put(function (req, res) {934 var data = req.body.answer;935 Answers.update({_id:req.query.id},{$set:data}, function(err, course) {936 if (err){937 handleError(res,err,500);938 }else{939 handleSuccess(res, {}, 3);940 }941 });942 })943 .delete(function (req, res) {944 var idToDelete = ObjectId(req.query.id);945 if(idToDelete){946 Questions.update({}, {$pull: {answers: idToDelete}}, {multi: true}).exec(function (err, wres) {947 if(err){948 handleError(res, err);949 }else{950 Answers.remove({_id: idToDelete}, function (err, wRes) {951 if(err){952 handleError(res, err);953 }else if(wRes == 0){954 handleError(res, null, 404, 51);955 }else{956 handleSuccess(res);957 }958 });959 }960 });961 }else{962 handleError(res, null, 400, 6);963 }964 });965 router.route('/elearning/courses')966 .get(function (req, res) {967 if(req.query.id){968 ContentVerifier.getContentById(Courses,req.query.id,false,false,'enabled','','groupsID',true).then(969 function(success){970 var objectToSend = {};971 objectToSend.courseDetails = success;972 objectToSend.slideViews = req.user.elearning.slide;973 handleSuccess(res, objectToSend);974 },function(err){975 if (err.status == 404)976 var message = 45;977 else978 var message = 46;979 handleError(res,null,err.status, message);980 }981 );982 }else{983 Courses.find({enabled: true}).sort({"order": 1}).exec(function(err, courses){984 if(err){985 handleError(res, err);986 }else{987 handleSuccess(res, courses);988 }989 });990 }991 });992 router.route('/elearning/subchapters')993 .get(function(req, res){994 if(!req.query.id){995 return handleError(res, false, 400, 6);996 }else{997 Subchapters.findOne({_id: req.query.id}).populate({path: 'listSlides', options: { sort: {order: 1}}}).exec(function(err, subchapter){998 if(err){999 return handleError(res, err);1000 }else if(!subchapter){1001 return handleError(res, err);1002 }else{1003 return handleSuccess(res, subchapter);1004 }1005 });1006 }1007 });1008 router.route('/elearning/slides')1009 .get(function(req, res){1010 if(!req.query.id){1011 handleError(res, false, 400, 6);1012 }else{1013 ElearningService.getSlide(req.query.id, req.query.previous, req.query.next).then(1014 function(slide){1015 var slideViews = ElearningService.getSlideViews(req.user, slide._id);1016 if(slide.type === "test"){1017 if(typeof slide.retake === "number" && slideViews >= slide.retake){1018 return handleError(res, false, 403, 42);1019 }else{1020 Slides.deepPopulate(slide, "questions.answers", function(err, slide){1021 if(err){1022 handleError(res, err);1023 }else{1024 handleSuccess(res, slide);1025 }1026 });1027 }1028 }else{1029 handleSuccess(res, slide);1030 ElearningService.userViewedSlide(slide._id, req.user);1031 }1032 },1033 function(err){1034 if(err){1035 handleError(res, err);1036 }else{1037 handleError(res, false, 404, 1);1038 }1039 }1040 );1041 }1042 })1043 .post(function(req, res){1044 //this route is for validating a user's test1045 if(!req.query.id){1046 return handleError(res, false, 400, 6);1047 }else{1048 var slideViews = ElearningService.getSlideViews(req.user, req.query.id);1049 Slides.findOne({_id: req.query.id, type: "test"}, function(err, slide){1050 if(err){1051 return handleError(res, err);1052 }else if(!slide){1053 return handleError(res, false, 404, 1);1054 }else if(typeof slide.retake === "number" && slideViews >= slide.retake){1055 return handleError(res, false, 403, 42);1056 }else{1057 //first we need to get a total of the answered questions and a total of all questions in parallel1058 //the request body will look like:1059 //{1060 // id_question1: [id_anwers],1061 // id_question2: [id_anwers]1062 //}1063 Q.all([1064 ElearningService.getQuestionsMaxPoints(slide.questions),1065 ElearningService.getUserPoints(req.body)1066 ]).then(1067 function(results){1068 var totalScore = results[0];1069 var userScore = results[1];1070 var normalisedScore = Math.round(userScore*slide.maximum/totalScore);1071 // console.log(totalScore);1072 // console.log(userScore);1073 // console.log(normalisedScore);1074 // 1075 // finally, record score on user1076 var updateQuery = {$set: {}};1077 var upd = "elearning.slide."+slide._id+".score";1078 updateQuery.$set[upd] = normalisedScore;1079 //console.log(updateQuery);1080 Users.update({_id: req.user._id}, updateQuery, function(err){1081 if(err){1082 handleError(res, err);1083 }else{1084 handleSuccess(res, normalisedScore);1085 ElearningService.userViewedSlide(slide._id, req.user);1086 }1087 })1088 },1089 function(err){1090 handleError(res, err);1091 }1092 );1093 }1094 });1095 }1096 });1097 ...

Full Screen

Full Screen

permi.js

Source:permi.js Github

copy

Full Screen

...15 cordova.plugins.diagnostic.registerLocationStateChangeHandler(function (state) {16 log("Location state changed to: " + state);17 checkState();18 }, function (error) {19 handleError("Error registering for location state changes: " + error);20 });21 }22 // Register change listeners for Android23 if(platform === "android"){24 cordova.plugins.diagnostic.registerPermissionRequestCompleteHandler(function(statuses){25 console.info("Permission request complete");26 for (var permission in statuses){27 switch(statuses[permission]){28 case cordova.plugins.diagnostic.permissionStatus.GRANTED:29 log("Permission granted to use "+permission);30 break;31 case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:32 log("Permission to use "+permission+" has not been requested yet");33 break;34 case cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE:35 log("Permission denied to use "+permission);36 break;37 case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:38 log("Permission permanently denied to use "+permission);39 break;40 }41 }42 });43 cordova.plugins.diagnostic.registerNFCStateChangeHandler(function (state) {44 log("NFC state changed to: " + state);45 checkState();46 }, function (error) {47 handleError("Error registering for NFC state changes: " + error);48 });49 registerBluetoothStateChangeHandler();50 }51 // iOS+Android settings52 $('#request-camera').on("click", function(){53 cordova.plugins.diagnostic.requestCameraAuthorization({54 successCallback: function(status){55 log("Successfully requested camera authorization: authorization was " + status);56 checkState();57 },58 errorCallback: handleError,59 externalStorage: true60 });61 });62 $('#settings').on("click", function(){63 cordova.plugins.diagnostic.switchToSettings(function(){64 log("Successfully opened settings");65 }, handleError);66 });67 $('#request-microphone').on("click", function(){68 cordova.plugins.diagnostic.requestMicrophoneAuthorization(function(status){69 log("Successfully requested microphone authorization: authorization was " + status);70 checkState();71 }, handleError);72 });73 $('#request-contacts').on("click", function(){74 cordova.plugins.diagnostic.requestContactsAuthorization(function(status){75 log("Successfully requested contacts authorization: authorization was " + status);76 checkState();77 }, handleError);78 });79 $('#request-calendar').on("click", function(){80 cordova.plugins.diagnostic.requestCalendarAuthorization(function(status){81 log("Successfully requested calendar authorization: authorization was " + status);82 checkState();83 }, handleError);84 });85 // iOS settings86 var onLocationRequestChange = function(status){87 log("Successfully requested location authorization: authorization was " + status);88 checkState();89 };90 $('#request-location-always').on("click", function(){91 cordova.plugins.diagnostic.requestLocationAuthorization(onLocationRequestChange, handleError, cordova.plugins.diagnostic.locationAuthorizationMode.ALWAYS);92 });93 $('#request-location-in-use').on("click", function(){94 cordova.plugins.diagnostic.requestLocationAuthorization(onLocationRequestChange, handleError, cordova.plugins.diagnostic.locationAuthorizationMode.WHEN_IN_USE);95 });96 $('#request-camera-roll').on("click", function(){97 cordova.plugins.diagnostic.requestCameraRollAuthorization(function(status){98 log("Successfully requested camera roll authorization: authorization was " + status);99 checkState();100 }, handleError);101 });102 $('#request-reminders').on("click", function(){103 cordova.plugins.diagnostic.requestRemindersAuthorization(function(status){104 log("Successfully requested reminders authorization: authorization was " + status);105 checkState();106 }, handleError);107 });108 $('#request-bluetooth').on("click", function(){109 cordova.plugins.diagnostic.requestBluetoothAuthorization(function(){110 log("Successfully requested Bluetooth authorization");111 if(!monitoringBluetooth) registerBluetoothStateChangeHandler();112 checkState();113 }, handleError);114 });115 $('#monitor-bluetooth').on("click", function(){116 registerBluetoothStateChangeHandler();117 $('#monitor-bluetooth').remove();118 });119 $('#request-motion').on("click", function(){120 cordova.plugins.diagnostic.requestMotionAuthorization(handleMotionAuthorizationStatus, handleError);121 });122 // Android settings123 $('#warm-restart').on("click", function(){124 cordova.plugins.diagnostic.restart(handleError, false);125 });126 $('#cold-restart').on("click", function(){127 cordova.plugins.diagnostic.restart(handleError, true);128 });129 $('#request-location').on("click", function(){130 cordova.plugins.diagnostic.requestLocationAuthorization(function(status){131 log("Successfully requested location authorization: authorization was " + status);132 }, handleError);133 });134 $('#location-settings').on("click", function(){135 cordova.plugins.diagnostic.switchToLocationSettings();136 });137 $('#mobile-data-settings').on("click", function(){138 cordova.plugins.diagnostic.switchToMobileDataSettings();139 });140 $('#bluetooth-settings').on("click", function(){141 cordova.plugins.diagnostic.switchToBluetoothSettings();142 });143 $('#wifi-settings').on("click", function(){144 cordova.plugins.diagnostic.switchToWifiSettings();145 });146 $('#wireless-settings').on("click", function(){147 cordova.plugins.diagnostic.switchToWirelessSettings();148 });149 $('#nfc-settings').on("click", function(){150 cordova.plugins.diagnostic.switchToNFCSettings();151 });152 // Android set state153 $('#enable-wifi').on("click", function(){154 cordova.plugins.diagnostic.setWifiState(function(){155 log("Successfully enabled Wifi");156 setTimeout(checkState, 100);157 }, handleError, true);158 });159 $('#disable-wifi').on("click", function(){160 cordova.plugins.diagnostic.setWifiState(function(){161 log("Successfully disabled Wifi");162 setTimeout(checkState, 100);163 }, handleError, false);164 });165 $('#enable-bluetooth').on("click", function(){166 cordova.plugins.diagnostic.setBluetoothState(function(){167 log("Successfully enabled Bluetooth");168 setTimeout(checkState, 1000);169 }, handleError, true);170 });171 $('#disable-bluetooth').on("click", function(){172 cordova.plugins.diagnostic.setBluetoothState(function(){173 log("Successfully disabled Bluetooth");174 setTimeout(checkState, 1000);175 }, handleError, false);176 });177 $('#get-location').on("click", function(){178 var posOptions = { timeout: 35000, enableHighAccuracy: true, maximumAge: 5000 };179 navigator.geolocation.getCurrentPosition(function(position) {180 var lat = position.coords.latitude;181 var lon = position.coords.longitude;182 log("Current position: "+lat+","+lon, true);183 }, function (err) {184 handleError("Position error: code="+ err.code + "; message=" + err.message);185 }, posOptions);186 });187 $('#use-camera').on("click", function(){188 navigator.camera.getPicture(function(){189 log("Successfully took a photo", true);190 }, function(err){191 handleError("Camera error: "+ err);192 }, {193 saveToPhotoAlbum: false,194 destinationType: Camera.DestinationType.DATA_URL195 });196 });197 $('#request-remote-notifications button').on("click", function(){198 var types = [];199 $("#request-remote-notifications select :selected").each(function(){200 types.push($(this).val());201 });202 cordova.plugins.diagnostic.requestRemoteNotificationsAuthorization({203 successCallback: function(result){204 log("Successfully requested remote notifications authorization: " + result);205 checkState();206 },207 errorCallback: handleError,208 types: types,209 omitRegistration: false210 });211 });212 $('#request-external-sd-permission').on("click", function(){213 cordova.plugins.diagnostic.requestExternalStorageAuthorization(function(status){214 log("Successfully requested external storage authorization: authorization was " + status);215 checkState();216 }, handleError);217 });218 $('#request-external-sd-details').on("click", function(){219 cordova.plugins.diagnostic.getExternalSdCardDetails(function(details){220 log("Successfully retrieved external SD card details");221 var $results = $('#request-external-sd-details-results');222 $results.show().empty();223 if(details.length > 0){224 details.forEach(function(detail){225 $results.append('<p>Path: '+detail.path+226 '<br/>Writable?: '+detail.canWrite+227 '<br/>Free space: '+detail.freeSpace+228 '<br/>Type: '+detail.type+229 '</p>');230 if(detail.canWrite){231 $('#write-external-sd-file').css('display', 'block');232 cordova.file.externalSdCardDirectory = detail.filePath;233 }234 });235 window.scrollTo(0,document.body.scrollHeight)236 }else{237 alert("No external storage found");238 }239 }, handleError);240 });241 $('#write-external-sd-file').on("click", function(){242 var targetDir = cordova.file.externalSdCardDirectory;243 var filename = "test.txt";244 var targetFilepath = targetDir + "/" + filename;245 var fail = function(error) {246 var msg = 'Failed to write file \'' + targetFilepath + '\'. Error code: ' + error.code;247 handleError(msg);248 };249 window.resolveLocalFileSystemURL(targetDir, function (dirEntry) {250 dirEntry.getFile(filename, {251 create: true,252 exclusive: false253 }, function (fileEntry) {254 fileEntry.createWriter(function (writer) {255 writer.onwriteend = function (evt) {256 log("Wrote "+targetFilepath, true);257 };258 writer.write("Hello world");259 }, fail);260 }, fail);261 }, fail);262 });263 if(platform === "ios") {264 // Setup background refresh request265 var Fetcher = window.BackgroundFetch;266 var fetchCallback = function() {267 log('BackgroundFetch initiated');268 $.get({269 url: 'index.html',270 callback: function(response) {271 log("BackgroundFetch successful");272 Fetcher.finish();273 }274 });275 };276 var failureCallback = function() {277 handleError('- BackgroundFetch failed');278 };279 Fetcher.configure(fetchCallback, failureCallback, {280 stopOnTerminate: true281 });282 }283 setTimeout(checkState, 500);284}285function checkState(){286 log("Checking state...");287 $('#state li').removeClass('on off');288 // Location289 var onGetLocationAuthorizationStatus;290 cordova.plugins.diagnostic.isLocationAvailable(function(available){291 $('#state .location').addClass(available ? 'on' : 'off');292 }, handleError);293 if(platform === "android" || platform === "ios") {294 cordova.plugins.diagnostic.isLocationEnabled(function (enabled) {295 $('#state .location-setting').addClass(enabled ? 'on' : 'off');296 }, handleError);297 cordova.plugins.diagnostic.isLocationAuthorized(function(enabled){298 $('#state .location-authorization').addClass(enabled ? 'on' : 'off');299 }, handleError);300 cordova.plugins.diagnostic.getLocationAuthorizationStatus(function(status){301 $('#state .location-authorization-status').find('.value').text(status.toUpperCase());302 onGetLocationAuthorizationStatus(status); // platform-specific303 }, handleError);304 }305 if(platform === "ios"){306 onGetLocationAuthorizationStatus = function(status){307 $('.request-location').toggle(status === cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED);308 }309 }310 if(platform === "android"){311 cordova.plugins.diagnostic.isGpsLocationAvailable(function(available){312 $('#state .gps-location').addClass(available ? 'on' : 'off');313 }, handleError);314 cordova.plugins.diagnostic.isNetworkLocationAvailable(function(available){315 $('#state .network-location').addClass(available ? 'on' : 'off');316 }, handleError);317 cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){318 $('#state .gps-location-setting').addClass(enabled ? 'on' : 'off');319 }, handleError);320 cordova.plugins.diagnostic.isNetworkLocationEnabled(function(enabled){321 $('#state .network-location-setting').addClass(enabled ? 'on' : 'off');322 }, handleError);323 cordova.plugins.diagnostic.getLocationMode(function(mode){324 $('#state .location-mode').find('.value').text(mode.toUpperCase());325 }, handleError);326 onGetLocationAuthorizationStatus = function(status){327 $('#request-location').toggle(status != cordova.plugins.diagnostic.permissionStatus.GRANTED && status != cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS);328 };329 cordova.plugins.diagnostic.hasBluetoothSupport(function(supported){330 $('#state .bluetooth-support').addClass(supported ? 'on' : 'off');331 }, handleError);332 cordova.plugins.diagnostic.hasBluetoothLESupport(function(supported){333 $('#state .bluetooth-le-support').addClass(supported ? 'on' : 'off');334 }, handleError);335 cordova.plugins.diagnostic.hasBluetoothLEPeripheralSupport(function(supported){336 $('#state .bluetooth-le-peripheral-support').addClass(supported ? 'on' : 'off');337 }, handleError);338 // NFC339 cordova.plugins.diagnostic.isNFCPresent(function (present) {340 $('#state .nfc-present').addClass(present ? 'on' : 'off');341 if(!present){342 $('#nfc-settings')343 .attr('disabled', 'disabled')344 .addClass('disabled');345 }346 }, handleError);347 cordova.plugins.diagnostic.isNFCEnabled(function (enabled) {348 $('#state .nfc-enabled').addClass(enabled ? 'on' : 'off');349 }, handleError);350 cordova.plugins.diagnostic.isNFCAvailable(function (available) {351 $('#state .nfc-available').addClass(available ? 'on' : 'off');352 }, handleError);353 }354 // Camera355 var onGetCameraAuthorizationStatus;356 cordova.plugins.diagnostic.isCameraAvailable({357 successCallback: function(available){358 $('#state .camera').addClass(available ? 'on' : 'off');359 },360 errorCallback: handleError,361 externalStorage: true362 });363 if(platform === "android" || platform === "ios") {364 cordova.plugins.diagnostic.isCameraPresent(function (present) {365 $('#state .camera-present').addClass(present ? 'on' : 'off');366 }, handleError);367 cordova.plugins.diagnostic.isCameraAuthorized({368 successCallback: function (authorized) {369 $('#state .camera-authorized').addClass(authorized ? 'on' : 'off');370 },371 errorCallback: handleError,372 externalStorage: true373 });374 cordova.plugins.diagnostic.getCameraAuthorizationStatus({375 successCallback: function (status) {376 $('#state .camera-authorization-status').find('.value').text(status.toUpperCase());377 onGetCameraAuthorizationStatus(status);378 },379 errorCallback: handleError,380 externalStorage: true381 });382 }383 if(platform === "ios"){384 cordova.plugins.diagnostic.isCameraRollAuthorized(function(authorized){385 $('#state .camera-roll-authorized').addClass(authorized ? 'on' : 'off');386 }, handleError);387 cordova.plugins.diagnostic.getCameraRollAuthorizationStatus(function(status){388 $('#state .camera-roll-authorization-status').find('.value').text(status.toUpperCase());389 $('#request-camera-roll').toggle(status === cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED);390 }, handleError);391 onGetCameraAuthorizationStatus = function(status){392 $('#request-camera').toggle(status === cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED);393 }394 }395 if(platform === "android"){396 onGetCameraAuthorizationStatus = function(status){397 $('#request-camera').toggle(status != cordova.plugins.diagnostic.permissionStatus.GRANTED && status != cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS);398 }399 }400 // Network401 cordova.plugins.diagnostic.isWifiAvailable(function(available){402 $('#state .wifi').addClass(available ? 'on' : 'off');403 if(platform === "android" || platform === "windows") {404 $('#enable-wifi').toggle(!available);405 $('#disable-wifi').toggle(!!available);406 }407 }, handleError);408 cordova.plugins.diagnostic.isWifiEnabled(function(available){409 $('#state .wifi-setting').addClass(available ? 'on' : 'off');410 }, handleError);411 if(platform === "android"){412 cordova.plugins.diagnostic.isDataRoamingEnabled(function(enabled){413 $('#state .data-roaming').addClass(enabled ? 'on' : 'off');414 }, handleError);415 }416 // Bluetooth417 if(monitoringBluetooth) {418 cordova.plugins.diagnostic.isBluetoothAvailable(function (available) {419 $('#state .bluetooth-available').addClass(available ? 'on' : 'off');420 if (platform === "android" || platform === "windows") {421 $('#enable-bluetooth').toggle(!available);422 $('#disable-bluetooth').toggle(!!available);423 }424 }, handleError);425 if (platform === "android") {426 cordova.plugins.diagnostic.isBluetoothEnabled(function (enabled) {427 $('#state .bluetooth-setting').addClass(enabled ? 'on' : 'off');428 }, handleError);429 }430 if (platform === "android" || platform === "ios") {431 cordova.plugins.diagnostic.getBluetoothState(function (state) {432 $('#state .bluetooth-state').find('.value').text(state.toUpperCase());433 $('#request-bluetooth, #monitor-bluetooth').toggle(state === cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS);434 }, handleError);435 }436 }437 // Microphone438 var onGetMicrophoneAuthorizationStatus;439 if(platform === "android" || platform === "ios") {440 cordova.plugins.diagnostic.isMicrophoneAuthorized(function (enabled) {441 $('#state .microphone-authorized').addClass(enabled ? 'on' : 'off');442 }, handleError);443 cordova.plugins.diagnostic.getMicrophoneAuthorizationStatus(function (status) {444 $('#state .microphone-authorization-status').find('.value').text(status.toUpperCase());445 onGetMicrophoneAuthorizationStatus(status);446 }, handleError);447 }448 if(platform === "ios"){449 onGetMicrophoneAuthorizationStatus = function(status){450 $('#request-microphone').toggle(status === cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED);451 }452 }453 if(platform === "android"){454 onGetMicrophoneAuthorizationStatus = function(status){455 $('#request-microphone').toggle(status != cordova.plugins.diagnostic.permissionStatus.GRANTED && status != cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS);456 }457 }458 // Contacts459 var onGetContactsAuthorizationStatus;460 if(platform === "android" || platform === "ios") {461 cordova.plugins.diagnostic.isContactsAuthorized(function (enabled) {462 $('#state .contacts-authorized').addClass(enabled ? 'on' : 'off');463 }, handleError);464 cordova.plugins.diagnostic.getContactsAuthorizationStatus(function (status) {465 $('#state .contacts-authorization-status').find('.value').text(status.toUpperCase());466 onGetContactsAuthorizationStatus(status);467 }, handleError);468 }469 if(platform === "ios"){470 onGetContactsAuthorizationStatus = function(status){471 $('#request-contacts').toggle(status === cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED);472 }473 }474 if(platform === "android"){475 onGetContactsAuthorizationStatus = function(status){476 $('#request-contacts').toggle(status != cordova.plugins.diagnostic.permissionStatus.GRANTED && status != cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS);477 }478 }479 // Calendar480 var onGetCalendarAuthorizationStatus;481 if(platform === "android" || platform === "ios") {482 cordova.plugins.diagnostic.isCalendarAuthorized(function (enabled) {483 $('#state .calendar-authorized').addClass(enabled ? 'on' : 'off');484 }, handleError);485 cordova.plugins.diagnostic.getCalendarAuthorizationStatus(function (status) {486 $('#state .calendar-authorization-status').find('.value').text(status.toUpperCase());487 onGetCalendarAuthorizationStatus(status);488 }, handleError);489 }490 if(platform === "ios"){491 onGetCalendarAuthorizationStatus = function(status){492 $('#request-calendar').toggle(status === cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED);493 }494 }495 if(platform === "android"){496 onGetCalendarAuthorizationStatus = function(status){497 $('#request-calendar').toggle(status != cordova.plugins.diagnostic.permissionStatus.GRANTED && status != cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS);498 }499 }500 if(platform === "ios" || platform === "android") {501 // Remote notifications502 cordova.plugins.diagnostic.isRemoteNotificationsEnabled(function (enabled) {503 $('#state .remote-notifications-enabled').addClass(enabled ? 'on' : 'off');504 }, handleError);505 }506 if(platform === "ios") {507 // Reminders508 cordova.plugins.diagnostic.isRemindersAuthorized(function (enabled) {509 $('#state .reminders-authorized').addClass(enabled ? 'on' : 'off');510 }, handleError);511 cordova.plugins.diagnostic.getRemindersAuthorizationStatus(function (status) {512 $('#state .reminders-authorization-status').find('.value').text(status.toUpperCase());513 $('#request-reminders').toggle(status === cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED);514 }, handleError);515 // Background refresh516 cordova.plugins.diagnostic.isBackgroundRefreshAuthorized(function (enabled) {517 $('#state .background-refresh-authorized').addClass(enabled ? 'on' : 'off');518 }, handleError);519 cordova.plugins.diagnostic.getBackgroundRefreshStatus(function (status) {520 $('#state .background-refresh-authorization-status').find('.value').text(status.toUpperCase());521 }, handleError);522 // Remote notifications523 var $remoteNotificationsAuthorizationStatusValue = $('#state .remote-notifications-authorization-status').find('.value');524 if(osVersion >= 10){525 cordova.plugins.diagnostic.getRemoteNotificationsAuthorizationStatus(function (status) {526 $remoteNotificationsAuthorizationStatusValue.text(status.toUpperCase());527 $('#request-remote-notifications').toggle(status === cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED);528 }, handleError);529 }else{530 $remoteNotificationsAuthorizationStatusValue.text("UNAVAILABLE");531 }532 cordova.plugins.diagnostic.isRegisteredForRemoteNotifications(function (enabled) {533 $('#state .remote-notifications-registered').addClass(enabled ? 'on' : 'off');534 }, handleError);535 cordova.plugins.diagnostic.getRemoteNotificationTypes(function (types) {536 var value = "";537 for (var type in types){538 value += type + "=" + (types[type] ? "Y" : "N") +"; ";539 }540 $('#state .remote-notifications-types').find('.value').text(value);541 }, handleError);542 // Motion543 cordova.plugins.diagnostic.isMotionAvailable(function (available) {544 $('#state .motion-available').addClass(available ? 'on' : 'off');545 if(!available){546 $('#request-motion')547 .attr('disabled', 'disabled')548 .addClass('disabled');549 }550 }, handleError);551 cordova.plugins.diagnostic.isMotionRequestOutcomeAvailable(function (available) {552 $('#state .motion-request-outcome-available').addClass(available ? 'on' : 'off');553 }, handleError);554 cordova.plugins.diagnostic.getMotionAuthorizationStatus(handleMotionAuthorizationStatus, handleError);555 }556 // External SD card557 if(platform === "android"){558 cordova.plugins.diagnostic.isExternalStorageAuthorized(function (enabled) {559 $('#state .external-sd-authorized').addClass(enabled ? 'on' : 'off');560 }, handleError);561 cordova.plugins.diagnostic.getExternalStorageAuthorizationStatus(function (status) {562 $('#state .external-sd-authorization-status').find('.value').text(status.toUpperCase());563 $('#request-external-sd-permission').toggle(status === cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED);564 $('#request-external-sd-details').toggle(status === cordova.plugins.diagnostic.permissionStatus.GRANTED);565 }, handleError);566 }567 //Misc568 if(platform === "android"){569 cordova.plugins.diagnostic.isADBModeEnabled(function(enabled){570 $('#state .adb').addClass(enabled ? 'on' : 'off');571 }, handleError);572 cordova.plugins.diagnostic.isDeviceRooted(function(enabled){573 $('#state .root').addClass(enabled ? 'on' : 'off');574 }, handleError);575 }576 if(platform === "android" || platform === "ios"){577 cordova.plugins.diagnostic.getArchitecture(function (arch) {578 $('#state .cpu-architecture').find('.value').text(arch.toUpperCase());579 });580 }581}582function handleError(error){583 var msg = "Error: "+error;584 console.error(msg);585 alert(msg);586}587function log(msg, showAlert){588 console.log(msg);589 if(showAlert){590 alert(msg);591 }592}593function onResume(){594 checkState();595}596function handleMotionAuthorizationStatus(status) {597 $('#state .motion-authorization-status').find('.value').text(status.toUpperCase());598 if(status === cordova.plugins.diagnostic.motionStatus.NOT_REQUESTED){599 $('#request-motion')600 .removeAttr('disabled')601 .removeClass('disabled');602 }else{603 $('#request-motion')604 .attr('disabled', 'disabled')605 .addClass('disabled');606 }607}608function registerBluetoothStateChangeHandler(){609 cordova.plugins.diagnostic.registerBluetoothStateChangeHandler(function (state) {610 log("Bluetooth state changed to: " + state);611 checkState();612 }, function (error) {613 handleError("Error registering for Bluetooth state changes: " + error);614 });615 monitoringBluetooth = true;616}...

Full Screen

Full Screen

59_drop_indexes.js

Source:59_drop_indexes.js Github

copy

Full Screen

...9 * @private10 * @param {Error} error Error or null11 * @returns {undefined}12 */13function handleError(error) {14 // This may fail if the index or the collection doesn't exist, which is what we want anyway15 if (16 error &&17 (18 typeof error.message !== "string" ||19 (!error.message.includes("index not found") && !error.message.includes("ns not found"))20 )21 ) {22 Logger.warn(error, "Caught error from dropIndex calls in migration 59");23 }24}25/**26 * Drop all indexes that support queries that are no longer expected27 * to be made by any plugins, or that are already supported by other...

Full Screen

Full Screen

api.js

Source:api.js Github

copy

Full Screen

1import { GET, POST } from '@utils/fetch'2export const createSku = action => (3 POST({4 api: '/Api/createSku',5 apiBase: 'catalog',6 data: action.data,7 handleError: true8 })9)10export const createGenre = action => (11 POST({12 api: '/Api/createGenre',13 apiBase: 'catalog',14 data: action.data,15 handleError: true16 })17)18export const createCollection = action => (19 POST({20 api: '/Api/catalog/collection/create',21 apiBase: 'catalog',22 data: action.data,23 handleError: true24 })25)26export const updateCollection = action => (27 POST({28 api: '/Api/catalog/collection/uppdate',29 apiBase: 'catalog',30 data: action.data,31 handleError: true32 })33)34export const updateGenre = action => (35 POST({36 api: '/Api/updateGenre',37 apiBase: 'catalog',38 data: action.data,39 handleError: true40 })41)42export const fetchSKUs = action => (43 POST({44 api: '/Api/listSku',45 apiBase: 'catalog',46 data: action.data,47 handleError: true48 })49)50export const fetchCollection = action => (51 POST({52 api: '/Api/catalog/collection/list',53 apiBase: 'catalog',54 data: action.data,55 handleError: true56 })57)58export const updateSKU = action => (59 POST({60 api: '/Api/updateSku',61 apiBase: 'catalog',62 data: action.data,63 handleError: true64 })65) 66export const updateSKUStatus = action => (67 POST({68 api: '/Api/changeSkuStatus',69 apiBase: 'catalog',70 data: action.data,71 handleError: true72 })73) 74export const fetchStates = action => (75 POST({76 api: '/Api/listStates',77 apiBase: 'retailer',78 data: action.data,79 handleError: true80 })81) 82export const fetchGenres = action => (83 POST({84 api: '/Api/listGenre',85 apiBase: 'catalog',86 data: action.data,87 handleError: true88 })89) 90export const fetchGenreList = action => (91 POST({92 api: '/Api/getGenreMap',93 apiBase: 'catalog',94 data: action.data,95 handleError: true96 })97) 98export const createOrUpdateBrandListingOrder = action => (99 POST({100 api: '/Api/createorupdateListingOrder',101 apiBase: 'catalog',102 data: action.data,103 handleError: true104 })105) 106export const fetchBrandListingOrder = action => (107 POST({108 api: '/Api/listListingOrderforGenreandState',109 apiBase: 'catalog',110 data: action.data,111 handleError: true112 })113)114export const updateGenreStatus = action => (115 POST({116 api: '/Api/changeGenreStatus',117 apiBase: 'catalog',118 data: action.data,119 handleError: true120 })121)122export const updateCollectionStatus = action => (123 POST({124 api: '/Api/catalog/collection/activate',125 apiBase: 'catalog',126 data: action.data,127 handleError: true128 })129)130export const fetchSkuMappedStates = action => (131 POST({132 api: '/Api/listSkuPrice',133 apiBase: 'catalog',134 data: action.data,135 handleError: true136 })137) 138export const mapStateToSku = action => (139 POST({140 api: '/Api/createSkuPrice',141 apiBase: 'catalog',142 data: action.data,143 handleError: true144 })145) 146export const updateSkuStateMap = action => (147 POST({148 api: '/Api/updateSkuPrice',149 apiBase: 'catalog',150 data: action.data,151 handleError: true152 })153) 154// export const fetchCollectionList = action => (155// POST({156// api: '/Api/catalog/collection/list',157// apiBase: 'catalog',158// data: action.data,159// handleError: true160// })161// )162export const fetchBrandCollection = action => (163 POST({164 api: '/Api/catalog/brand-collection/list',165 apiBase: 'catalog',166 data: action.data,167 handleError: true168 })169)170export const updateBrandCollectionStatus = action => (171 POST({172 api: '/Api/catalog/brand-collection/activate',173 apiBase: 'catalog',174 data: action.data,175 handleError: true176 })177)178export const createBrandCollection = action => (179 POST({180 api: '/Api/catalog/brand-collection/create',181 apiBase: 'catalog',182 data: action.data,183 handleError: true184 })185) 186export const editBrandCollection = action => (187 POST({188 api: '/Api/catalog/brand-collection/update',189 apiBase: 'catalog',190 data: action.data,191 handleError: true192 })193)194export const fetchBrands = action => (195 POST({196 api: '/Api/listBrandDetails',197 apiBase: 'catalog',198 data: action.data,199 handleError: true200 })201 .then(json => json)202)203export const fetchAccessLogs = action => (204 POST({205 api: '/Api/catalog/accesslog',206 apiBase: 'catalog',207 data: action.data,208 handleError: true209 })210 .then(json => json)211)212export const fetchGenreBasedBrandList = action => (213 POST({214 api: '/Api/getBrandforGenre',215 apiBase: 'catalog',216 data: action.data,217 handleError: true218 })219)220export const createBrand = action => (221 POST({222 api: '/Api/createBrand',223 apiBase: 'catalog',224 data: action.data,225 handleError: true226 })227 .then(json => json)228) 229export const updateBrand = action => (230 POST({231 api: '/Api/updateBrand',232 apiBase: 'catalog',233 data: action.data,234 handleError: true235 })236 .then(json => json)237)238export const updateBrandStatus = action => (239 POST({240 api: '/Api/changeBrandStatus',241 apiBase: 'catalog',242 data: action.data,243 handleError: true244 })245 .then(json => json)246)247export const fetchBrandTypes = action => (248 POST({249 api: '/Api/listBrandType',250 apiBase: 'catalog',251 data: action.data,252 handleError: true253 })...

Full Screen

Full Screen

handleResponse.spec.js

Source:handleResponse.spec.js Github

copy

Full Screen

1import handleResponse from './handleResponse';2import CODES from 'http-status-codes';3jest.mock('./handleError', () => jest.fn());4jest.mock('./parseResponse', () => jest.fn());5beforeEach(jest.clearAllMocks);6describe('handleResponse', () => {7 it('sends empty responses to handleError', () => {8 const handleError = require('./handleError');9 handleResponse();10 expect(handleError).toHaveBeenCalled();11 });12 it('sends responses with statuses higher than 400 to handleError', () => {13 const handleError = require('./handleError');14 handleResponse({ status: 400 });15 expect(handleError).toHaveBeenCalled();16 handleError.mockClear();17 handleResponse({ status: 401 });18 expect(handleError).toHaveBeenCalled();19 handleError.mockClear();20 handleResponse({ status: 200 });21 expect(handleError).not.toHaveBeenCalled();22 handleError.mockClear();23 handleResponse({ status: 403 });24 expect(handleError).toHaveBeenCalled();25 handleError.mockClear();26 handleResponse({ status: 500 });27 expect(handleError).toHaveBeenCalled();28 handleError.mockClear();29 });30 it('sends valid responses to parseResponse', () => {31 const parseResponse = require('./parseResponse');32 handleResponse({ status: 200 });33 expect(parseResponse).toHaveBeenCalled();34 parseResponse.mockClear();35 handleResponse({ status: 500 });36 expect(parseResponse).not.toHaveBeenCalled();37 parseResponse.mockClear();38 });39 it('doesnt try to parse the response in case of a no-content status', () => {40 const parseResponse = require('./parseResponse');41 const emptyResponse = {42 status: CODES.NO_CONTENT43 };44 handleResponse(emptyResponse);45 expect(parseResponse).not.toHaveBeenCalled();46 });...

Full Screen

Full Screen

rest.js

Source:rest.js Github

copy

Full Screen

...16 Dialog.alert(encoded);17 18 return [e, data];19};20module.exports.delete = handleError(IO.delete);21module.exports.patch = handleError(IO.patch);22module.exports.write = handleError(IO.write);23module.exports.createDirectory = handleError(IO.createDirectory);24module.exports.read = handleError(IO.read);25module.exports.copy = handleError(IO.copy);26module.exports.pack = handleError(IO.pack);27module.exports.extract = handleError(IO.extract);28module.exports.move = handleError(IO.move);29module.exports.rename = handleError(IO.rename);30module.exports.Config = {31 read: handleError(IO.Config.read),32 write: handleError(IO.Config.write),33};34module.exports.Markdown = {35 read: handleError(IO.Markdown.read),36 render: handleError(IO.Markdown.render),...

Full Screen

Full Screen

user.js

Source:user.js Github

copy

Full Screen

1import axios from 'utils/http';2import { handleError } from './error';3export async function loginUserApi(data) {4 return axios.post('/users/login/', data).catch(handleError);5}6export async function forgotPasswordApi(data) {7 return axios.post('/users/forgot-password', data).catch(handleError);8}9export async function resetPasswordApi(data) {10 return axios.post('/users/reset-password', data).catch(handleError);11}12export async function signupUserApi(data) {13 return axios.post('/users/', data).catch(handleError);14}15export async function confirmEmailApi(token) {16 return axios.get(`/users/confirm/${token}`).catch(handleError);17}18export async function updateUserAccountApi(id, data) {19 return axios.put(`/restricted/users/${id}`, data).catch(handleError);20}21export async function fetchUserAccountApi(id) {22 return axios.get(`/restricted/users/${id}`).catch(handleError);23}24export async function reloginApi() {25 return axios.get('/restricted/tokens').catch(handleError);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestError = require('./BestError');2var error = new bestError();3error.handleError('test4.js');4var bestError = require('./BestError');5var error = new bestError();6error.handleError('test5.js');7var bestError = require('./BestError');8var error = new bestError();9error.handleError('test6.js');10var bestError = require('./BestError');11var error = new bestError();12error.handleError('test7.js');13var bestError = require('./BestError');14var error = new bestError();15error.handleError('test8.js');16var bestError = require('./BestError');17var error = new bestError();18error.handleError('test9.js');19var bestError = require('./BestError');20var error = new bestError();21error.handleError('test10.js');22var bestError = require('./BestError');23var error = new bestError();24error.handleError('test11.js');25var bestError = require('./BestError');26var error = new bestError();27error.handleError('test12.js');28var bestError = require('./BestError');29var error = new bestError();30error.handleError('test13.js');31var bestError = require('./BestError');32var error = new bestError();33error.handleError('test14.js');34var bestError = require('./BestError');35var error = new bestError();36error.handleError('test15.js');37var bestError = require('./BestError');38var error = new bestError();

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestError = require('./besterror');2var be = new BestError('Something went wrong');3be.handleError();4var BestError = require('./besterror');5var be = new BestError('Something went wrong');6be.handleError();7var BestError = require('./besterror');8var be = new BestError('Something went wrong');9be.handleError();10var BestError = require('./besterror');11var be = new BestError('Something went wrong');12be.handleError();13var BestError = require('./besterror');14var be = new BestError('Something went wrong');15be.handleError();16var BestError = require('./besterror');17var be = new BestError('Something went wrong');18be.handleError();19var BestError = require('./besterror');20var be = new BestError('Something went wrong');21be.handleError();22var BestError = require('./besterror');23var be = new BestError('Something went wrong');24be.handleError();25var BestError = require('./besterror');26var be = new BestError('Something went wrong');27be.handleError();28be.handleError();29be.handleError();30be.handleError();31be.handleError();32be.handleError();33be.handleError();

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestError = require('./BestError');2var be = new BestError('Test Error');3be.handleError();4var util = require('util');5var Error = require('Error');6function BestError(message) {7 Error.call(this);8 Error.captureStackTrace(this, arguments.callee);9 this.message = message;10 this.name = 'BestError';11}12util.inherits(BestError, Error);13BestError.prototype.handleError = function() {14 console.log('Error name: ' + this.name);15 console.log('Error message: ' + this.message);16}17module.exports = BestError;18at BestError.handleError (BestError.js:13:9)19at Object.<anonymous> (test4.js:5:6)20at Module._compile (module.js:456:26)21at Object.Module._extensions..js (module.js:474:10)22at Module.load (module.js:356:32)23at Function.Module._load (module.js:312:12)24at Function.Module.runMain (module.js:497:10)25at startup (node.js:119:16)

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestError = require('./BestError');2var be = new BestError();3be.handleError(new Error('Error message'));4var BestError = require('./BestError');5var be = new BestError();6be.handleError(new Error('Error message'));

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestError = require("./BestError");2const error = new BestError("My Error Message");3error.handleError();4class BestError {5 constructor(message) {6 this.message = message;7 }8 handleError() {9 console.log(this.message);10 }11}12module.exports = BestError;13const BestError = require("./BestError");14const error = new BestError("My Error Message");15error.handleError();16class BestError {17 constructor(message) {18 this.message = message;19 }20 handleError() {21 console.log(this.message);22 }23}24module.exports = BestError;25const BestError = require("./BestError");26const error = new BestError("My Error Message");27error.handleError();28class BestError {29 constructor(message) {30 this.message = message;31 }32 handleError() {33 console.log(this.message);34 }35}36module.exports = BestError;37const BestError = require("./BestError");38const error = new BestError("My Error Message");39error.handleError();40class BestError {41 constructor(message) {42 this.message = message;43 }44 handleError() {45 console.log(this.message);46 }47}48module.exports = BestError;49const BestError = require("./BestError");50const error = new BestError("My Error Message");51error.handleError();52class BestError {53 constructor(message) {54 this.message = message;55 }56 handleError() {57 console.log(this.message);58 }59}60module.exports = BestError;61const BestError = require("./BestError");62const error = new BestError("My Error Message");63error.handleError();

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestError = require('./best-error');2const err = new BestError('My Error Message');3err.handleError();4const util = require('util');5function BestError(message){6 Error.captureStackTrace(this, BestError);7 this.message = message;8}9util.inherits(BestError, Error);10BestError.prototype.name = 'BestError';11BestError.prototype.handleError = function(){12 console.log('Error: ' + this.message);13 console.log('Stack: ' + this.stack);14}15module.exports = BestError;16const BestError = require('./best-error');17const err = new BestError('My Error Message');18err.handleError();19const util = require('util');20function BestError(message){21 Error.captureStackTrace(this, BestError);22 this.message = message;23}24util.inherits(BestError, Error);25BestError.prototype.name = 'BestError';26BestError.prototype.handleError = function(){27 console.log('Error: ' + this.message);28 console.log('Stack: ' + this.stack);29}30module.exports = BestError;31const BestError = require('./best-error');32const err = new BestError('My Error Message');33err.handleError();34const util = require('util');35function BestError(message){36 Error.captureStackTrace(this, BestError);37 this.message = message;38}39util.inherits(BestError, Error);40BestError.prototype.name = 'BestError';41BestError.prototype.handleError = function(){42 console.log('Error: ' + this.message);43 console.log('Stack: ' + this.stack);44}45module.exports = BestError;46const BestError = require('./best-error');47const err = new BestError('My Error Message');48err.handleError();49const util = require('util');50function BestError(message){51 Error.captureStackTrace(this, BestError);52 this.message = message;53}54util.inherits(BestError, Error);55BestError.prototype.name = 'BestError';

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestError = require('best-error');2let bestError = new BestError({});3let err = new Error('This is an error');4let err2 = new Error('This is an error 2');5let err3 = new Error('This is an error 3');6bestError.handleError(err);7bestError.handleError(err2);8bestError.handleError(err3);9bestError.printErrors();10const BestError = require('best-error');11let bestError = new BestError({});12let err = new Error('This is an error');13let err2 = new Error('This is an error 2');14let err3 = new Error('This is an error 3');15bestError.handleError(err);16bestError.handleError(err2);17bestError.handleError(err3);18bestError.printErrors();19const BestError = require('best-error');20let bestError = new BestError({});21let err = new Error('This is an error');22let err2 = new Error('This is an error 2');23let err3 = new Error('This is an error 3');24bestError.handleError(err);25bestError.handleError(err2);26bestError.handleError(err3);27bestError.printErrors();28const BestError = require('best-error');29let bestError = new BestError({});30let err = new Error('This is an error');31let err2 = new Error('This is an error 2');32let err3 = new Error('This is an error 3');33bestError.handleError(err);34bestError.handleError(err2);35bestError.handleError(err3);36bestError.printErrorsInConsole();

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