generated from alkemyTech/base-ong-server-js
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from alkemyTech/OT-30_Slides_Model-migration-c…
…ontroller-seeders Ot 30 slides model migration controller seeders
- Loading branch information
Showing
4 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class SlidersController{} | ||
|
||
module.exports = SlidersController; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
await queryInterface.createTable('Slides', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
imageUrl: { | ||
allowNull:false, | ||
type: Sequelize.STRING | ||
}, | ||
text: { | ||
allowNull:false, | ||
type: Sequelize.STRING | ||
}, | ||
order: { | ||
allowNull:false, | ||
type: Sequelize.INTEGER | ||
}, | ||
organizationId: { | ||
type: Sequelize.INTEGER, | ||
references: { | ||
model: 'Organizations', | ||
key: 'id', | ||
}, | ||
onUpdate: 'CASCADE', | ||
onDelete: 'SET NULL' | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
}); | ||
}, | ||
down: async (queryInterface, Sequelize) => { | ||
await queryInterface.dropTable('Slides'); | ||
} | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
const { | ||
Model | ||
} = require('sequelize'); | ||
module.exports = (sequelize, DataTypes) => { | ||
class Slide extends Model { | ||
/** | ||
* Helper method for defining associations. | ||
* This method is not a part of Sequelize lifecycle. | ||
* The `models/index` file will call this method automatically. | ||
*/ | ||
static associate(models) { | ||
// define association here | ||
Slide.belongsTo(models.Organization, { | ||
as: 'organization', | ||
foreignKey: 'id', | ||
sourceKey: 'organizationId', | ||
}) | ||
} | ||
}; | ||
Slide.init({ | ||
id: { | ||
type: DataTypes.INTEGER, | ||
autoIncrement: true, | ||
allowNull: false, | ||
primaryKey:true | ||
}, | ||
imageUrl: { | ||
allowNull: false, | ||
type: DataTypes.STRING | ||
}, | ||
text: { | ||
allowNull: false, | ||
type: DataTypes.STRING | ||
}, | ||
order: { | ||
allowNull: false, | ||
type: DataTypes.INTEGER | ||
}, | ||
organizationId: { | ||
type: DataTypes.INTEGER | ||
}, | ||
deletedAt: DataTypes.DATE | ||
}, { | ||
sequelize, | ||
modelName: 'Slide', | ||
timestamps: true, | ||
paranoid: true | ||
}); | ||
return Slide; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
await queryInterface.bulkInsert('Slides', [{ | ||
imageUrl: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', | ||
text: 'this is a text', | ||
order: 1, | ||
organizationId: 1, | ||
createdAt: new Date, | ||
updatedAt: new Date | ||
},{ | ||
imageUrl: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', | ||
text: 'this is a text1', | ||
order: 2, | ||
organizationId: 2, | ||
createdAt: new Date, | ||
updatedAt: new Date | ||
},{ | ||
imageUrl: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', | ||
text: 'this is a text2', | ||
order: 3, | ||
organizationId: 2, | ||
createdAt: new Date, | ||
updatedAt: new Date | ||
},{ | ||
imageUrl: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', | ||
text: 'this is a text3', | ||
order: 4, | ||
organizationId: 2, | ||
createdAt: new Date, | ||
updatedAt: new Date | ||
},{ | ||
imageUrl: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', | ||
text: 'this is a text4', | ||
order: 5, | ||
organizationId: 1, | ||
createdAt: new Date, | ||
updatedAt: new Date | ||
},{ | ||
imageUrl: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', | ||
text: 'this is a text5', | ||
order: 6, | ||
organizationId: 1, | ||
createdAt: new Date, | ||
updatedAt: new Date | ||
},{ | ||
imageUrl: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', | ||
text: 'this is a text6', | ||
order: 7, | ||
organizationId: 1, | ||
createdAt: new Date, | ||
updatedAt: new Date | ||
},{ | ||
imageUrl: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', | ||
text: 'this is a text7', | ||
order: 8, | ||
organizationId: 1, | ||
createdAt: new Date, | ||
updatedAt: new Date | ||
}], {}); | ||
}, | ||
|
||
down: async (queryInterface, Sequelize) => { | ||
await queryInterface.bulkDelete('Slides', null, {}); | ||
} | ||
}; |