Best JavaScript code snippet using storybook-root
builder.controller.js
Source:builder.controller.js
1'use strict';2var User = require('./../../../models/user.model');3var Team = require('./../../../models/team.model');4var Project = require('./../../../models/project.model');5var BuilderPackage = require('./../../../models/builderPackage.model');6var BuilderPackageNewVersion = require('./../../../models/builderPackageNew.model');7var errorsHelper = require('./../../../components/helpers/errors');8var ProjectValidator = require('./../../../validators/project');9var _ = require('lodash');10var async = require('async');11var EventBus = require('./../../../components/EventBus');12var mongoose = require('mongoose');13exports.project = function(req, res, next) {14 Project.findById(req.params.id,function(err,project) {15 if (err) {16 return res.send(500,{msg: 'Missing project.'})17 }18 if (!project) {19 return res.send(404,err);20 }21 req.project = project;22 next();23 })24};25exports.getDefaultPackageByProject = function(req, res) {26 var user = req.user;27 var project = req.project;28 BuilderPackageNewVersion.findOne({29 project: mongoose.Types.ObjectId(project._id)30 })31 .populate('project')32 .populate('owner', '-hashedPassword -salt')33 .populate('to.team')34 .populate('variations')35 .populate('messages.sendBy')36 .populate('winner')37 .populate('architect.team')38 .populate('invitees.quoteDocument', '_id mimeType title')39 .populate('projectManager._id', '-hashedPassword -salt')40 .exec(function(err, builderPackage) {41 if (err){return res.send(500, err); }42 User.populate(builderPackage,[43 {path : 'owner.member._id', select: '-hashedPassword -salt'},44 {path : 'owner.leader', select: '-hashedPassword -salt'},45 {path : 'to.team.member._id', select: '-hashedPassword -salt'},46 {path : 'to.team.leader', select: '-hashedPassword -salt'},47 {path : 'architect.team.leader', select: '-hashedPassword -salt'},48 {path : 'architect.team.member._id', select: '-hashedPassword -salt'},49 {path : 'winner.leader', select: '-hashedPassword -salt'},50 {path : 'winner.member._id', select: '-hashedPassword -salt'}51 ],function(err,builderPackage) {52 if (err){ return res.send(500, err); }53 if (builderPackage.hasArchitectManager && builderPackage.architect.team) {54 if (builderPackage.architect.team._id.toString() == user.team._id.toString()) {55 return res.json(builderPackage);56 } else {57 var messagesFiltered = [];58 _.each(builderPackage.messages, function(message){59 if (message.to.toString() == user.team._id.toString()) {60 messagesFiltered.push(message);61 }62 });63 builderPackage.messages = [];64 builderPackage.messages = messagesFiltered;65 return res.json(builderPackage);66 }67 } else {68 var messagesFiltered = [];69 _.each(builderPackage.messages, function(message){70 if (message.to.toString() == user.team._id.toString()) {71 messagesFiltered.push(message);72 }73 });74 builderPackage.messages = [];75 builderPackage.messages = messagesFiltered;76 return res.json(builderPackage);77 }78 });79 });80};81/**82 * get single package id83 */84exports.findByProject = function(req, res){85 BuilderPackage.findOne({project: req.params.id})86 .populate('project')87 .populate('owner')88 .populate('to.team')89 .populate('variations')90 .exec(function(err, builderPackage) {91 if (err){ return res.send(500, err); }92 if (!builderPackage) {return res.send(404, err);}93 User.populate(builderPackage,[94 {path : 'owner.member._id'},95 {path : 'owner.leader'},96 {path : 'to.team.member._id'},97 {path : 'to.team.leader'}98 ],function(err,builderPackage) {99 if (err){ return res.send(500, err); }100 return res.json(builderPackage);101 });102 });103};104exports.getAll = function(req, res){105 BuilderPackage.find({}, function(err, builderPackages){106 if (err) {return res.send(500,err);}107 return res.send(200,builderPackages);108 })109};110exports.destroy = function (req, res) {111 BuilderPackage.findByIdAndRemove(req.params.id, function (err, builderPackage) {112 if (err) {113 return res.send(500, err);114 }115 BuilderPackage.find({}, function(err,builderPackages){116 if (err) {return res.send(500,err);}117 return res.send(200, builderPackages);118 })119 });120};121exports.updatePackage = function(req, res) {122 var requestPackage = req.body.package;123 BuilderPackage.update({_id: req.params.id},124 {name: requestPackage.name, descriptions: requestPackage.descriptions}, function(err, saved) {125 if (err) {return res.send(500,err);}126 return res.send(200,saved);127 })128};129exports.inviteBuilder = function(req, res) {130 BuilderPackage.findById(req.params.id, function(err, builderPackage){131 if (err) {return res.send(500,err);}132 if (!builderPackage) {return res.send(404);}133 var newInvitees = [];134 var invitees = builderPackage.invitees;135 async.each(req.body.toBuilder, function(builder, cb){136 User.findOne({email: builder.email}, function(err, user){137 if (err) {return cb(err);}138 if (!user) {139 invitees.push({140 email: builder.email,141 phoneNumber: builder.phoneNumber142 });143 newInvitees.push({144 email: builder.email,145 phoneNumber: builder.phoneNumber146 });147 cb()148 } else {149 if (user.team._id) {150 invitees.push({151 _id: user.team._id,152 email: builder.email,153 phoneNumber: builder.phoneNumber154 });155 newInvitees.push({156 _id: user.team._id,157 email: builder.email,158 phoneNumber: builder.phoneNumber159 });160 Team.findById(user.team._id, function(err, team){161 if (err) {return cb(err);}162 team.project.push(builderPackage.project);163 team._user = req.user;164 team.save(function(err){165 if (err) {return res.send(500,err);}166 });167 });168 cb();169 } else {170 cb();171 }172 }173 });174 }, function(err){175 if (err) {return res.send(500,err);}176 builderPackage.invitees = invitees;177 builderPackage.newInvitees = newInvitees;178 builderPackage._ownerUser = req.user;179 builderPackage._editUser = req.user;180 builderPackage.markModified('inviteBuilder');181 builderPackage.save(function(err){182 if (err) {return res.send(500,err);}183 builderPackage.populate('invitees.quoteDocument', function(err){184 if (err) {return res.send(500,err);}185 return res.json(200,builderPackage);186 });187 });188 });189 });190};191exports.declineQuote = function(req, res) {192 BuilderPackage.findById(req.body.id, function(err, builderPackage) {193 if (err) {return res.send(500,err);}194 var ownerUser = {};195 _.each(builderPackage.invitees, function(invitee){196 if (invitee._id == req.body.belongTo) {197 invitee.isDecline = true;198 ownerUser = req.body.belongTo;199 Team.findById(invitee._id, function(err,team){200 if (err || !team) {return res.send(500,err);}201 var index = team.project.indexOf(builderPackage.project);202 team.project.splice(index,1);203 team.markModified('project');204 team._user = req.user;205 team.save(function(err){206 if (err) {return res.send(500,err);}207 });208 });209 invitee._id = null;210 invitee.quoteDocument = [];211 }212 });213 builderPackage.markModified('decline-quote');214 builderPackage._ownerUser = ownerUser;215 builderPackage._editUser = req.user;216 builderPackage.save(function(err, saved) {217 if (err) {return res.send(500,err);}218 else {219 return res.json(200, saved);220 }221 });222 });223};224exports.selectWinner = function(req, res) {225 BuilderPackage.findById(req.body.id, function(err, builderPackage){226 if (err) {return res.send(500,err);}227 if (!builderPackage) {return res.send(404);}228 builderPackage.winner = req.body.selector;229 builderPackage.hasWinner = true;230 builderPackage.hasTempWinner = false;231 _.remove(builderPackage.invitees,{_id: builderPackage.winner});232 _.each(builderPackage.invitees, function(invitee){233 if (invitee._id) {234 Team.findById(invitee._id, function(err,team){235 if (err || !team) {return res.send(500,err);}236 var index = team.project.indexOf(builderPackage.project);237 team.project.splice(index,1);238 team.markModified('project');239 team._user = req.user;240 team.save(function(err){241 if (err) {return res.send(500,err);}242 });243 });244 }245 });246 builderPackage.markModified('selectQuote');247 builderPackage._ownerUser = req.body.selector;248 builderPackage._editUser = req.user;249 builderPackage.save(function(err, saved) {250 if (err) {return res.send(500,err);}251 else {252 BuilderPackage.findById(saved._id).populate('winner').exec(function(err,builderPackage) {253 if (err) {return res.send(500,err);}254 else {255 return res.json(200,builderPackage);256 }257 }); 258 }259 });260 });261};262exports.sendMessage = function(req, res) {263 BuilderPackage.findById(req.params.id, function(err, builderPackage) {264 if (err) {return res.send(500,err)}265 if (!builderPackage) {return res.send(404)}266 else {267 builderPackage.messages.push({268 owner: req.body.owner,269 to: req.body.to,270 sendBy: req.user.team._id,271 message: req.body.message,272 sendAt: new Date()273 });274 builderPackage.markModified('sendMessage');275 builderPackage._editUser = req.body.to;276 builderPackage._ownerUser = req.user;277 builderPackage.save(function(err, saved) {278 if (err) {return res.send(500, err)}279 else {280 BuilderPackage.populate(saved,[{path:'messages.sendBy'},{path: 'invitees.quoteDocument'}] , function(err,builderPackage){281 if (err) {return res.send(500,err);}282 EventBus.emit('socket:emit', {283 event: 'messageInBuilderPackageTender:new',284 room: builderPackage._id.toString(),285 data: builderPackage286 });287 return res.json(200,builderPackage);288 });289 }290 });291 }292 });293};294exports.sendMessageToArchitect = function(req, res) {295 var user = req.user;296 BuilderPackage.findById(req.params.id, function(err, builderPackage) {297 if (err) {return res.send(500,err)}298 if (!builderPackage) {return res.send(404,err)}299 else {300 builderPackage.messages.push({301 owner: builderPackage.architect.team,302 to: req.body.to,303 sendBy: req.user.team._id,304 message: req.body.message,305 sendAt: new Date()306 });307 builderPackage.markModified('sendMessageToArchitect');308 builderPackage._editUser = req.user;309 builderPackage.save(function(err, saved) {310 if (err) {return res.send(500, err)}311 else {312 BuilderPackage.populate(saved,[{path:'messages.sendBy'},{path: 'invitees.quoteDocument'}] , function(err,builderPackage){313 if (err) {return res.send(500,err);}314 EventBus.emit('socket:emit', {315 event: 'messageInBuilderPackageTender:new',316 room: builderPackage._id.toString(),317 data: builderPackage318 });319 var messagesFiltered = [];320 _.each(builderPackage.messages, function(message){321 if (message.to.toString() == user.team._id.toString()) {322 messagesFiltered.push(message);323 }324 });325 builderPackage.messages = [];326 builderPackage.messages = messagesFiltered;327 return res.json(200,builderPackage);328 });329 }330 });331 }332 });...
get-preview-builder.ts
Source:get-preview-builder.ts
1import path from 'path';2import { getInterpretedFile, serverRequire, Options } from '@storybook/core-common';3export async function getPreviewBuilder(configDir: Options['configDir']) {4 const main = path.resolve(configDir, 'main');5 const mainFile = getInterpretedFile(main);6 const { core } = mainFile ? serverRequire(mainFile) : { core: null };7 let builderPackage: string;8 if (core) {9 const builderName = typeof core.builder === 'string' ? core.builder : core.builder?.name;10 builderPackage = require.resolve(11 ['webpack4', 'webpack5'].includes(builderName)12 ? `@storybook/builder-${builderName}`13 : builderName,14 { paths: [main] }15 );16 } else {17 builderPackage = require.resolve('@storybook/builder-webpack4');18 }19 const previewBuilder = await import(builderPackage);20 return previewBuilder;...
Using AI Code Generation
1import { builderPackage } from 'storybook-root-decorator'2import { storiesOf } from '@storybook/react'3const stories = storiesOf('test', module)4stories.add('test', () => {5 return (6})
Using AI Code Generation
1import { builderPackage } from 'storybook-root';2builderPackage();3export { builderPackage } from './builderPackage';4export function builderPackage() {5 console.log('builderPackage');6}7export { builderPackage } from './builderPackage';8export function builderPackage() {9 console.log('builderPackage');10}11export { builderPackage } from './builderPackage';12export function builderPackage() {13 console.log('builderPackage');14}15export { builderPackage } from './builderPackage';16export function builderPackage() {17 console.log('builderPackage');18}19export { builderPackage } from './builderPackage';20export function builderPackage() {21 console.log('builderPackage');22}23export { builderPackage } from './builderPackage';24export function builderPackage() {25 console.log('builderPackage');26}
Using AI Code Generation
1import { builderPackage } from "storybook-root";2export default builderPackage("test");3const { builderMain } = require("storybook-root");4module.exports = builderMain(__dirname);5const { builderPreview } = require("storybook-root");6module.exports = builderPreview(__dirname);7const { builderManager } = require("storybook-root");8module.exports = builderManager(__dirname);9const { builderWebpack } = require("storybook-root");10module.exports = builderWebpack(__dirname);11const { builderTsConfig } = require("storybook-root");12module.exports = builderTsConfig(__dirname);13const { builderBabel } = require("storybook-root");14module.exports = builderBabel(__dirname);15const { builderPreviewHead } = require("storybook-root");16module.exports = builderPreviewHead(__dirname);17const { builderPreviewBody } = require("storybook-root");18module.exports = builderPreviewBody(__dirname);19const { builderAddons } = require("storybook-root");20module.exports = builderAddons(__dirname);21const { builderManagerHead } = require("storybook-root");22module.exports = builderManagerHead(__dirname);23const { builderManagerBody } = require("storybook-root");24module.exports = builderManagerBody(__dirname);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!