Skip to content

Instantly share code, notes, and snippets.

const models = require('./models');
const User = models.User;
const Company = models.Company;
const WorkingDay = models.WorkingDay;
// 1:1
// Get the company linked to a given User
User.findOne({
where: {email: 'john-connor@domain.com'}, include: 'company'
})
const models = require('./models');
const User = models.User;
const Company = models.Company;
const WorkingDay = models.WorkingDay;
let currentDate = new Date();
WorkingDay.bulkCreate([
{
weekDay: 'Monday',
const models = require('./models');
const User = models.User;
const Company = models.Company;
const WorkingDay = models.WorkingDay;
let currentDate = new Date();
WorkingDay.bulkCreate([
{
weekDay: 'Monday',
const models = require('./models');
const User = models.User;
const Company = models.Company;
const WorkingDay = models.WorkingDay;
// // Get workingDays for a given User
User.findByPk(1, {include: ['days']})
.then((user) => {
console.log(user.get())
@Eth3rnit3
Eth3rnit3 / asyncAction.js
Created December 19, 2018 08:00
example of an asynx action with redux
import axios from 'axios'
export function fetchCategories(){
return async dispatch => {
function onSuccess(response){
dispatch({type: 'FETCH_CATEGORIES', payload: response })
return response
}
function onError(error){
dispatch({type: 'ERROR_GENERATED', error })
const fs = require('fs');
module.exports = {
getFilesNames: (path='./uploads') => {
let files = fs.readdirSync(path)
return files
}
}
@Eth3rnit3
Eth3rnit3 / nestedInclude.js
Created January 9, 2019 15:22
In this example, Product belongsTo Media and Category hasMany Product Media > Product > Category Product know mediaId Product know categoryId
Category.findByPk(req.params.id, {
include: [
{
model: Product, as: 'products', include:
[
{model: Media, as: 'image'}
]
}
]
})
if(process.env.NODE_ENV == 'production'){
app.use(express.static(path.join(__dirname, 'client')));
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'client', 'index.html'));
});
}
///////////////////// Exercice 1 ///////////////////////
let num1 = 5;
let num2 = 4;
let i = 0;
let result = 0;
while(i < num1){
result = result + num2
i++;
}
{
"current": "0.1.6"
}