From 9e0afa49866f2b9916d4b806b089de42c887af42 Mon Sep 17 00:00:00 2001 From: Joshua C Alpuerto Date: Sun, 1 Jul 2018 12:57:27 +0800 Subject: [PATCH 1/2] chore(Add updatedBy entity User): Add updatedBy instance for the entity user --- src/app/user/get.js | 2 +- src/domain/user/user.js | 5 ++++- src/infra/database/models/user.js | 4 ++++ src/infra/repositories/transforms/user.js | 6 ++++-- src/infra/sequelize/migrations/001-users.js | 4 ++++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/app/user/get.js b/src/app/user/get.js index 5e0f86f..e2c9835 100644 --- a/src/app/user/get.js +++ b/src/app/user/get.js @@ -9,7 +9,7 @@ module.exports = ({ userRepository }) => { .then(() => userRepository.getAll({ attributes: [ - 'id', 'firstName', 'lastName', 'middleName', 'email', 'roleId', 'isDeleted', 'createdBy' + 'id', 'firstName', 'lastName', 'middleName', 'email', 'roleId', 'isDeleted', 'createdBy', 'updatedBy' ] }) ) diff --git a/src/domain/user/user.js b/src/domain/user/user.js index ccbe01d..3b23351 100644 --- a/src/domain/user/user.js +++ b/src/domain/user/user.js @@ -13,7 +13,10 @@ const User = t.struct({ verificationCode: t.maybe(t.String), isVerified: t.maybe(t.Number), isDeleted: t.Number, - createdBy: t.String + createdBy: t.maybe(t.String), + updatedBy: t.maybe(t.String), + createdAt: t.maybe(t.Date), + updatedAt: t.maybe(t.Date) }) module.exports = compose( diff --git a/src/infra/database/models/user.js b/src/infra/database/models/user.js index 236f7f1..edcad5c 100644 --- a/src/infra/database/models/user.js +++ b/src/infra/database/models/user.js @@ -48,6 +48,10 @@ module.exports = function (sequelize, DataTypes) { createdBy: { type: DataTypes.UUID, allowNull: false + }, + updatedBy: { + type: DataTypes.UUID, + allowNull: true } }, { hooks: { diff --git a/src/infra/repositories/transforms/user.js b/src/infra/repositories/transforms/user.js index acee7e0..92d32a0 100644 --- a/src/infra/repositories/transforms/user.js +++ b/src/infra/repositories/transforms/user.js @@ -9,7 +9,8 @@ const toEntity = ({ password, roleId, isDeleted, - createdBy + createdBy, + updatedBy }) => User({ id, firstName, @@ -19,7 +20,8 @@ const toEntity = ({ password, roleId, isDeleted, - createdBy + createdBy, + updatedBy }) module.exports = { diff --git a/src/infra/sequelize/migrations/001-users.js b/src/infra/sequelize/migrations/001-users.js index adff26c..9f290f1 100644 --- a/src/infra/sequelize/migrations/001-users.js +++ b/src/infra/sequelize/migrations/001-users.js @@ -49,6 +49,10 @@ module.exports = { type: Sequelize.UUID, allowNull: false }, + updatedBy: { + type: Sequelize.UUID, + allowNull: true + }, createdAt: { allowNull: false, type: Sequelize.DATE, From a2716bc43b839e3e890c9cd5ed53a0764d844ba1 Mon Sep 17 00:00:00 2001 From: Joshua C Alpuerto Date: Sun, 1 Jul 2018 13:02:10 +0800 Subject: [PATCH 2/2] chore(Company Entity): Add updatedBy on company entity --- src/app/company/get.js | 2 +- src/domain/company/company.js | 5 ++++- src/infra/database/models/company.js | 8 ++++++-- src/infra/repositories/transforms/company.js | 6 ++++-- src/infra/sequelize/migrations/002-company.js | 4 ++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/app/company/get.js b/src/app/company/get.js index d834cc2..ea9bc2c 100644 --- a/src/app/company/get.js +++ b/src/app/company/get.js @@ -9,7 +9,7 @@ module.exports = ({ companyRepository }) => { .then(() => companyRepository.getAll({ attributes: [ - 'id', 'name', 'address', 'contact', 'tin', 'sss', 'philhealth', 'isDeleted', 'createdBy' + 'id', 'name', 'address', 'contact', 'tin', 'sss', 'philhealth', 'isDeleted', 'createdBy', 'updatedBy' ] }) ) diff --git a/src/domain/company/company.js b/src/domain/company/company.js index b0c7dfd..39ae3fe 100644 --- a/src/domain/company/company.js +++ b/src/domain/company/company.js @@ -11,7 +11,10 @@ const Company = t.struct({ sss: t.String, philhealth: t.String, isDeleted: t.Number, - createdBy: t.String + createdBy: t.maybe(t.String), + updatedBy: t.maybe(t.String), + createdAt: t.maybe(t.Date), + updatedAt: t.maybe(t.Date) }) module.exports = compose( diff --git a/src/infra/database/models/company.js b/src/infra/database/models/company.js index fe20309..dec6520 100644 --- a/src/infra/database/models/company.js +++ b/src/infra/database/models/company.js @@ -1,5 +1,5 @@ module.exports = function (sequelize, DataTypes) { - const User = sequelize.define('companies', { + const Company = sequelize.define('companies', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, @@ -37,6 +37,10 @@ module.exports = function (sequelize, DataTypes) { createdBy: { type: DataTypes.UUID, allowNull: false + }, + updatedBy: { + type: DataTypes.UUID, + allowNull: true } }, { freezeTableName: true, @@ -48,5 +52,5 @@ module.exports = function (sequelize, DataTypes) { } }) - return User + return Company } diff --git a/src/infra/repositories/transforms/company.js b/src/infra/repositories/transforms/company.js index 40fcc10..69505f4 100644 --- a/src/infra/repositories/transforms/company.js +++ b/src/infra/repositories/transforms/company.js @@ -9,7 +9,8 @@ const toEntity = ({ sss, philhealth, isDeleted, - createdBy + createdBy, + updatedBy }) => Company({ id, name, @@ -19,7 +20,8 @@ const toEntity = ({ sss, philhealth, isDeleted, - createdBy + createdBy, + updatedBy }) module.exports = { diff --git a/src/infra/sequelize/migrations/002-company.js b/src/infra/sequelize/migrations/002-company.js index a129a41..05a41c9 100644 --- a/src/infra/sequelize/migrations/002-company.js +++ b/src/infra/sequelize/migrations/002-company.js @@ -40,6 +40,10 @@ module.exports = { type: Sequelize.UUID, allowNull: false }, + updatedBy: { + type: Sequelize.UUID, + allowNull: true + }, createdAt: { allowNull: false, type: Sequelize.DATE,