Skip to content

Commit

Permalink
refactor: repositories directory (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrunton authored Aug 26, 2024
1 parent 3790af8 commit 6447452
Show file tree
Hide file tree
Showing 37 changed files with 69 additions and 60 deletions.
8 changes: 7 additions & 1 deletion services/api/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ module.exports = {
'@casl/ability',
],
},
{
from: [['data', { adapterType: 'test' }]],
allow: ['@faker-js/faker'],
},
{
from: ['config'],
allow: ['@aws-sdk/client-dynamodb', '@nestjs/config', 'assert'],
Expand Down Expand Up @@ -121,7 +125,9 @@ module.exports = {
},
{
type: 'data',
pattern: 'src/data',
pattern: ['src/data/*/*', 'src/data'],
mode: 'folder',
capture: ['kind', 'adapterType'],
},
{
type: 'config',
Expand Down
2 changes: 2 additions & 0 deletions services/api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ reports/mutation

# typedoc
/docs

/coverage
1 change: 1 addition & 0 deletions services/api/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ module.exports = {
'^@entities/(.*)$': ['<rootDir>/src/domain/entities/$1'],
'^@usecases/(.*)$': ['<rootDir>/src/domain/usecases/$1'],
},
coverageDirectory: 'coverage',
};
2 changes: 1 addition & 1 deletion services/api/scripts/db/drop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DynamoDBAdapter } from '@data/adapters/dynamodb.adapter';
import { DynamoDBAdapter } from '@data/adapters/dynamodb/dynamodb.adapter';
import { RunnableDataModule, runWithContext } from '../runWithContext';

runWithContext({
Expand Down
2 changes: 1 addition & 1 deletion services/api/scripts/db/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DynamoDBAdapter } from '@data/adapters/dynamodb.adapter';
import { DynamoDBAdapter } from '@data/adapters/dynamodb/dynamodb.adapter';
import { RunnableDataModule, runWithContext } from '../runWithContext';

runWithContext({
Expand Down
4 changes: 2 additions & 2 deletions services/api/src/app/dispatcher/dispatcher.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { DispatcherService } from './dispatcher.service';
import { TestMessagesRepository } from '@fixtures/data/test.messages.repository';
import { TestMessagesRepository } from '@data/repositories/test/test.messages.repository';
import { TestAuthService } from '@fixtures/auth/test-auth-service';
import { DraftMessage, SentMessage } from '@entities/messages';
import { RoomFactory } from '@fixtures/messages/room.factory';
Expand Down
10 changes: 5 additions & 5 deletions services/api/src/app/messages/messages.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import {
import { MessageFactory } from '@fixtures/messages/message.factory';
import { UsersRepository } from '@entities/users';
import { MessagesRepository } from '@entities/messages';
import { TestDataModule } from '@fixtures/data/test.data.module';
import { TestUsersRepository } from '@fixtures/data/test.users.repository';
import { TestMessagesRepository } from '@fixtures/data/test.messages.repository';
import { TestUsersRepository } from '@data/repositories/test/test.users.repository';
import { TestMessagesRepository } from '@data/repositories/test/test.messages.repository';
import { Room } from '@entities/room.entity';
import { RoomsRepository } from '@entities/rooms.repository';
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { RoomFactory } from '@fixtures/messages/room.factory';
import { CreateMessageDto } from './dto/messages';
import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository';
import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository';
import { MembershipsRepository } from '@entities/memberships.repository';
import { MembershipStatus } from '@entities/membership.entity';
import { MessagesModule } from './messages.module';
import { Auth0Client } from '@app/auth/auth0/auth0.client';
import { MockLoggerModule } from '@fixtures/MockLoggerModule';
import { TestDataModule } from '@fixtures/data/test.data.module';

jest.mock('@app/auth/auth0/auth0.client');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
DbRoom,
DbSchema,
DbUser,
} from '@data/adapters/schema';
} from '@data/adapters/dynamodb/schema';

@Injectable()
export class DynamoDBAdapter {
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions services/api/src/data/data.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Global, Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { MessagesRepository } from '@entities/messages';
import databaseConfig from '@config/database.config';
import { DynamoDBMessagesRepository } from './repositories/dynamodb.messages.repository';
import { DynamoDBMessagesRepository } from './repositories/dynamodb/dynamodb.messages.repository';
import { RoomsRepository } from '@entities/rooms.repository';
import { UsersRepository } from '@entities/users';
import { DynamoDBUsersRepository } from './repositories/dynamodb.users.repository';
import { DynamoDBAdapter } from './adapters/dynamodb.adapter';
import { DynamoDBRoomsRepository } from './repositories/dynamodb.rooms.repository';
import { DynamoDBUsersRepository } from './repositories/dynamodb/dynamodb.users.repository';
import { DynamoDBAdapter } from './adapters/dynamodb/dynamodb.adapter';
import { DynamoDBRoomsRepository } from './repositories/dynamodb/dynamodb.rooms.repository';
import { MembershipsRepository } from '@entities/memberships.repository';
import { DynamoDBMembershipsRepository } from './repositories/dynamodb.memberships.repository';
import { DynamoDBMembershipsRepository } from './repositories/dynamodb/dynamodb.memberships.repository';

export const DatabaseConfigModule = ConfigModule.forFeature(databaseConfig);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { MembershipStatus } from '@entities/membership.entity';
import { CreateMembershipParams } from '@entities/memberships.repository';
import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository';
import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository';
import { RoomFactory } from '@fixtures/messages/room.factory';
import { UserFactory } from '@fixtures/messages/user.factory';
import { Test, TestingModule } from '@nestjs/testing';
import { DataModule } from '../data.module';
import { DynamoDBMembershipsRepository } from './dynamodb.memberships.repository';
import { MockLoggerModule } from '@fixtures/MockLoggerModule';
import { DynamoDBMembershipsRepository } from './dynamodb/dynamodb.memberships.repository';

type TestCase = {
name: 'DynamoDBMembershipsRepository' | 'TestMembershipsRepository';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DynamoDBMessagesRepository } from '@data/repositories/dynamodb.messages.repository';
import { DynamoDBMessagesRepository } from '@data/repositories/dynamodb/dynamodb.messages.repository';
import { DraftMessage } from '@entities/messages';
import { TestMessagesRepository } from '@fixtures/data/test.messages.repository';
import { TestMessagesRepository } from '@data/repositories/test/test.messages.repository';
import { RoomFactory } from '@fixtures/messages/room.factory';
import { UserFactory } from '@fixtures/messages/user.factory';
import { Test, TestingModule } from '@nestjs/testing';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DynamoDBRoomsRepository } from '@data/repositories/dynamodb.rooms.repository';
import { DynamoDBRoomsRepository } from '@data/repositories/dynamodb/dynamodb.rooms.repository';
import { ContentPolicy, JoinPolicy } from '@entities/room.entity';
import { CreateRoomParams } from '@entities/rooms.repository';
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { Test } from '@nestjs/testing';
import { DataModule } from '../data.module';
import { MockLoggerModule } from '@fixtures/MockLoggerModule';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DynamoDBUsersRepository } from '@data/repositories/dynamodb.users.repository';
import { DynamoDBUsersRepository } from '@data/repositories/dynamodb/dynamodb.users.repository';
import { userParamsFromAuth } from '@entities/users';
import { TestUsersRepository } from '@fixtures/data/test.users.repository';
import { TestUsersRepository } from '@data/repositories/test/test.users.repository';
import { Test, TestingModule } from '@nestjs/testing';
import { DataModule } from '../data.module';
import { MockLoggerModule } from '@fixtures/MockLoggerModule';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
} from '@entities/memberships.repository';
import { Injectable } from '@nestjs/common';
import { pick } from 'rambda';
import { DynamoDBAdapter } from '../adapters/dynamodb.adapter';
import { DbMembership } from '../adapters/schema';
import { DynamoDBAdapter } from '../../adapters/dynamodb/dynamodb.adapter';
import { DbMembership } from '../../adapters/dynamodb/schema';

@Injectable()
export class DynamoDBMembershipsRepository extends MembershipsRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { DraftMessage, SentMessage } from '@entities/messages';
import { MessagesRepository } from '@entities/messages';
import { Injectable } from '@nestjs/common';
import { pick } from 'rambda';
import { DynamoDBAdapter } from '../adapters/dynamodb.adapter';
import { DbMessage } from '../adapters/schema';
import { DynamoDBAdapter } from '../../adapters/dynamodb/dynamodb.adapter';
import { DbMessage } from '../../adapters/dynamodb/schema';

@Injectable()
export class DynamoDBMessagesRepository extends MessagesRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
} from '@entities/rooms.repository';
import { Injectable, NotFoundException } from '@nestjs/common';
import { pick } from 'rambda';
import { DynamoDBAdapter } from '../adapters/dynamodb.adapter';
import { DbRoom } from '../adapters/schema';
import { DynamoDBAdapter } from '../../adapters/dynamodb/dynamodb.adapter';
import { DbRoom } from '../../adapters/dynamodb/schema';

@Injectable()
export class DynamoDBRoomsRepository extends RoomsRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
} from '@entities/users';
import { Injectable, NotFoundException } from '@nestjs/common';
import { pick } from 'rambda';
import { DynamoDBAdapter } from '../adapters/dynamodb.adapter';
import { DbUser } from '../adapters/schema';
import { DynamoDBAdapter } from '../../adapters/dynamodb/dynamodb.adapter';
import { DbUser } from '../../adapters/dynamodb/schema';

@Injectable()
export class DynamoDBUsersRepository extends UsersRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { JoinPolicy } from '@entities/room.entity';
import { TestAuthService } from '@fixtures/auth/test-auth-service';
import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository';
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { RoomFactory } from '@fixtures/messages/room.factory';
import { UserFactory } from '@fixtures/messages/user.factory';
import { UnauthorizedException } from '@nestjs/common';
import { AppLogger } from '@app/app.logger';
import { Role } from '@usecases/auth.service';
import mock, { MockProxy } from 'jest-mock-extended/lib/Mock';
import { Dispatcher } from '@entities/messages/message';
import { TestUsersRepository } from '@fixtures/data/test.users.repository';
import { TestUsersRepository } from '@data/repositories/test/test.users.repository';
import { MembershipStatus } from '@entities/membership.entity';
import { ApproveRequestUseCase } from './approve-request';

Expand Down
6 changes: 3 additions & 3 deletions services/api/src/domain/usecases/memberships/invite.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JoinPolicy } from '@entities/room.entity';
import { TestAuthService } from '@fixtures/auth/test-auth-service';
import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository';
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { RoomFactory } from '@fixtures/messages/room.factory';
import { UserFactory } from '@fixtures/messages/user.factory';
import { UnauthorizedException } from '@nestjs/common';
Expand All @@ -10,7 +10,7 @@ import { Role } from '@usecases/auth.service';
import mock, { MockProxy } from 'jest-mock-extended/lib/Mock';
import { Dispatcher } from '@entities/messages/message';
import { InviteUseCase } from './invite';
import { TestUsersRepository } from '@fixtures/data/test.users.repository';
import { TestUsersRepository } from '@data/repositories/test/test.users.repository';
import { MembershipStatus } from '@entities/membership.entity';

describe('InviteUseCase', () => {
Expand Down
4 changes: 2 additions & 2 deletions services/api/src/domain/usecases/memberships/join.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JoinPolicy } from '@entities/room.entity';
import { TestAuthService } from '@fixtures/auth/test-auth-service';
import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository';
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { RoomFactory } from '@fixtures/messages/room.factory';
import { UserFactory } from '@fixtures/messages/user.factory';
import { UnauthorizedException } from '@nestjs/common';
Expand Down
4 changes: 2 additions & 2 deletions services/api/src/domain/usecases/memberships/leave.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JoinPolicy } from '@entities/room.entity';
import { TestAuthService } from '@fixtures/auth/test-auth-service';
import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository';
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { RoomFactory } from '@fixtures/messages/room.factory';
import { UserFactory } from '@fixtures/messages/user.factory';
import { AppLogger } from '@app/app.logger';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestMessagesRepository } from '@fixtures/data/test.messages.repository';
import { TestMessagesRepository } from '@data/repositories/test/test.messages.repository';
import { UserFactory } from '@fixtures/messages/user.factory';
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { RoomFactory } from '@fixtures/messages/room.factory';
import { GetMessagesUseCase } from './get-messages';
import { TestAuthService } from '@fixtures/auth/test-auth-service';
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/domain/usecases/messages/send.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UserFactory } from '@fixtures/messages/user.factory';
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { RoomFactory } from '@fixtures/messages/room.factory';
import { TestAuthService } from '@fixtures/auth/test-auth-service';
import { UnauthorizedException } from '@nestjs/common';
Expand Down
4 changes: 2 additions & 2 deletions services/api/src/domain/usecases/rooms/about-room.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestAuthService } from '@fixtures/auth/test-auth-service';
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { RoomFactory } from '@fixtures/messages/room.factory';
import { UserFactory } from '@fixtures/messages/user.factory';
import { UnauthorizedException } from '@nestjs/common';
Expand All @@ -8,7 +8,7 @@ import { Role } from '@usecases/auth.service';
import mock, { MockProxy } from 'jest-mock-extended/lib/Mock';
import { Dispatcher } from '@entities/messages/message';
import { AboutRoomUseCase } from './about-room';
import { TestUsersRepository } from '@fixtures/data/test.users.repository';
import { TestUsersRepository } from '@data/repositories/test/test.users.repository';

describe('AboutRoomUseCase', () => {
let aboutRoom: AboutRoomUseCase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestAuthService } from '@fixtures/auth/test-auth-service';
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { mock, MockProxy } from 'jest-mock-extended';
import { RoomFactory } from '@fixtures/messages/room.factory';
import { UserFactory } from '@fixtures/messages/user.factory';
Expand Down
4 changes: 2 additions & 2 deletions services/api/src/domain/usecases/rooms/create.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository';
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { UserFactory } from '@fixtures/messages/user.factory';
import { CreateRoomUseCase } from './create';
import { ContentPolicy, JoinPolicy } from '@entities/room.entity';
Expand Down
4 changes: 2 additions & 2 deletions services/api/src/domain/usecases/rooms/get.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { TestAuthService } from '@fixtures/auth/test-auth-service';
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { RoomFactory } from '@fixtures/messages/room.factory';
import { UserFactory } from '@fixtures/messages/user.factory';
import { GetRoomUseCase } from './get';
import { AppLogger } from '@app/app.logger';
import { Role } from '@usecases/auth.service';
import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository';
import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository';
import { MembershipStatus } from '@entities/membership.entity';

describe('GetRoomUseCase', () => {
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/domain/usecases/rooms/rename.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestAuthService } from '@fixtures/auth/test-auth-service';
import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository';
import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository';
import { RenameRoomUseCase } from './rename';
import { mock, MockProxy } from 'jest-mock-extended';
import { RoomFactory } from '@fixtures/messages/room.factory';
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/domain/usecases/users/rename.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RenameUserUseCase } from './rename';
import { mock, MockProxy } from 'jest-mock-extended';
import { RoomFactory } from '@fixtures/messages/room.factory';
import { UserFactory } from '@fixtures/messages/user.factory';
import { TestUsersRepository } from '@fixtures/data/test.users.repository';
import { TestUsersRepository } from '@data/repositories/test/test.users.repository';
import { Dispatcher } from '@entities/messages';

describe('RenameUserUseCase', () => {
Expand Down
8 changes: 4 additions & 4 deletions services/api/src/fixtures/data/test.data.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { MessagesRepository } from '@entities/messages';
import { RoomsRepository } from '@entities/rooms.repository';
import { UsersRepository } from '@entities/users';
import { Global, Module } from '@nestjs/common';
import { TestMembershipsRepository } from './test.memberships.repository';
import { TestMessagesRepository } from './test.messages.repository';
import { TestRoomsRepository } from './test.rooms.repository';
import { TestUsersRepository } from './test.users.repository';
import { TestMembershipsRepository } from '../../data/repositories/test/test.memberships.repository';
import { TestMessagesRepository } from '../../data/repositories/test/test.messages.repository';
import { TestRoomsRepository } from '../../data/repositories/test/test.rooms.repository';
import { TestUsersRepository } from '../../data/repositories/test/test.users.repository';

@Global()
@Module({
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/fixtures/setup-e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'tsconfig-paths/register';
import { DynamoDBAdapter } from '@data/adapters/dynamodb.adapter';
import { DynamoDBAdapter } from '@data/adapters/dynamodb/dynamodb.adapter';
import { DataModule } from '@data/data.module';
import { Test, TestingModule } from '@nestjs/testing';
import { LoggerModule } from '@app/app.logger';
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/fixtures/teardown-e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'tsconfig-paths/register';
import { DynamoDBAdapter } from '@data/adapters/dynamodb.adapter';
import { DynamoDBAdapter } from '@data/adapters/dynamodb/dynamodb.adapter';
import { DataModule } from '@data/data.module';
import { Test, TestingModule } from '@nestjs/testing';
import { LoggerModule } from '@app/app.logger';
Expand Down

0 comments on commit 6447452

Please sign in to comment.