Skip to content

Instantly share code, notes, and snippets.

View segovia-no's full-sized avatar
🏠
Working from home

Diego Segovia segovia-no

🏠
Working from home
  • ClickIT Devops & Software Development
  • Chile
View GitHub Profile
@JamieMason
JamieMason / group-objects-by-property.md
Created September 14, 2018 07:38
Group Array of JavaScript Objects by Key or Property Value

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
@jskod
jskod / multi-tenant.js
Created September 13, 2019 07:44
Multi-Tenant Mongoose Model Wrapper For NodeJS Based Applications
import mongoose, { Schema } from 'mongoose'
import { getCurrentTenantId } from './storage'
/**
Function will return another function, which will further return a mongoose discriminator.
The only difference here is that everytime you use the mongoose model, you will have to call a function,
but it will give you a freedom of passing tenant-based data.
*/
export function tenantModel(name, schema, options) {
return (props = {}) => {