Skip to content

Commit

Permalink
Reorganiza módulos
Browse files Browse the repository at this point in the history
  • Loading branch information
fsodano committed Sep 4, 2020
1 parent c7b6196 commit 770f792
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 47 deletions.
6 changes: 0 additions & 6 deletions src/config/associations.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/config/di.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const SequelizeStore = require('connect-session-sequelize')(session.Store);
const { ClubController, ClubService, ClubRepository, ClubModel } = require('../module/club/module');
const { AreaController, AreaService, AreaRepository, AreaModel } = require('../module/area/module');

const setupSequelizeModelAssociations = require('./associations');

function configureMainSequelizeDatabase() {
const sequelize = new Sequelize({
dialect: 'sqlite',
Expand Down Expand Up @@ -118,6 +116,5 @@ module.exports = function configureDI() {
addCommonDefinitions(container);
addAreaModuleDefinitions(container);
addClubModuleDefinitions(container);
setupSequelizeModelAssociations(container.get('ClubModel'), container.get('AreaModel'));
return container;
};
2 changes: 1 addition & 1 deletion src/module/area/controller/areaController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fromDataToEntity = require('../mapper/areaMapper');
const { fromDataToEntity } = require('../mapper/areaMapper');
const AreaIdNotDefinedError = require('./error/areaIdNotDefinedError');
const AbstractController = require('../../abstractController');

Expand Down
15 changes: 14 additions & 1 deletion src/module/area/mapper/areaMapper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
const Area = require('../entity/area');

module.exports = function fromDataToEntity({ id, name }) {
/**
* @param {import('./areaModel')} model
* @returns {import('../../entity/area')}
*/
function fromModelToEntity(model) {
return new Area(model.toJSON());
}

function fromDataToEntity({ id, name }) {
return new Area({ id, name });
}

module.exports = {
fromModelToEntity,
fromDataToEntity,
};
File renamed without changes.
2 changes: 1 addition & 1 deletion src/module/area/module.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const AreaController = require('./controller/areaController');
const AreaRepository = require('./repository/sqlite/areaRepository');
const AreaService = require('./service/areaService');
const AreaModel = require('./repository/sqlite/areaModel');
const AreaModel = require('./model/areaModel');

/**
* @param {import('express').Application} app
Expand Down
11 changes: 0 additions & 11 deletions src/module/area/repository/sqlite/areaMapper.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/module/area/repository/sqlite/areaRepository.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { fromModelToEntity } = require('./areaMapper');
const { fromModelToEntity } = require('../../mapper/areaMapper');
const AbstractAreaRepository = require('../abstractAreaRepository');
const AreaNotFoundError = require('../error/areaNotFoundError');
const AreaIdNotDefinedError = require('../error/areaIdNotDefinedError');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { fromModelToEntity } = require('../clubMapper');
const ClubEntity = require('../../../entity/club');
const ClubEntity = require('../../entity/club');

test('Convierte un modelo a una entidad del dominio', () => {
expect(
Expand Down
9 changes: 9 additions & 0 deletions src/module/club/mapper/clubMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ function fromDataToEntity({
});
}

/**
* @param {import('./clubModel')} model
* @returns {import('../../entity/club')}
*/
function fromModelToEntity(model) {
return new Club(model.toJSON());
}

module.exports = {
fromDataToEntity,
fromModelToEntity,
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const Sequelize = require('sequelize');
const ClubModel = require('../clubModel');
const AreaModel = require('../../../area/model/areaModel');

const sequelizeInstance = new Sequelize('sqlite::memory');

test('Después de hacerle un setup a Club Model y sincronizar el modelo, la tabla Clubs existe ', async () => {
const TEST_ID = 1;
test('Después de hacerle un setup a Club Model y sincronizar el modelo, la tabla Clubs existe', async () => {
ClubModel.setup(sequelizeInstance);
AreaModel.setup(sequelizeInstance);
ClubModel.setupAssociations(AreaModel);
await ClubModel.sync({ force: true });
await ClubModel.create({ id: 1 });
const club = await ClubModel.findOne({ where: { id: TEST_ID } });
expect(club.id).toEqual(TEST_ID);
expect(await ClubModel.findAll()).toEqual([]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ module.exports = class ClubModel extends Model {
timestamps: false,
}
);

return ClubModel;
}

/**
*
* @param {import('../../area/model/areaModel')} AreaModel
*/
static setupAssociations(AreaModel) {
ClubModel.belongsTo(AreaModel, { foreignKey: 'area_id' });
}
};
2 changes: 1 addition & 1 deletion src/module/club/module.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const ClubController = require('./controller/clubController');
const ClubRepository = require('./repository/sqlite/clubRepository');
const ClubService = require('./service/clubService');
const ClubModel = require('./repository/sqlite/clubModel');
const ClubModel = require('./model/clubModel');

/**
* @param {import('express').Application} app
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { Sequelize } = require('sequelize');
const ClubRepository = require('../clubRepository');
const ClubModel = require('../clubModel');
const AreaModel = require('../../../../area/repository/sqlite/areaModel');
const ClubModel = require('../../../model/clubModel');
const AreaModel = require('../../../../area/model/areaModel');
const ClubEntity = require('../../../entity/club');
const ClubNotFoundError = require('../../error/clubNotFoundError');
const ClubIdNotDefinedError = require('../../error/clubIdNotDefinedError');
Expand Down
11 changes: 0 additions & 11 deletions src/module/club/repository/sqlite/clubMapper.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/module/club/repository/sqlite/clubRepository.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { fromModelToEntity } = require('./clubMapper');
const { fromModelToEntity } = require('../../mapper/clubMapper');
const AbstractClubRepository = require('../abstractClubRepository');
const ClubNotFoundError = require('../error/clubNotFoundError');
const ClubIdNotDefinedError = require('../error/clubIdNotDefinedError');

module.exports = class ClubRepository extends AbstractClubRepository {
/**
* @param {typeof import('./clubModel')} clubModel
* * @param {typeof import('../../../area/repository/sqlite/areaModel')} areaModel
* @param {typeof import('../../model/clubModel')} clubModel
* * @param {typeof import('../../../area/model/areaModel')} areaModel
*/
constructor(clubModel, areaModel) {
super();
Expand Down

0 comments on commit 770f792

Please sign in to comment.