From 23f08fe1c39bf85bb0648b3216a4fbb3026bdc25 Mon Sep 17 00:00:00 2001 From: Alvaro1599 Date: Wed, 14 Sep 2022 18:12:31 -0500 Subject: [PATCH 1/4] =?UTF-8?q?se=20a=C3=B1adi=C3=B3=20el=20modelo,=20base?= =?UTF-8?q?=20del=20controlador=20y=20la=20migraci=C3=B3n=20de=20Members?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/member.controller.js | 50 ++++++++++++++++++++ migrations/20220914211317-create-member.js | 51 ++++++++++++++++++++ models/member.js | 55 ++++++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 controllers/member.controller.js create mode 100644 migrations/20220914211317-create-member.js create mode 100644 models/member.js diff --git a/controllers/member.controller.js b/controllers/member.controller.js new file mode 100644 index 0000000..7ae8882 --- /dev/null +++ b/controllers/member.controller.js @@ -0,0 +1,50 @@ +const { Members: Member } = require("../models").sequelize.models + +class MemberController { +/* async createMember(data) { + try { + return await Member.create({...data}) + } catch (error) { + throw new Error(error) + } + } + + async findMemberByPk(id) { + try { + const user = await Member.findByPk(id) + if (!user) { + throw new Error("Member can't be found") + } + return user + } catch (error) { + throw new Error(error) + + } + } + async deleteMember(id) { + try { + await this.findMemberByPk(id) + } catch (error) { + throw new Error(error) + } + } + async deleteMember(id) { + try { + const user=await this.findMemberByPk(id) + return user.destroy() + } catch (error) { + throw new Error(error) + } + } + + async updateMemberById(data){ + try { + await this.findMemberByPk(id) + } catch (error) { + throw new Error(error) + } + } +*/ +} + +module.exports = new MemberController \ No newline at end of file diff --git a/migrations/20220914211317-create-member.js b/migrations/20220914211317-create-member.js new file mode 100644 index 0000000..b3e2f0e --- /dev/null +++ b/migrations/20220914211317-create-member.js @@ -0,0 +1,51 @@ +'use strict'; +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.createTable('Member', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + name: { + allowNull: false, + type: Sequelize.STRING + }, + facebookUrl: { + allowNull: true, + type: Sequelize.STRING + }, + instagramUrl: { + allowNull: true, + type: Sequelize.STRING + }, + linkedinUrl: { + allowNull: true, + type: Sequelize.STRING + }, + image: { + allowNull: false, + type: Sequelize.STRING + }, + description: { + allowNull: true, + type: Sequelize.STRING + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + }, + deletedAt: { + type: Sequelize.DATE + } + }); + }, + down: async (queryInterface, Sequelize) => { + await queryInterface.dropTable('Member'); + } +}; \ No newline at end of file diff --git a/models/member.js b/models/member.js new file mode 100644 index 0000000..44f78d7 --- /dev/null +++ b/models/member.js @@ -0,0 +1,55 @@ +'use strict'; +const { + Model +} = require('sequelize'); +module.exports = (sequelize, DataTypes) => { + class Member 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 + } + }; + Member.init({ + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: DataTypes.INTEGER + }, + name: { + allowNull: false, + type: DataTypes.STRING + }, + facebookUrl: { + allowNull: true, + type: DataTypes.STRING + }, + instagramUrl: { + allowNull: true, + type: DataTypes.STRING + }, + linkedinUrl: { + allowNull: true, + type: DataTypes.STRING + }, + image: { + allowNull: false, + type: DataTypes.STRING + }, + description: { + allowNull: true, + type: DataTypes.STRING + }, + deletedAt: { + type: DataTypes.DATE + } + }, { + sequelize, + modelName: 'Member', paranoid: true + }); + return Member; +}; \ No newline at end of file From bc0d95b4d49faebfcc97e150ff25cbe51a062bd4 Mon Sep 17 00:00:00 2001 From: Alvaro1599 Date: Wed, 14 Sep 2022 20:43:51 -0500 Subject: [PATCH 2/4] =?UTF-8?q?se=20a=C3=B1adi=C3=B3=20los=20seeders=20y?= =?UTF-8?q?=20el=20rollback,=20se=20elimin=C3=B3=20el=20comentario?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/member.controller.js | 43 ------------ migrations/20220914211317-create-member.js | 4 +- models/member.js | 11 +-- seeders/20220914235547-create-member.js | 78 ++++++++++++++++++++++ 4 files changed, 83 insertions(+), 53 deletions(-) create mode 100644 seeders/20220914235547-create-member.js diff --git a/controllers/member.controller.js b/controllers/member.controller.js index 7ae8882..ff58483 100644 --- a/controllers/member.controller.js +++ b/controllers/member.controller.js @@ -1,50 +1,7 @@ const { Members: Member } = require("../models").sequelize.models class MemberController { -/* async createMember(data) { - try { - return await Member.create({...data}) - } catch (error) { - throw new Error(error) - } - } - async findMemberByPk(id) { - try { - const user = await Member.findByPk(id) - if (!user) { - throw new Error("Member can't be found") - } - return user - } catch (error) { - throw new Error(error) - - } - } - async deleteMember(id) { - try { - await this.findMemberByPk(id) - } catch (error) { - throw new Error(error) - } - } - async deleteMember(id) { - try { - const user=await this.findMemberByPk(id) - return user.destroy() - } catch (error) { - throw new Error(error) - } - } - - async updateMemberById(data){ - try { - await this.findMemberByPk(id) - } catch (error) { - throw new Error(error) - } - } -*/ } module.exports = new MemberController \ No newline at end of file diff --git a/migrations/20220914211317-create-member.js b/migrations/20220914211317-create-member.js index b3e2f0e..b3c3320 100644 --- a/migrations/20220914211317-create-member.js +++ b/migrations/20220914211317-create-member.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = { up: async (queryInterface, Sequelize) => { - await queryInterface.createTable('Member', { + await queryInterface.createTable('Members', { id: { allowNull: false, autoIncrement: true, @@ -46,6 +46,6 @@ module.exports = { }); }, down: async (queryInterface, Sequelize) => { - await queryInterface.dropTable('Member'); + await queryInterface.dropTable('Members'); } }; \ No newline at end of file diff --git a/models/member.js b/models/member.js index 44f78d7..b6c7512 100644 --- a/models/member.js +++ b/models/member.js @@ -25,15 +25,12 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.STRING }, facebookUrl: { - allowNull: true, type: DataTypes.STRING }, instagramUrl: { - allowNull: true, type: DataTypes.STRING }, linkedinUrl: { - allowNull: true, type: DataTypes.STRING }, image: { @@ -41,15 +38,13 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.STRING }, description: { - allowNull: true, type: DataTypes.STRING }, - deletedAt: { - type: DataTypes.DATE - } + deletedAt:DataTypes.DATE }, { sequelize, - modelName: 'Member', paranoid: true + modelName: 'Member', + paranoid: true }); return Member; }; \ No newline at end of file diff --git a/seeders/20220914235547-create-member.js b/seeders/20220914235547-create-member.js new file mode 100644 index 0000000..9e392b9 --- /dev/null +++ b/seeders/20220914235547-create-member.js @@ -0,0 +1,78 @@ +'use strict'; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.bulkInsert('Members', [{ + name: 'Member', + facebookUrl: 'https://www.facebook.com/member/', + instagramUrl: 'https://www.instagram.com/member/', + linkedinUrl: 'https://www.linkedin.com/member/', + description: "this is a description", + image: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', + createdAt: new Date, + updatedAt: new Date, + }, + { + name: 'Member1', + facebookUrl: 'https://www.facebook.com/member1/', + instagramUrl: 'https://www.instagram.com/member1/', + linkedinUrl: 'https://www.linkedin.com/member1/', + image: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', + createdAt: new Date, + updatedAt: new Date, + }, { + name: 'Member2', + facebookUrl: 'https://www.facebook.com/member2/', + instagramUrl: 'https://www.instagram.com/member2/', + linkedinUrl: 'https://www.linkedin.com/member2/', + description: "this is a description", + image: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', + createdAt: new Date, + updatedAt: new Date, + } + , { + name: 'Member3', + facebookUrl: 'https://www.facebook.com/member3/', + instagramUrl: 'https://www.instagram.com/member3/', + linkedinUrl: 'https://www.linkedin.com/member3/', + description: "this is a description", + image: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', + createdAt: new Date, + updatedAt: new Date, + } + , { + name: 'Member4', + facebookUrl: 'https://www.facebook.com/member4/', + instagramUrl: 'https://www.instagram.com/member4/', + linkedinUrl: 'https://www.linkedin.com/member4/', + description: "this is a description", + image: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', + createdAt: new Date, + updatedAt: new Date, + } + , { + name: 'Member5', + facebookUrl: 'https://www.facebook.com/member5/', + instagramUrl: 'https://www.instagram.com/member5/', + linkedinUrl: 'https://www.linkedin.com/member5/', + description: "this is a description", + image: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', + createdAt: new Date, + updatedAt: new Date, + }, + { + name: 'Member6', + facebookUrl: 'https://www.facebook.com/member6/', + instagramUrl: 'https://www.instagram.com/member6/', + linkedinUrl: 'https://www.linkedin.com/member6/', + description: "this is a description", + image: 'https://www.designevo.com/res/templates/thumb_small/colorful-hand-and-warm-community.png', + createdAt: new Date, + updatedAt: new Date, + }], {}); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.bulkDelete('Members', null, {}); + } +}; From c9e84d589dc7cfbb75b7f98d75a75ce8fb266083 Mon Sep 17 00:00:00 2001 From: alvaro1599 Date: Fri, 16 Sep 2022 02:35:24 -0500 Subject: [PATCH 3/4] =?UTF-8?q?se=20actualiz=C3=B3=20con=20la=20rama=20dev?= =?UTF-8?q?elopment=20se=20a=C3=B1adi=C3=B3=20campos=20que=20permitan=20el?= =?UTF-8?q?ementos=20nulos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/member.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/models/member.js b/models/member.js index b6c7512..95f0581 100644 --- a/models/member.js +++ b/models/member.js @@ -25,12 +25,15 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.STRING }, facebookUrl: { + allowNull: true, type: DataTypes.STRING }, instagramUrl: { + allowNull: true, type: DataTypes.STRING }, linkedinUrl: { + allowNull: true, type: DataTypes.STRING }, image: { @@ -38,12 +41,13 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.STRING }, description: { + allowNull: true, type: DataTypes.STRING - }, - deletedAt:DataTypes.DATE + }, + deletedAt: DataTypes.DATE }, { sequelize, - modelName: 'Member', + modelName: 'Member', paranoid: true }); return Member; From 31d12995db618c2306a0e48b988755f6f901eee2 Mon Sep 17 00:00:00 2001 From: Alvaro1599 <77476175+Alvaro1599@users.noreply.github.com> Date: Fri, 16 Sep 2022 02:40:43 -0500 Subject: [PATCH 4/4] se cambio la forma de instaciar MemberController --- controllers/member.controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/member.controller.js b/controllers/member.controller.js index ff58483..619ac5d 100644 --- a/controllers/member.controller.js +++ b/controllers/member.controller.js @@ -4,4 +4,4 @@ class MemberController { } -module.exports = new MemberController \ No newline at end of file +module.exports = MemberController