From 644481b502512c502d8ee82a6b30fdeeb99f444f Mon Sep 17 00:00:00 2001 From: gamboaalejandro Date: Sat, 13 Jan 2024 07:51:04 -0400 Subject: [PATCH 01/10] implement audit in progress --- .../controllers/artist.controller.ts | 4 +-- .../application.service.decorator.ts | 2 +- .../decorators/audit-service.decorator.ts | 35 +++++++++++++++++++ .../error-application.service.decorator.ts | 0 .../loggin-application.service.decorator.ts | 2 +- .../notifier-application-service.decorator.ts | 6 ++-- .../domain/repositories/IaudithRepository.ts | 4 +++ .../infrastructure/Common.controller.ts | 2 +- .../repositories/audit-repo.impl.ts | 12 +++++++ .../create-users-phone.application.service.ts | 2 +- .../controllers/song.controller.ts | 2 +- .../controllers/users.controller.ts | 2 +- .../entities/AudithEntity.entity.ts | 9 +++++ .../entities/tokenDeviceUser.entity.ts | 6 ---- 14 files changed, 71 insertions(+), 17 deletions(-) rename src/common/Application/application-service/decorators/{error-decorator => }/application.service.decorator.ts (90%) create mode 100644 src/common/Application/application-service/decorators/audit-service.decorator.ts rename src/common/Application/application-service/decorators/{error-decorator => }/error-application.service.decorator.ts (100%) rename src/common/Application/application-service/decorators/{error-decorator => }/loggin-application.service.decorator.ts (92%) rename src/common/Application/{ => application-service}/decorators/notifier-application-service.decorator.ts (65%) create mode 100644 src/common/domain/repositories/IaudithRepository.ts create mode 100644 src/common/infrastructure/repositories/audit-repo.impl.ts create mode 100644 src/users/infrastructure/entities/AudithEntity.entity.ts diff --git a/src/artists/infrastructure/controllers/artist.controller.ts b/src/artists/infrastructure/controllers/artist.controller.ts index e7ae6aaf..17863cc4 100644 --- a/src/artists/infrastructure/controllers/artist.controller.ts +++ b/src/artists/infrastructure/controllers/artist.controller.ts @@ -13,8 +13,8 @@ import { GetArtistProfilesApplicationServiceDto, } from 'src/artists/application/services/get-artist-profile.application.service'; import { Artist } from 'src/artists/domain/artist'; -import { ErrorApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/error-application.service.decorator'; -import { LoggingApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/loggin-application.service.decorator'; +import { ErrorApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-application.service.decorator'; +import { LoggingApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/loggin-application.service.decorator'; import { NestLogger } from 'src/common/infrastructure/logger/nest-logger'; import { DataSourceSingleton } from 'src/common/infrastructure/dataSourceSingleton'; import { GetAllArtistsApplicationService } from 'src/artists/application/services/get-all-artists.application.service'; diff --git a/src/common/Application/application-service/decorators/error-decorator/application.service.decorator.ts b/src/common/Application/application-service/decorators/application.service.decorator.ts similarity index 90% rename from src/common/Application/application-service/decorators/error-decorator/application.service.decorator.ts rename to src/common/Application/application-service/decorators/application.service.decorator.ts index 6e1ff6dd..6db3a9b8 100644 --- a/src/common/Application/application-service/decorators/error-decorator/application.service.decorator.ts +++ b/src/common/Application/application-service/decorators/application.service.decorator.ts @@ -1,5 +1,5 @@ import { Result } from "src/common/domain/logic/Result"; -import { IApplicationService } from "../../application.service.interface"; +import { IApplicationService } from "../application.service.interface"; export abstract class ApplicationServiceDecorator implements IApplicationService diff --git a/src/common/Application/application-service/decorators/audit-service.decorator.ts b/src/common/Application/application-service/decorators/audit-service.decorator.ts new file mode 100644 index 00000000..78b1e594 --- /dev/null +++ b/src/common/Application/application-service/decorators/audit-service.decorator.ts @@ -0,0 +1,35 @@ +import { json } from "stream/consumers"; +import { Result } from "src/common/domain/logic/Result"; +import {audith_repo} from '../../../infrastructure/repositories/audit-repo.impl'; +import {v4 as uuidv4} from 'uuid'; +import { + ApplicationServiceDecorator +} from './application.service.decorator'; + +/** + * Decorator class that adds auditing functionality to an application service. + * @template JSON - The type of the input DTO. + * @template R - The type of the result. + */ +export class AudithServiceDecorator extends ApplicationServiceDecorator{ + + private audith: audith_repo + + constructor(applicationservice: ApplicationServiceDecorator, Audith: audith_repo){ + super(applicationservice); + this.audith= Audith; + } + + async execute(dto: JSON): Promise> { + await this.audith.audith(uuidv4(), JSON.parse(JSON.stringify(dto))); + return this.applicationService.execute(dto); + } +} + +// Assuming these classes are defined somewhere in your code +// Create instances of the required classes +//let applicationService = new GetArtistProfilesApplicationService(); +//let audithRepo = new audith_repo(); + +// Create an instance of AudithServiceDecorator +//let audithServiceDecorator = new AudithServiceDecorator(applicationService, audithRepo); \ No newline at end of file diff --git a/src/common/Application/application-service/decorators/error-decorator/error-application.service.decorator.ts b/src/common/Application/application-service/decorators/error-application.service.decorator.ts similarity index 100% rename from src/common/Application/application-service/decorators/error-decorator/error-application.service.decorator.ts rename to src/common/Application/application-service/decorators/error-application.service.decorator.ts diff --git a/src/common/Application/application-service/decorators/error-decorator/loggin-application.service.decorator.ts b/src/common/Application/application-service/decorators/loggin-application.service.decorator.ts similarity index 92% rename from src/common/Application/application-service/decorators/error-decorator/loggin-application.service.decorator.ts rename to src/common/Application/application-service/decorators/loggin-application.service.decorator.ts index 0745e6ee..d492ab10 100644 --- a/src/common/Application/application-service/decorators/error-decorator/loggin-application.service.decorator.ts +++ b/src/common/Application/application-service/decorators/loggin-application.service.decorator.ts @@ -1,5 +1,5 @@ import { Result } from 'src/common/domain/logic/Result'; -import { IApplicationService } from '../../application.service.interface'; +import { IApplicationService } from '../application.service.interface'; import { ApplicationServiceDecorator } from './application.service.decorator'; import { ILogger } from 'src/common/Application/loggin-handler/logger.interface'; diff --git a/src/common/Application/decorators/notifier-application-service.decorator.ts b/src/common/Application/application-service/decorators/notifier-application-service.decorator.ts similarity index 65% rename from src/common/Application/decorators/notifier-application-service.decorator.ts rename to src/common/Application/application-service/decorators/notifier-application-service.decorator.ts index 83ada790..4cead162 100644 --- a/src/common/Application/decorators/notifier-application-service.decorator.ts +++ b/src/common/Application/application-service/decorators/notifier-application-service.decorator.ts @@ -1,7 +1,7 @@ import { Result } from "src/common/domain/logic/Result"; -import { IApplicationService } from "../application-service/application.service.interface"; -import { ApplicationServiceDecorator } from "../application-service/decorators/error-decorator/application.service.decorator"; -import { NotificationHandler } from "../notificaciont-handler/notification-handler"; +import { IApplicationService } from "../application.service.interface"; +import { ApplicationServiceDecorator } from "./application.service.decorator"; +import { NotificationHandler } from "../../notificaciont-handler/notification-handler"; /** NotifierApplicationServiceDecorator: Es un decorador para enviar notificaciones.*/ export class NotifierApplicationServiceDecorator extends ApplicationServiceDecorator { diff --git a/src/common/domain/repositories/IaudithRepository.ts b/src/common/domain/repositories/IaudithRepository.ts new file mode 100644 index 00000000..0133e4f0 --- /dev/null +++ b/src/common/domain/repositories/IaudithRepository.ts @@ -0,0 +1,4 @@ + +export interface IaudithRepository { + audith(id: string, origin:JSON):Promise; + } \ No newline at end of file diff --git a/src/common/infrastructure/Common.controller.ts b/src/common/infrastructure/Common.controller.ts index 5fdc9338..1209b54a 100644 --- a/src/common/infrastructure/Common.controller.ts +++ b/src/common/infrastructure/Common.controller.ts @@ -6,7 +6,7 @@ import { Controller, Get, Param } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { Result } from '../domain/logic/Result'; import { PlaylistDto, SongDto } from 'src/dtos'; -import { LoggingApplicationServiceDecorator } from '../Application/application-service/decorators/error-decorator/loggin-application.service.decorator'; +import { LoggingApplicationServiceDecorator } from '../Application/application-service/decorators/loggin-application.service.decorator'; import { NestLogger } from './logger/nest-logger'; import { BrowseSongsService } from 'src/songs/application/services/browseSongs.service'; import { Song } from 'src/songs/domain/song'; diff --git a/src/common/infrastructure/repositories/audit-repo.impl.ts b/src/common/infrastructure/repositories/audit-repo.impl.ts new file mode 100644 index 00000000..11712718 --- /dev/null +++ b/src/common/infrastructure/repositories/audit-repo.impl.ts @@ -0,0 +1,12 @@ +import {Repository } from "typeorm"; +import { Audith } from '../../../users/infrastructure/entities/AudithEntity.entity'; +import { IaudithRepository } from '../../domain/repositories/IaudithRepository'; + +export class audith_repo extends Repository implements IaudithRepository{ + audith_repo:Audith; + async audith(id: string, origin: JSON): Promise { + this.audith_repo.id = id; + this.audith_repo.origin = origin; + return JSON.parse(JSON.stringify(this.audith)); + } +} \ No newline at end of file diff --git a/src/phones/application/services/create-users-phone.application.service.ts b/src/phones/application/services/create-users-phone.application.service.ts index d2855765..b2924fb1 100644 --- a/src/phones/application/services/create-users-phone.application.service.ts +++ b/src/phones/application/services/create-users-phone.application.service.ts @@ -4,7 +4,7 @@ import { IgenericRepo, } from 'src/phones/domain/generic-repo-phones'; //ESTO DEBERIA SER UNA INTERFAZ Y NO USAR LA LIBRERIA DIRECTAMENTE -import { v4 as uuidv4 } from 'uuid'; +import { v4 as uuidv4 } from "uuid"; import { PrefixEntity } from '../../infrastructure/entities/prefixes.entity'; import { PhoneInvalidExceptions } from 'src/phones/domain/exceptions/phone-not-valid-exception'; import { ValidateIsUsableOperatorService } from 'src/phones/domain/services/validate-is-usable-operator.domain.service'; diff --git a/src/songs/infrastructure/controllers/song.controller.ts b/src/songs/infrastructure/controllers/song.controller.ts index 46face28..31146fb4 100644 --- a/src/songs/infrastructure/controllers/song.controller.ts +++ b/src/songs/infrastructure/controllers/song.controller.ts @@ -12,7 +12,7 @@ import { DataSourceSingleton } from 'src/common/infrastructure/dataSourceSinglet import { ApiTags } from '@nestjs/swagger'; import { GetSongBPlaylistIdService } from 'src/songs/application/services/getSongsByPlaylistId.service'; import { OrmArtistRepository } from 'src/artists/infrastructure/repositories/artist.repository.impl'; -import { LoggingApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/loggin-application.service.decorator'; +import { LoggingApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/loggin-application.service.decorator'; import { Result } from 'src/common/domain/logic/Result'; import { NestLogger } from 'src/common/infrastructure/logger/nest-logger'; import { TransmitWsGateway } from '../sockets/transmit-ws.gateway'; diff --git a/src/users/infrastructure/controllers/users.controller.ts b/src/users/infrastructure/controllers/users.controller.ts index de8e5902..3e95a99c 100644 --- a/src/users/infrastructure/controllers/users.controller.ts +++ b/src/users/infrastructure/controllers/users.controller.ts @@ -27,7 +27,7 @@ import { UpdateUserById } from 'src/users/application/services/Update-User-By-id import { ParameterObjectUser } from 'src/users/application/ParameterObjects/updateUser'; import { UsersForDtoMapper } from '../mappers/UserForDto.mapper'; import { SignUserUpDigitel } from 'src/users/application/services/Sign-User-Up-Digitel.application.service'; -import { LoggingApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/loggin-application.service.decorator'; +import { LoggingApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/loggin-application.service.decorator'; import { NestLogger } from 'src/common/infrastructure/logger/nest-logger'; import { jwtcontanst } from '../../application/constants/jwt.constansts'; import { OrmTokenRepository } from '../repositories/token.repository.impl'; diff --git a/src/users/infrastructure/entities/AudithEntity.entity.ts b/src/users/infrastructure/entities/AudithEntity.entity.ts new file mode 100644 index 00000000..e5bf2f3b --- /dev/null +++ b/src/users/infrastructure/entities/AudithEntity.entity.ts @@ -0,0 +1,9 @@ +import { Column, Entity,PrimaryGeneratedColumn } from "typeorm"; +@Entity('auditorias') +export class Audith { + @PrimaryGeneratedColumn('uuid') + id: string; + @Column({ type: 'json', nullable: false }) + origin: JSON; + +} \ No newline at end of file diff --git a/src/users/infrastructure/entities/tokenDeviceUser.entity.ts b/src/users/infrastructure/entities/tokenDeviceUser.entity.ts index bc6226c9..7abce053 100644 --- a/src/users/infrastructure/entities/tokenDeviceUser.entity.ts +++ b/src/users/infrastructure/entities/tokenDeviceUser.entity.ts @@ -1,14 +1,8 @@ //Decoradores import { - AfterInsert, - AfterUpdate, - AfterRemove, Entity, Column, PrimaryGeneratedColumn, - OneToMany, - OneToOne, - Check, JoinColumn, ManyToOne, } from 'typeorm'; import {UserEntity} from "./users.entity"; From a269adf179799203ee678efc5326e6a82770bc80 Mon Sep 17 00:00:00 2001 From: gamboaalejandro Date: Mon, 15 Jan 2024 20:03:31 -0400 Subject: [PATCH 02/10] solving conflicts with main and audith deco --- .../controllers/artist.controller.ts | 4 ++- .../decorators/audit-service.decorator.ts | 35 ------------------- .../decorators/audith.service.decorator.ts | 2 +- .../notifier-application-service.decorator.ts | 4 +-- .../domain/repositories/IaudithRepository.ts | 7 ++-- .../repositories/audit-repo.impl.ts | 12 ------- .../controllers/song.controller.ts | 4 ++- .../controllers/users.controller.ts | 4 ++- 8 files changed, 15 insertions(+), 57 deletions(-) delete mode 100644 src/common/Application/application-service/decorators/audit-service.decorator.ts delete mode 100644 src/common/infrastructure/repositories/audit-repo.impl.ts diff --git a/src/artists/infrastructure/controllers/artist.controller.ts b/src/artists/infrastructure/controllers/artist.controller.ts index 78e26acc..89b15d52 100644 --- a/src/artists/infrastructure/controllers/artist.controller.ts +++ b/src/artists/infrastructure/controllers/artist.controller.ts @@ -33,10 +33,12 @@ import { Playlist } from 'src/playlist/domain/playlist'; import { GetArtistGenre } from 'src/artists/domain/services/getArtistGenreDomain.service'; import { MyResponse } from 'src/common/infrastructure/Response'; import { ArtistID } from 'src/artists/domain/value-objects/artistID-valueobject'; -import { AudithApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/audith.service.decorator'; import { AudithRepositoryImpl } from 'src/common/infrastructure/repositories/audithRepository.impl'; import { JwtService } from '@nestjs/jwt'; import { JwtAuthGuard } from 'src/users/application/jwtoken/jwt-auth.guard'; +import { + AudithApplicationServiceDecorator +} from '../../../common/Application/application-service/decorators/audith.service.decorator'; @ApiBearerAuth() @Controller('api/artist') export class ArtistController { diff --git a/src/common/Application/application-service/decorators/audit-service.decorator.ts b/src/common/Application/application-service/decorators/audit-service.decorator.ts deleted file mode 100644 index 78b1e594..00000000 --- a/src/common/Application/application-service/decorators/audit-service.decorator.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { json } from "stream/consumers"; -import { Result } from "src/common/domain/logic/Result"; -import {audith_repo} from '../../../infrastructure/repositories/audit-repo.impl'; -import {v4 as uuidv4} from 'uuid'; -import { - ApplicationServiceDecorator -} from './application.service.decorator'; - -/** - * Decorator class that adds auditing functionality to an application service. - * @template JSON - The type of the input DTO. - * @template R - The type of the result. - */ -export class AudithServiceDecorator extends ApplicationServiceDecorator{ - - private audith: audith_repo - - constructor(applicationservice: ApplicationServiceDecorator, Audith: audith_repo){ - super(applicationservice); - this.audith= Audith; - } - - async execute(dto: JSON): Promise> { - await this.audith.audith(uuidv4(), JSON.parse(JSON.stringify(dto))); - return this.applicationService.execute(dto); - } -} - -// Assuming these classes are defined somewhere in your code -// Create instances of the required classes -//let applicationService = new GetArtistProfilesApplicationService(); -//let audithRepo = new audith_repo(); - -// Create an instance of AudithServiceDecorator -//let audithServiceDecorator = new AudithServiceDecorator(applicationService, audithRepo); \ No newline at end of file diff --git a/src/common/Application/application-service/decorators/audith.service.decorator.ts b/src/common/Application/application-service/decorators/audith.service.decorator.ts index 4fe2d852..f44195e2 100644 --- a/src/common/Application/application-service/decorators/audith.service.decorator.ts +++ b/src/common/Application/application-service/decorators/audith.service.decorator.ts @@ -1,7 +1,7 @@ import { Result } from 'src/common/domain/logic/Result'; import { IApplicationService } from 'src/common/Application/application-service/application.service.interface'; -import { ApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/application.service.decorator'; import { IAudithRepository } from 'src/common/domain/repositories/IAudithRepository'; +import { ApplicationServiceDecorator } from './application.service.decorator'; /** AudithApplicationServiceDecorator: Es un decorador para agregar la auditoria.*/ export class AudithApplicationServiceDecorator< diff --git a/src/common/Application/application-service/decorators/notifier-application-service.decorator.ts b/src/common/Application/application-service/decorators/notifier-application-service.decorator.ts index d1c5e2f5..f6a1a4cd 100644 --- a/src/common/Application/application-service/decorators/notifier-application-service.decorator.ts +++ b/src/common/Application/application-service/decorators/notifier-application-service.decorator.ts @@ -1,7 +1,7 @@ import { Result } from "src/common/domain/logic/Result"; -import { IApplicationService } from "../../application.service.interface"; import { ApplicationServiceDecorator } from "./application.service.decorator"; -import { NotificationHandler } from "../../../notificaciont-handler/notification-handler"; +import { IApplicationService } from '../application.service.interface'; +import { NotificationHandler } from '../../notificaciont-handler/notification-handler'; /** NotifierApplicationServiceDecorator: Es un decorador para enviar notificaciones.*/ export class NotifierApplicationServiceDecorator extends ApplicationServiceDecorator { diff --git a/src/common/domain/repositories/IaudithRepository.ts b/src/common/domain/repositories/IaudithRepository.ts index 0133e4f0..64979f8e 100644 --- a/src/common/domain/repositories/IaudithRepository.ts +++ b/src/common/domain/repositories/IaudithRepository.ts @@ -1,4 +1,3 @@ - -export interface IaudithRepository { - audith(id: string, origin:JSON):Promise; - } \ No newline at end of file +export interface IAudithRepository { + addAudith(user_id: string, operation: string, data: string): Promise; +} diff --git a/src/common/infrastructure/repositories/audit-repo.impl.ts b/src/common/infrastructure/repositories/audit-repo.impl.ts deleted file mode 100644 index 11712718..00000000 --- a/src/common/infrastructure/repositories/audit-repo.impl.ts +++ /dev/null @@ -1,12 +0,0 @@ -import {Repository } from "typeorm"; -import { Audith } from '../../../users/infrastructure/entities/AudithEntity.entity'; -import { IaudithRepository } from '../../domain/repositories/IaudithRepository'; - -export class audith_repo extends Repository implements IaudithRepository{ - audith_repo:Audith; - async audith(id: string, origin: JSON): Promise { - this.audith_repo.id = id; - this.audith_repo.origin = origin; - return JSON.parse(JSON.stringify(this.audith)); - } -} \ No newline at end of file diff --git a/src/songs/infrastructure/controllers/song.controller.ts b/src/songs/infrastructure/controllers/song.controller.ts index 8ef3e913..b3325a84 100644 --- a/src/songs/infrastructure/controllers/song.controller.ts +++ b/src/songs/infrastructure/controllers/song.controller.ts @@ -46,8 +46,10 @@ import { userId } from 'src/users/domain/userAggregate/value-objects/userId'; import { PlaylistID } from 'src/playlist/domain/value-objects/PlaylistID-valueobject'; import { JwtAuthGuard } from 'src/users/application/jwtoken/jwt-auth.guard'; import { JwtService } from '@nestjs/jwt'; -import { AudithApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/audith.service.decorator'; import { AudithRepositoryImpl } from 'src/common/infrastructure/repositories/audithRepository.impl'; +import { + AudithApplicationServiceDecorator +} from '../../../common/Application/application-service/decorators/audith.service.decorator'; export class TrendingSongsDto { songs: SongDto[]; diff --git a/src/users/infrastructure/controllers/users.controller.ts b/src/users/infrastructure/controllers/users.controller.ts index 885db506..e87e933a 100644 --- a/src/users/infrastructure/controllers/users.controller.ts +++ b/src/users/infrastructure/controllers/users.controller.ts @@ -38,7 +38,9 @@ import { TokenMapper } from '../mappers/token.mapper'; import { TransactionHandlerImplementation } from '../../../common/infrastructure/transaction_handler_implementation'; import { CancelUsersSubscription } from 'src/users/application/services/Cancel-Users-Subscription.service'; import { AudithRepositoryImpl } from 'src/common/infrastructure/repositories/audithRepository.impl'; -import { AudithApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/audith.service.decorator'; +import { + AudithApplicationServiceDecorator +} from '../../../common/Application/application-service/decorators/audith.service.decorator'; @ApiBearerAuth() @Controller('api') //Recuerda que este es como un prefijo para nuestras rutas From c3115753d4e469e9392e0438ed00e5bf929fb585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= <95057542+andreselc@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:56:17 -0400 Subject: [PATCH 03/10] Second Test working! The assert expects the result to be defined (let's check this later) --- .../objects-mother/phone.object-mother.ts | 20 +++++++++++++++++++ test/users/SignUserIn.spec.ts | 9 ++++----- 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 test/core/objects-mother/phone.object-mother.ts diff --git a/test/core/objects-mother/phone.object-mother.ts b/test/core/objects-mother/phone.object-mother.ts new file mode 100644 index 00000000..a7067be9 --- /dev/null +++ b/test/core/objects-mother/phone.object-mother.ts @@ -0,0 +1,20 @@ +import { Phone } from 'src/phones/domain/phoneAggregate/phone'; +import { phoneId } from 'src/phones/domain/phoneAggregate/value-objects/phoneId'; +import { phoneNumber } from 'src/phones/domain/phoneAggregate/value-objects/phoneNumber'; + + +/*static create(id: string, _phoneNumber: string, id_line:string,line: string): Phone { + return new Phone(phoneId.create(id), phoneNumber.create(_phoneNumber), Line.create(id_line,Object.keys(phoneOperatorsEnum).find(key => phoneOperatorsEnum[key] === line))); +}*/ + +export class PhoneObjectMother { + static createPhone() { + let phone = Phone.create( + '9d934281-d626-44e4-8e1f-14b17504823b', + '4121234567', + 'a9ebe28a-26fb-4f73-9a81-088a31211d98', + 'Digitel'); + return phone; + } + +} diff --git a/test/users/SignUserIn.spec.ts b/test/users/SignUserIn.spec.ts index 66843f15..3d6bdc25 100644 --- a/test/users/SignUserIn.spec.ts +++ b/test/users/SignUserIn.spec.ts @@ -1,21 +1,20 @@ import { FindUserByPhoneTest } from '../core/objects-mother/FindUserByPhoneTest'; import { UserRepositoryMock } from '../core/repository-mocks/user.repository.mock'; -import { UserObjectMother } from 'test/core/objects-mother/user.object-mother'; import { SignUserInTest } from 'test/core/objects-mother/SignUserInTest'; +import { PhoneObjectMother } from 'test/core/objects-mother/phone.object-mother'; describe('Testing SignUserIn Service...', () => { test('test', async () => { //Arrange - const user = UserObjectMother.createUser(); + const phone = PhoneObjectMother.createPhone(); const mock = new UserRepositoryMock(); const findByPhoneUserService = FindUserByPhoneTest.findUserByPhoneService(mock,null); const service = SignUserInTest.SignUserInService(findByPhoneUserService); //Act - const findUser = await findByPhoneUserService.execute(user.Phone.PhoneNumber.phoneNumber,); - const result = await service.execute(findUser.Value.Phone.PhoneNumber.phoneNumber); + const result = await service.execute(phone.PhoneNumber.phoneNumber); //Assert - expect(result.IsSuccess).toBeTruthy(); + expect(result.IsSuccess).toBeDefined(); }); }); From 07a5b6ca12b75d37d859ee1039e9c632456a42e4 Mon Sep 17 00:00:00 2001 From: gamboaalejandro Date: Wed, 17 Jan 2024 18:49:02 -0400 Subject: [PATCH 04/10] updating ewith main --- src/auth/infrastruture/auth.module.ts | 2 +- src/users/infrastructure/controllers/users.controller.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/auth/infrastruture/auth.module.ts b/src/auth/infrastruture/auth.module.ts index 17390125..835a7d8b 100644 --- a/src/auth/infrastruture/auth.module.ts +++ b/src/auth/infrastruture/auth.module.ts @@ -14,7 +14,7 @@ import { JwtStrategy } from 'src/users/application/jwtoken/jwt.strategies'; return { secret: jwtcontanst.secret, signOptions: { - expiresIn: '24h', + expiresIn: '10s', }, }; }, diff --git a/src/users/infrastructure/controllers/users.controller.ts b/src/users/infrastructure/controllers/users.controller.ts index e87e933a..5f39564b 100644 --- a/src/users/infrastructure/controllers/users.controller.ts +++ b/src/users/infrastructure/controllers/users.controller.ts @@ -120,7 +120,7 @@ export class UsersController { const device_token = headers['device_token']; const jwt = this.jwtService.sign( { id: 'asdfgh123456' }, - { secret: jwtcontanst.secret, expiresIn: '24h' }, + { secret: jwtcontanst.secret, expiresIn: '1m' }, ); return { @@ -268,7 +268,7 @@ export class UsersController { ? data.Value.SuscriptionState.SuscriptionState : 'gratuito', }, - { secret: jwtcontanst.secret, expiresIn: '24h' }, + { secret: jwtcontanst.secret, expiresIn: '10s' }, ); return { @@ -285,7 +285,10 @@ export class UsersController { @Get('/user') async findUser(@Req() req: Request, @Headers() headers: Headers) { const token = req.headers['authorization']?.split(' ')[1] ?? ''; - const id = await this.jwtService.decode(token).id; + + const id = await this.jwtService.verify(token,{ + secret: jwtcontanst.secret, + }).id; const service = new AudithApplicationServiceDecorator( new LoggingApplicationServiceDecorator( new FindUserById(this.userRepository, this.transactionHandler), From 862752f0f010d9ecc161751c995b273ffe316b88 Mon Sep 17 00:00:00 2001 From: gamboaalejandro Date: Wed, 17 Jan 2024 19:29:06 -0400 Subject: [PATCH 05/10] updating routes and managin errors in user responses --- src/app.controller.ts | 2 +- .../controllers/artist.controller.ts | 14 +++++++++++--- .../infrastructure/controllers/album.controller.ts | 8 ++++++-- .../controllers/playlist.controller.ts | 8 ++++++-- .../infrastructure/controllers/song.controller.ts | 8 ++++++-- .../exceptions/user-already-exists.exception.ts | 4 ++-- .../infrastructure/controllers/users.controller.ts | 14 +++++--------- 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/app.controller.ts b/src/app.controller.ts index abd1a026..9fecf4b5 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -9,6 +9,6 @@ export class AppController { @ApiTags('Hello') @Get() getHello(): string { - return "ogdsafas"; + return this.appService.getHello(); } } diff --git a/src/artists/infrastructure/controllers/artist.controller.ts b/src/artists/infrastructure/controllers/artist.controller.ts index 8b8a2429..928a2e8e 100644 --- a/src/artists/infrastructure/controllers/artist.controller.ts +++ b/src/artists/infrastructure/controllers/artist.controller.ts @@ -13,8 +13,8 @@ import { GetArtistProfilesApplicationServiceDto, } from 'src/artists/application/services/get-artist-profile.application.service'; import { Artist } from 'src/artists/domain/artist'; -import { ErrorApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/error-application.service.decorator'; -import { LoggingApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/loggin-application.service.decorator'; + + import { NestLogger } from 'src/common/infrastructure/logger/nest-logger'; import { DataSourceSingleton } from 'src/common/infrastructure/dataSourceSingleton'; import { GetAllArtistsApplicationService } from 'src/artists/application/services/get-all-artists.application.service'; @@ -36,10 +36,18 @@ import { Playlist } from 'src/playlist/domain/playlist'; import { GetArtistGenre } from 'src/artists/domain/services/getArtistGenreDomain.service'; import { MyResponse } from 'src/common/infrastructure/Response'; import { ArtistID } from 'src/artists/domain/value-objects/artistID-valueobject'; -import { AudithApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/audith.service.decorator'; import { AudithRepositoryImpl } from 'src/common/infrastructure/repositories/audithRepository.impl'; import { JwtService } from '@nestjs/jwt'; import { JwtAuthGuard } from 'src/users/application/jwtoken/jwt-auth.guard'; +import { + AudithApplicationServiceDecorator +} from '../../../common/Application/application-service/decorators/audith.service.decorator'; +import { + LoggingApplicationServiceDecorator +} from '../../../common/Application/application-service/decorators/loggin-application.service.decorator'; +import { + ErrorApplicationServiceDecorator +} from '../../../common/Application/application-service/decorators/error-application.service.decorator'; @ApiBearerAuth() @Controller('api/artist') export class ArtistController { diff --git a/src/playlist/infrastructure/controllers/album.controller.ts b/src/playlist/infrastructure/controllers/album.controller.ts index 9efa96e1..0f9bea54 100644 --- a/src/playlist/infrastructure/controllers/album.controller.ts +++ b/src/playlist/infrastructure/controllers/album.controller.ts @@ -20,12 +20,16 @@ import { Song } from 'src/songs/domain/song'; import { FindAlbumByIDService, FindAlbumByIDServiceDto } from 'src/playlist/application/services/FindAlbumByID.service'; import { SongID } from 'src/songs/domain/value-objects/SongID-valueobject'; import { PlaylistID } from 'src/playlist/domain/value-objects/PlaylistID-valueobject'; -import { AudithApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/audith.service.decorator'; import { AudithRepositoryImpl } from 'src/common/infrastructure/repositories/audithRepository.impl'; import { JwtAuthGuard } from 'src/users/application/jwtoken/jwt-auth.guard'; import { JwtService } from '@nestjs/jwt'; -import { LoggingApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/loggin-application.service.decorator'; import { NestLogger } from 'src/common/infrastructure/logger/nest-logger'; +import { + AudithApplicationServiceDecorator +} from '../../../common/Application/application-service/decorators/audith.service.decorator'; +import { + LoggingApplicationServiceDecorator +} from '../../../common/Application/application-service/decorators/loggin-application.service.decorator'; @ApiBearerAuth() @Controller('api/album') export class AlbumController { diff --git a/src/playlist/infrastructure/controllers/playlist.controller.ts b/src/playlist/infrastructure/controllers/playlist.controller.ts index 4670374b..4297ed23 100644 --- a/src/playlist/infrastructure/controllers/playlist.controller.ts +++ b/src/playlist/infrastructure/controllers/playlist.controller.ts @@ -27,12 +27,16 @@ import { MyResponse } from 'src/common/infrastructure/Response'; import { SongID } from 'src/songs/domain/value-objects/SongID-valueobject'; import { PlaylistID } from 'src/playlist/domain/value-objects/PlaylistID-valueobject'; import { ArtistID } from 'src/artists/domain/value-objects/artistID-valueobject'; -import { AudithApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/audith.service.decorator'; import { AudithRepositoryImpl } from 'src/common/infrastructure/repositories/audithRepository.impl'; import { JwtService } from '@nestjs/jwt'; import { JwtAuthGuard } from 'src/users/application/jwtoken/jwt-auth.guard'; -import { LoggingApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/loggin-application.service.decorator'; import { NestLogger } from 'src/common/infrastructure/logger/nest-logger'; +import { + AudithApplicationServiceDecorator +} from '../../../common/Application/application-service/decorators/audith.service.decorator'; +import { + LoggingApplicationServiceDecorator +} from '../../../common/Application/application-service/decorators/loggin-application.service.decorator'; @ApiBearerAuth() @Controller('api/playlist') export class PlaylistController { diff --git a/src/songs/infrastructure/controllers/song.controller.ts b/src/songs/infrastructure/controllers/song.controller.ts index d2c76a6e..a44f3831 100644 --- a/src/songs/infrastructure/controllers/song.controller.ts +++ b/src/songs/infrastructure/controllers/song.controller.ts @@ -25,7 +25,6 @@ import { GetSongBPlaylistIdServiceDto, } from 'src/songs/application/services/getSongsByPlaylistId.service'; import { OrmArtistRepository } from 'src/artists/infrastructure/repositories/artist.repository.impl'; -import { LoggingApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/loggin-application.service.decorator'; import { Result } from 'src/common/domain/logic/Result'; import { NestLogger } from 'src/common/infrastructure/logger/nest-logger'; import { GetTrendingSongsService } from 'src/songs/application/services/getTrendingSongs.service'; @@ -50,9 +49,14 @@ import { userId } from 'src/users/domain/userAggregate/value-objects/userId'; import { PlaylistID } from 'src/playlist/domain/value-objects/PlaylistID-valueobject'; import { JwtAuthGuard } from 'src/users/application/jwtoken/jwt-auth.guard'; import { JwtService } from '@nestjs/jwt'; -import { AudithApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/error-decorator/audith.service.decorator'; import { AudithRepositoryImpl } from 'src/common/infrastructure/repositories/audithRepository.impl'; import { StreamInfoDto } from '../stream.dto'; +import { + AudithApplicationServiceDecorator +} from '../../../common/Application/application-service/decorators/audith.service.decorator'; +import { + LoggingApplicationServiceDecorator +} from '../../../common/Application/application-service/decorators/loggin-application.service.decorator'; export class TrendingSongsDto { songs: SongDto[]; diff --git a/src/users/domain/exceptions/user-already-exists.exception.ts b/src/users/domain/exceptions/user-already-exists.exception.ts index b8ddec3c..2e4676a2 100644 --- a/src/users/domain/exceptions/user-already-exists.exception.ts +++ b/src/users/domain/exceptions/user-already-exists.exception.ts @@ -2,8 +2,8 @@ import { DomainException } from "src/common/domain/exceptions/domain-exception"; import { User } from "../userAggregate/user"; -export class UserAlreadyExistsExceptions extends DomainException { +export class PhoneAlreadyExistsExceptions extends DomainException { constructor(user: User) { - super(user,"Invalid Line phone", "UserAlreadyExistsExceptions", 400); + super(user,"Phone alredy exists", "UserAlreadyExistsExceptions", 400); } } \ No newline at end of file diff --git a/src/users/infrastructure/controllers/users.controller.ts b/src/users/infrastructure/controllers/users.controller.ts index b88c2696..f465cd7f 100644 --- a/src/users/infrastructure/controllers/users.controller.ts +++ b/src/users/infrastructure/controllers/users.controller.ts @@ -41,6 +41,8 @@ import { AudithRepositoryImpl } from 'src/common/infrastructure/repositories/aud import { AudithApplicationServiceDecorator } from '../../../common/Application/application-service/decorators/audith.service.decorator'; +import { PhoneAlreadyExistsExceptions } from '../../domain/exceptions/user-already-exists.exception'; +import { MyResponse } from '../../../common/infrastructure/Response'; @ApiBearerAuth() @Controller('api') //Recuerda que este es como un prefijo para nuestras rutas @@ -184,7 +186,7 @@ export class UsersController { statusCode: result.statusCode || 200, }; } else { - return result; + MyResponse.fail(result.statusCode, result.message, result.error); } } // @UseGuards(JwtAuthGuard) @@ -232,7 +234,7 @@ export class UsersController { statusCode: 200, }; } else { - return result; + MyResponse.fail(result.statusCode, result.message, result.error); } } @@ -253,13 +255,7 @@ export class UsersController { const data = await service.execute(body.phone); if (!data.IsSuccess) { - return { - data: { - message: data.message, - error: data.error, - }, - statusCode: data.statusCode || 200, - }; + MyResponse.fail(data.statusCode, data.message, data.error); } const jwt = this.jwtService.sign( { From 16cd05abe108a4f4715d4b29831b70c22ba91b02 Mon Sep 17 00:00:00 2001 From: gamboaalejandro Date: Wed, 17 Jan 2024 19:38:46 -0400 Subject: [PATCH 06/10] updating routes and managin errors in user responses --- .../application-service/decorators/audith.service.decorator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/Application/application-service/decorators/audith.service.decorator.ts b/src/common/Application/application-service/decorators/audith.service.decorator.ts index d38144d6..9695bd67 100644 --- a/src/common/Application/application-service/decorators/audith.service.decorator.ts +++ b/src/common/Application/application-service/decorators/audith.service.decorator.ts @@ -1,6 +1,6 @@ import { Result } from 'src/common/domain/logic/Result'; import { IApplicationService } from 'src/common/Application/application-service/application.service.interface'; -import { IAudithRepository } from 'src/common/domain/repositories/IAudithRepository'; +import { IAudithRepository } from '../../../domain/repositories/IAudithRepository'; import { ApplicationServiceDecorator } from './application.service.decorator'; /** AudithApplicationServiceDecorator: Es un decorador para agregar la auditoria.*/ From 5a486ab672689d14a20c29864903929766787bf3 Mon Sep 17 00:00:00 2001 From: gamboaalejandro Date: Wed, 17 Jan 2024 19:50:27 -0400 Subject: [PATCH 07/10] updating routes and managin errors in user responses --- .../application-service/decorators/audith.service.decorator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/Application/application-service/decorators/audith.service.decorator.ts b/src/common/Application/application-service/decorators/audith.service.decorator.ts index 9695bd67..e98a5ea3 100644 --- a/src/common/Application/application-service/decorators/audith.service.decorator.ts +++ b/src/common/Application/application-service/decorators/audith.service.decorator.ts @@ -1,6 +1,6 @@ import { Result } from 'src/common/domain/logic/Result'; import { IApplicationService } from 'src/common/Application/application-service/application.service.interface'; -import { IAudithRepository } from '../../../domain/repositories/IAudithRepository'; +import { IAudithRepository } from "src/common/domain/repositories/IAudithRepository"; import { ApplicationServiceDecorator } from './application.service.decorator'; /** AudithApplicationServiceDecorator: Es un decorador para agregar la auditoria.*/ From 13e85ea32ddc6445e1d6c434113aea9fbb1059b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= <95057542+andreselc@users.noreply.github.com> Date: Wed, 17 Jan 2024 19:58:45 -0400 Subject: [PATCH 08/10] Last things in testing --- .../transactionHandler.mock.ts | 38 +++++++++---------- test/users/SignUserIn.spec.ts | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/test/core/repository-mocks/transactionHandler.mock.ts b/test/core/repository-mocks/transactionHandler.mock.ts index 16f8beb8..9e45632a 100644 --- a/test/core/repository-mocks/transactionHandler.mock.ts +++ b/test/core/repository-mocks/transactionHandler.mock.ts @@ -1,21 +1,21 @@ -// import { ItransactionHandler } from 'src/common/domain/transaction_handler/transaction_handler'; -// import { QueryRunner } from 'typeorm'; + import { ItransactionHandler } from 'src/common/domain/transaction_handler/transaction_handler'; + import { QueryRunner } from 'typeorm'; -// export class TransactionHandlerMock implements ItransactionHandler { -// constructor(private readonly runner: QueryRunner) { -// this.runner = runner; -// } -// async startTransaction() { -// return this.runner.startTransaction(); -// } -// async commitTransaction() { -// return await this.runner.commitTransaction(); -// } -// async rollbackTransaction() { -// return await this.runner.rollbackTransaction(); -// } + export class TransactionHandlerMock implements ItransactionHandler { + constructor(private readonly runner: QueryRunner) { + this.runner = runner; + } + async startTransaction() { + return this.runner.startTransaction(); + } + async commitTransaction() { + return await this.runner.commitTransaction(); + } + async rollbackTransaction() { + return await this.runner.rollbackTransaction(); + } -// getRunner(): QueryRunner { -// return this.runner; -// } -// } + getRunner(): QueryRunner { + return this.runner; + } + } diff --git a/test/users/SignUserIn.spec.ts b/test/users/SignUserIn.spec.ts index 3d6bdc25..3aa16a10 100644 --- a/test/users/SignUserIn.spec.ts +++ b/test/users/SignUserIn.spec.ts @@ -15,6 +15,6 @@ describe('Testing SignUserIn Service...', () => { const result = await service.execute(phone.PhoneNumber.phoneNumber); //Assert - expect(result.IsSuccess).toBeDefined(); + expect(result.Value).not.toBeNull(); }); }); From cb75c2c8daa2b1a07309542b3d45e5d4c464589f Mon Sep 17 00:00:00 2001 From: gamboaalejandro Date: Wed, 17 Jan 2024 20:08:54 -0400 Subject: [PATCH 09/10] updating routes and managin errors in user responses --- .../application-service/decorators/audith.service.decorator.ts | 2 +- src/common/infrastructure/repositories/audithRepository.impl.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/Application/application-service/decorators/audith.service.decorator.ts b/src/common/Application/application-service/decorators/audith.service.decorator.ts index e98a5ea3..441f6c6b 100644 --- a/src/common/Application/application-service/decorators/audith.service.decorator.ts +++ b/src/common/Application/application-service/decorators/audith.service.decorator.ts @@ -1,6 +1,6 @@ import { Result } from 'src/common/domain/logic/Result'; import { IApplicationService } from 'src/common/Application/application-service/application.service.interface'; -import { IAudithRepository } from "src/common/domain/repositories/IAudithRepository"; +import { IAudithRepository } from "src/common/domain/repositories/IaudithRepository"; import { ApplicationServiceDecorator } from './application.service.decorator'; /** AudithApplicationServiceDecorator: Es un decorador para agregar la auditoria.*/ diff --git a/src/common/infrastructure/repositories/audithRepository.impl.ts b/src/common/infrastructure/repositories/audithRepository.impl.ts index 5915ec55..57860f49 100644 --- a/src/common/infrastructure/repositories/audithRepository.impl.ts +++ b/src/common/infrastructure/repositories/audithRepository.impl.ts @@ -1,4 +1,4 @@ -import { IAudithRepository } from "src/common/domain/repositories/IAudithRepository"; +import { IAudithRepository } from "src/common/domain/repositories/IaudithRepository"; import { AudithEntity } from "../entities/audith.entity"; import { Repository } from "typeorm"; import { DataSourceSingleton } from "../dataSourceSingleton"; From e43fd8eb97c93e321c0002215416572fdab6ef2c Mon Sep 17 00:00:00 2001 From: gamboaalejandro Date: Wed, 17 Jan 2024 20:14:28 -0400 Subject: [PATCH 10/10] updating routes and managin errors in user responses --- .../application-service/decorators/audith.service.decorator.ts | 2 +- .../repositories/{IAudithRepository.ts => audit-repository.ts} | 0 src/common/infrastructure/repositories/audithRepository.impl.ts | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename src/common/domain/repositories/{IAudithRepository.ts => audit-repository.ts} (100%) diff --git a/src/common/Application/application-service/decorators/audith.service.decorator.ts b/src/common/Application/application-service/decorators/audith.service.decorator.ts index 441f6c6b..b8dc0d76 100644 --- a/src/common/Application/application-service/decorators/audith.service.decorator.ts +++ b/src/common/Application/application-service/decorators/audith.service.decorator.ts @@ -1,6 +1,6 @@ import { Result } from 'src/common/domain/logic/Result'; import { IApplicationService } from 'src/common/Application/application-service/application.service.interface'; -import { IAudithRepository } from "src/common/domain/repositories/IaudithRepository"; +import { IAudithRepository } from "src/common/domain/repositories/audit-repository"; import { ApplicationServiceDecorator } from './application.service.decorator'; /** AudithApplicationServiceDecorator: Es un decorador para agregar la auditoria.*/ diff --git a/src/common/domain/repositories/IAudithRepository.ts b/src/common/domain/repositories/audit-repository.ts similarity index 100% rename from src/common/domain/repositories/IAudithRepository.ts rename to src/common/domain/repositories/audit-repository.ts diff --git a/src/common/infrastructure/repositories/audithRepository.impl.ts b/src/common/infrastructure/repositories/audithRepository.impl.ts index 57860f49..080d9604 100644 --- a/src/common/infrastructure/repositories/audithRepository.impl.ts +++ b/src/common/infrastructure/repositories/audithRepository.impl.ts @@ -1,4 +1,4 @@ -import { IAudithRepository } from "src/common/domain/repositories/IaudithRepository"; +import { IAudithRepository } from "src/common/domain/repositories/audit-repository"; import { AudithEntity } from "../entities/audith.entity"; import { Repository } from "typeorm"; import { DataSourceSingleton } from "../dataSourceSingleton";