Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added controller, model, migration and seeder for Activities #19

Merged
merged 1 commit into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions controllers/activitiesController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ActivitiesController{}

module.exports = ActivitiesController;
35 changes: 35 additions & 0 deletions migrations/20220915231847-create-activities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Activities', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
name: {
type: dataTypes.STRING,
allowNull: false,
},
content: {
type: dataTypes.TEXT,
allowNull: false,
},
image: {
type: dataTypes.STRING,
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
},
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Activities');
},
};
29 changes: 29 additions & 0 deletions models/activities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';
const { Model } = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class Activities extends Model {
/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Este comentario no debería estar.

* 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
}
}
Activities.init(
{
id: DataTypes.INTEGER,
name: DataTypes.STRING,
content:DataTypes.TEXT,
image:DataTypes.STRING,
},
{
sequelize,
modelName: 'Activities',
timestamps: true,
paranoid: true,
}
);
return Activities;
};
30 changes: 30 additions & 0 deletions seeders/20220915233004-create-activities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.bulkInsert(
'Activities',
[
{
name: 'Activity example 1',
content: 'Content activity example 1',
image: 'image activity example 1',
createdAt: new Date(),
updatedAt: new Date(),
},
{
name: 'Activity example 2',
content: 'Content activity example 2',
image: 'image activity example 2',
createdAt: new Date(),
updatedAt: new Date(),
},
],
{}
);
},

down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('Activities', null, {});
},
};