This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require('fs'); | |
| module.exports = { | |
| getFilesNames: (path='./uploads') => { | |
| let files = fs.readdirSync(path) | |
| return files | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const models = require('./models'); | |
| const User = models.User; | |
| const Company = models.Company; | |
| const WorkingDay = models.WorkingDay; | |
| let currentDate = new Date(); | |
| WorkingDay.bulkCreate([ | |
| { | |
| weekDay: 'Monday', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const models = require('./models'); | |
| const User = models.User; | |
| const Company = models.Company; | |
| const WorkingDay = models.WorkingDay; | |
| let currentDate = new Date(); | |
| WorkingDay.bulkCreate([ | |
| { | |
| weekDay: 'Monday', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: '[email protected]'}, include: 'company' | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const models = require('./models'); | |
| const User = models.User; | |
| const Company = models.Company; | |
| const WorkingDay = models.WorkingDay; | |
| User.bulkCreate([ | |
| {email: '[email protected]', firstName: 'John', lastName: 'DOE', companyId: 1}, | |
| {email: '[email protected]', firstName: 'Logan', lastName: 'WOLVERINE', companyId: 1}, | |
| {email: '[email protected]', firstName: 'John', lastName: 'CONNOR', companyId: 1} | |
| ]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const models = require('./models'); | |
| const User = models.User; | |
| const Company = models.Company; | |
| const WorkingDay = models.WorkingDay; | |
| Company.create({ | |
| name: "My super company" | |
| }) | |
| .then((newCompany) => { | |
| // The get() function allows you to recover only the DataValues of the object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const models = require('./models'); | |
| const User = models.User; | |
| const Company = models.Company; | |
| const WorkingDay = models.WorkingDay; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| module.exports = (sequelize, DataTypes) => { | |
| const User = sequelize.define('User', { | |
| email: DataTypes.STRING, | |
| firstName: DataTypes.STRING, | |
| lastName: DataTypes.STRING, | |
| companyId: DataTypes.INTEGER | |
| }, {}); | |
| User.associate = function(models) { | |
| User.belongsTo(models.Company, {foreignKey: 'companyId', as: 'company'}) |