io.on('connection', socket => { socket.on('request shortid', function() { onlines.delete(socket.shortid); socket.shortid = shortid.generate().toLowerCase(); // generate shortid for a request onlines.set(socket.shortid, socket); // add incomming connection to online table socket.emit('shortid', socket.shortid); }); socket.on('set shortid', function(id) { onlines.delete(socket.shortid); socket.shortid = id; onlines.set(socket.shortid, socket); socket.emit('shortid', socket.shortid); }) socket.on('disconnect', socket => { onlines.delete(socket.shortid); }); });
function handleEventChoose(deps, ans) { deps.reduce(ans); deps.requestId = shortid.generate(); const { questions } = mapEventIdToData(deps.state.eventId); const filteredQuestions = questions.filter( filterQuestions(deps.state.eventId) ); // filter val which is set by first question filteredQuestions.forEach(e => deps.prompts.next(e)); if (filteredQuestions.length === 0) { validate(deps.state, () => deps.prompts.next(askSendRequest)); } }
/** * Get a random ID for a record */ const randid = _ => { return shortid.generate(); }
function enrichPayloadMaybe(payload) { switch (payload.eventId) { case 'createJobRequest': { return Object.assign({}, payload, { jobRequestId: shortid.generate() }); } default: { return payload; } } }
api.post('/post', function (request) { const title = request.body.title; const article = request.body.article; Article .create({ id: shortid.generate(), title: title, article: article }) .then(function(article) { }) .then(() => api.sendStatus(200)); });
/** * @returns {Object} - a new user object */ export function generateUser() { return { name: faker.name.findName(), email: faker.internet.email(), profile_pic: faker.internet.avatar(), status: txtgen.sentence(), user_id: shortid.generate() }; }
bcrypt.hash(this.password, 10, (err, hash) => { if (err) throw err; const username = `${this.firstName}.${ this.lastName }${shortid.generate()}`; this.username = username.toLowerCase(); this.password = hash; this.save((error, savedObj) => { if (error) throw error; resolve(savedObj); }); });
it('Should successfully create a new plan for subscription update', (done) => { plan.code = shortid.generate() moip.plan.create(plan) .then((response) => { response.statusCode.should.be.eql(201) done() }) .catch(done) })
beforeCreate(project){ const url = slug(project.name).toLowerCase(); project.url = `${url}-${shortid.generate()}`; }
function _createChatMessage(id, message) { _chats[id].tabbed = true; if(message.username) { _chats[id].username = message.username; } _chats[id].messages.push({ id: shortid.generate(), // each message gets unique ID type: message.type, date: message.date, text: message.text, meta: message.meta }); }
/* Handle index requests for /Pad */ router.get('/', function (req, res, next) { var sid = shortid.generate() res.render('index', { title: 'Welcome to Pad', buttonLbl: 'Get started', id: sid }) })
router.get('/uuid', (req, res) => { res.json({ id: shortid.generate() }) })
/* GET home page. */ router.get('/', function (req, res, next) { var sid = shortid.generate() res.render('index', { title: 'Welcome to Pad', buttonLbl: 'Get started', id: sid }) })
/** * @returns {Object} - a new user object */ export function generateUser() { return { name: faker.name.findName(), email: faker.internet.email(), profile_pic: faker.internet.avatar(), status: txtgen.sentence(), user_id: shortid.generate() }; }