Skip to content

Commit

Permalink
Merge pull request #89 from shimisnow/issue-88
Browse files Browse the repository at this point in the history
Move TypeORM entities from shared to individual services
  • Loading branch information
shimisnow authored Mar 5, 2024
2 parents f8ce8af + d41fae3 commit 2796524
Show file tree
Hide file tree
Showing 33 changed files with 42 additions and 41 deletions.
2 changes: 1 addition & 1 deletion apps/auth-service/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CacheModule } from '@nestjs/cache-manager';
import * as redisStore from 'cache-manager-redis-store';
import { JwtModule } from '@nestjs/jwt';
import { AuthModule } from './auth/auth.module';
import { UserAuthEntity } from '@shared/database/authentication/entities/user-auth.entity';
import { UserAuthEntity } from './database/entities/user-auth.entity';

@Module({
imports: [
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-service/src/app/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { UserAuthsRepository } from './repositories/user-auths/user-auths.reposi
import { UserAuthsRepositoryMock } from './mocks/user-auths-repository.mock';
import { JwtService } from '@nestjs/jwt';
import { getRepositoryToken } from '@nestjs/typeorm';
import { UserAuthEntity } from '@shared/database/authentication/entities/user-auth.entity';
import { UserAuthEntity } from '../database/entities/user-auth.entity';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Logger } from '@nestjs/common';

Expand Down
2 changes: 1 addition & 1 deletion apps/auth-service/src/app/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { getRepositoryToken } from '@nestjs/typeorm';
import jsonwebtoken, { JwtPayload } from 'jsonwebtoken';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { UserAuthEntity } from '@shared/database/authentication/entities/user-auth.entity';
import { UserAuthEntity } from '../database/entities/user-auth.entity';
import { UserPayload } from '@shared/authentication/payloads/user.payload';
import { AuthErrorNames } from '@shared/authentication/enums/auth-error-names.enum';
import { AuthErrorMessages } from '@shared/authentication/enums/auth-error-messages.enum';
Expand Down
4 changes: 2 additions & 2 deletions apps/auth-service/src/app/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import { UserPayload } from '@shared/authentication/payloads/user.payload';
import { CacheKeyPrefix } from '@shared/cache/enums/cache-key-prefix.enum';
import { UserAuthsRepository } from './repositories/user-auths/user-auths.repository';
import { SignUpSerializer } from './serializers/signup.serializer';
import { UserAuthEntity } from '@shared/database/authentication/entities/user-auth.entity';
import { UserAuthEntity } from '../database/entities/user-auth.entity';
import { LoginSerializer } from './serializers/login.serializer';
import { UserAuthStatusEnum } from '@shared/database/authentication/enums/user-auth-status.enum';
import { UserAuthStatusEnum } from '../database/enums/user-auth-status.enum';
import { RefreshSerializer } from './serializers/refresh.serializer';
import { LogoutSerializer } from './serializers/logout.serializer';
import { PasswordChangeSerializer } from './serializers/password-change.serializer';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UserAuthEntity } from '@shared/database/authentication/entities/user-auth.entity';
import { UserAuthStatusEnum } from '@shared/database/authentication/enums/user-auth-status.enum';
import { UserAuthEntity } from '../../database/entities/user-auth.entity';
import { UserAuthStatusEnum } from '../../database/enums/user-auth-status.enum';
import { InsertResult, QueryFailedError } from 'typeorm';

export class UserAuthsRepositoryMock {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserAuthEntity } from '@shared/database/authentication/entities/user-auth.entity';
import { UserAuthEntity } from '../../../database/entities/user-auth.entity';
import { UserAuthsRepository } from './user-auths.repository';

@Module({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { UserAuthEntity } from '@shared/database/authentication/entities/user-auth.entity';
import { UserAuthEntity } from '../../../database/entities/user-auth.entity';
import { InsertResult, Repository } from 'typeorm';

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import * as bcrypt from 'bcrypt';

/**
* TypeORM Entity with the user authentication information.
* WARNING: this entity is to be used only at the auth-service.
* It is located at the @shared just to centralize the entities code.
*/
@Entity({
name: 'user_auths',
Expand Down
3 changes: 2 additions & 1 deletion apps/financial-service-e2e/src/balance/balance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ describe('GET /balance', () => {
JWT_SECRET_KEY,
);

// request with a random balance to guarantee that is retrieved from cache and not from database
// request with a random balance to guarantee
// that it was retrieved from cache and not from database
await request(host)
.get(endpoint)
.query({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ describe('POST /transaction', () => {
JWT_SECRET_KEY,
);

// request with a random balance to guarantee that is retrieved from cache and not from database
// request with a random balance to guarantee
// that it was retrieved from cache and not from database
await request(host)
.get('/balance')
.query({
Expand All @@ -216,7 +217,8 @@ describe('POST /transaction', () => {
expect(body.cached).toBeTruthy();
});

// request with a random balance to guarantee that is retrieved from cache and not from database
// request with a random balance to guarantee
// that was retrieved from cache and not from database
await request(host)
.get('/balance')
.query({
Expand Down
6 changes: 3 additions & 3 deletions apps/financial-service/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { CacheModule } from '@nestjs/cache-manager';
import * as redisStore from 'cache-manager-redis-store';
import { JwtModule } from '@nestjs/jwt';
import { AccountEntity } from '@shared/database/financial/entities/account.entity';
import { BalanceEntity } from '@shared/database/financial/entities/balance.entity';
import { TransactionEntity } from '@shared/database/financial/entities/transaction.entity';
import { AccountEntity } from './database/entities/account.entity';
import { BalanceEntity } from './database/entities/balance.entity';
import { TransactionEntity } from './database/entities/transaction.entity';
import { TransactionModule } from './transaction/transaction.module';
import { BalanceModule } from './balance/balance.module';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { BalanceService } from './balance.service';
import { BalancesRepository } from './repositories/balances.repository';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { getRepositoryToken } from '@nestjs/typeorm';
import { BalanceEntity } from '@shared/database/financial/entities/balance.entity';
import { TransactionEntity } from '@shared/database/financial/entities/transaction.entity';
import { BalanceEntity } from '../database/entities/balance.entity';
import { TransactionEntity } from '../database/entities/transaction.entity';
import { ForbiddenException } from '@nestjs/common';
import { UserService } from '../user/user.service';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { BalanceEntity } from '@shared/database/financial/entities/balance.entity';
import { BalanceEntity } from '../../database/entities/balance.entity';
import { BalancesRepository } from './balances.repository';
import { TransactionEntity } from '@shared/database/financial/entities/transaction.entity';
import { TransactionEntity } from '../../database/entities/transaction.entity';

@Module({
imports: [TypeOrmModule.forFeature([BalanceEntity, TransactionEntity])],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { BalanceEntity } from '@shared/database/financial/entities/balance.entity';
import { TransactionEntity } from '@shared/database/financial/entities/transaction.entity';
import { BalanceEntity } from '../../database/entities/balance.entity';
import { TransactionEntity } from '../../database/entities/transaction.entity';
import { MoreThan, Repository } from 'typeorm';
import { BalanceDifferenceSerializer } from '../serializers/balance-difference.serializer';
import { AccountEntity } from '@shared/database/financial/entities/account.entity';
import { AccountEntity } from '../../database/entities/account.entity';

@Injectable()
export class BalancesRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { TransactionTypeEnum } from '@shared/database/financial/enums/transaction-type.enum';
import { TransactionTypeEnum } from '../../database/enums/transaction-type.enum';
import { IsEnum, IsNotEmpty, IsNumber, Min } from 'class-validator';

export class CreateTransactionBodyDto {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AccountEntity } from '@shared/database/financial/entities/account.entity';
import { AccountEntity } from '../../../database/entities/account.entity';
import { AccountsRepository } from './accounts.repository';

@Module({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AccountsRepository } from './accounts.repository';
import { getRepositoryToken } from '@nestjs/typeorm';
import { AccountEntity } from '@shared/database/financial/entities/account.entity';
import { AccountStatusEnum } from '@shared/database/financial/enums/account-status.enum';
import { AccountEntity } from '../../../database/entities/account.entity';
import { AccountStatusEnum } from '../../../database/enums/account-status.enum';

describe('AccountsRepository', () => {
let repository: AccountsRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { AccountEntity } from '@shared/database/financial/entities/account.entity';
import { AccountStatusEnum } from '@shared/database/financial/enums/account-status.enum';
import { AccountEntity } from '../../../database/entities/account.entity';
import { AccountStatusEnum } from '../../../database/enums/account-status.enum';

@Injectable()
export class AccountsRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TransactionTypeEnum } from '@shared/database/financial/enums/transaction-type.enum';
import { TransactionTypeEnum } from '../../../database/enums/transaction-type.enum';

/** Defines the information needed to create a pair transaction */
export class CreatePairTransactionBody {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { TransactionEntity } from '@shared/database/financial/entities/transaction.entity';
import { TransactionEntity } from '../../../database/entities/transaction.entity';
import { TransactionsRepository } from './transactions.repository';

@Module({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { QueryRunner, Repository } from 'typeorm';
import { TransactionEntity } from '@shared/database/financial/entities/transaction.entity';
import { TransactionTypeEnum } from '@shared/database/financial/enums/transaction-type.enum';
import { AccountEntity } from '@shared/database/financial/entities/account.entity';
import { TransactionEntity } from '../../../database/entities/transaction.entity';
import { TransactionTypeEnum } from '../../../database/enums/transaction-type.enum';
import { AccountEntity } from '../../../database/entities/account.entity';
import { CreatePairTransactionBody } from './create-pair-transaction.body';
import { CreatePairTransactionResult } from './create-pair-transaction.result';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import { TransactionController } from './transaction.controller';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { getRepositoryToken } from '@nestjs/typeorm';
import { TransactionEntity } from '@shared/database/financial/entities/transaction.entity';
import { TransactionEntity } from '../database/entities/transaction.entity';
import { TransactionsRepository } from './repositories/transactions/transactions.repository';
import { TransactionService } from './transaction.service';
import { BalanceService } from '../balance/balance.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { TransactionService } from './transaction.service';
import { TransactionsRepository } from './repositories/transactions/transactions.repository';
import { BalanceService } from '../balance/balance.service';
import { AccountsRepository } from './repositories/accounts/accounts.repository';
import { TransactionTypeEnum } from '@shared/database/financial/enums/transaction-type.enum';
import { TransactionTypeEnum } from '../database/enums/transaction-type.enum';
import {
ForbiddenException,
PreconditionFailedException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { AccountsRepository } from './repositories/accounts/accounts.repository'
import { Cache } from 'cache-manager';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { BalanceService } from '../balance/balance.service';
import { TransactionTypeEnum } from '@shared/database/financial/enums/transaction-type.enum';
import { TransactionTypeEnum } from '../database/enums/transaction-type.enum';
import { CacheKeyPrefix } from '@shared/cache/enums/cache-key-prefix.enum';
import { CreatePairTransactionResult } from './repositories/transactions/create-pair-transaction.result';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AccountEntity } from '@shared/database/financial/entities/account.entity';
import { AccountEntity } from '../../../database/entities/account.entity';
import { AccountsRepository } from './accounts.repository';

@Module({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { AccountEntity } from '@shared/database/financial/entities/account.entity';
import { AccountEntity } from '../../../database/entities/account.entity';

@Injectable()
export class AccountsRepository {
Expand Down
2 changes: 1 addition & 1 deletion apps/financial-service/src/app/user/user.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UserService } from './user.service';
import { getRepositoryToken } from '@nestjs/typeorm';
import { AccountEntity } from '@shared/database/financial/entities/account.entity';
import { AccountEntity } from '../database//entities/account.entity';
import { AccountsRepository } from './repositories/accounts/accounts.repository';

describe('user.service', () => {
Expand Down

0 comments on commit 2796524

Please sign in to comment.