Skip to content

Commit

Permalink
placing dtos in each folder
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisGil11 committed Jan 18, 2024
2 parents e516b9c + e43fd8e commit a0e904c
Show file tree
Hide file tree
Showing 23 changed files with 94 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export class AppController {
@ApiTags('Hello')
@Get()
getHello(): string {
return "ogdsafas";
return this.appService.getHello();
}
}
7 changes: 4 additions & 3 deletions src/artists/infrastructure/controllers/artist.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ 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';
Expand All @@ -36,12 +35,14 @@ 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 { TrendingArtistsDto } from '../dtos/trendingArtist.dto';
import { AllArtistInfoDto } from '../dtos/allArtistInfo.dto';
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/auth/infrastruture/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { JwtStrategy } from 'src/users/application/jwtoken/jwt.strategies';
return {
secret: jwtcontanst.secret,
signOptions: {
expiresIn: '24h',
expiresIn: '10s',
},
};
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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<D, R>
implements IApplicationService<D, R>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 { IAudithRepository } from "src/common/domain/repositories/audit-repository";
import { ApplicationServiceDecorator } from './application.service.decorator';

/** AudithApplicationServiceDecorator: Es un decorador para agregar la auditoria.*/
export class AudithApplicationServiceDecorator<
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
@@ -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<D, R> extends ApplicationServiceDecorator<D, R> {
Expand Down
3 changes: 3 additions & 0 deletions src/common/domain/repositories/audit-repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface IAudithRepository {
addAudith(user_id: string, operation: string, data: string): Promise<void>;
}
2 changes: 1 addition & 1 deletion src/common/infrastructure/Common.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { PlaylistRepository } from 'src/playlist/infrastructure/PlaylistReposito
import { Controller, Get, Param } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Result } from '../domain/logic/Result';
import { LoggingApplicationServiceDecorator } from '../Application/application-service/decorators/error-decorator/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';
Expand All @@ -21,6 +20,7 @@ import { MyResponse } from './Response';
import { PaginationDto } from './Dtos/pagination.dto';
import { ArtistID } from 'src/artists/domain/value-objects/artistID-valueobject';
import { SongDto } from 'src/songs/infrastructure/dtos/Song.dto';
import { LoggingApplicationServiceDecorator } from '../Application/application-service/decorators/loggin-application.service.decorator';

export class QueryDto {
artists?: { id: string; name: string; image: Buffer }[];
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions src/playlist/infrastructure/controllers/album.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ import {
} 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 { TopPlaylistDto } from '../dtos/topPlaylistDto';
import { PlaylistDto } from '../dtos/playlistDto';
import { TopAlbumsDto } from '../dtos/topAlbumsDto';
import { SongDto } from 'src/songs/infrastructure/dtos/Song.dto';
import { AudithApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/audith.service.decorator';
import { LoggingApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/loggin-application.service.decorator';
@ApiBearerAuth()
@Controller('api/album')
export class AlbumController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ 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 { TopPlaylistDto } from '../dtos/topPlaylistDto';
import { PlaylistDto } from '../dtos/playlistDto';
import { SongDto } from 'src/songs/infrastructure/dtos/Song.dto';
import { AudithApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/audith.service.decorator';
import { LoggingApplicationServiceDecorator } from 'src/common/Application/application-service/decorators/loggin-application.service.decorator';
@ApiBearerAuth()
@Controller('api/playlist')
export class PlaylistController {
Expand Down
6 changes: 3 additions & 3 deletions src/songs/infrastructure/controllers/song.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -49,10 +48,11 @@ 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 '../dtos/stream.dto';
import { SongDto } from '../dtos/Song.dto';
import { AudithApplicationServiceDecorator } from '../../../common/Application/application-service/decorators/audith.service.decorator';
import { LoggingApplicationServiceDecorator } from '../../../common/Application/application-service/decorators/loggin-application.service.decorator';
import { StreamInfoDto } from '../dtos/stream.dto';

export class TrendingSongsDto {
songs: SongDto[];
Expand Down
4 changes: 2 additions & 2 deletions src/users/domain/exceptions/user-already-exists.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { DomainException } from "src/common/domain/exceptions/domain-exception";
import { User } from "../userAggregate/user";

export class UserAlreadyExistsExceptions extends DomainException<User> {
export class PhoneAlreadyExistsExceptions extends DomainException<User> {
constructor(user: User) {
super(user,"Invalid Line phone", "UserAlreadyExistsExceptions", 400);
super(user,"Phone alredy exists", "UserAlreadyExistsExceptions", 400);
}
}
29 changes: 15 additions & 14 deletions src/users/infrastructure/controllers/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ 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';
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';
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
Expand Down Expand Up @@ -118,7 +122,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 {
Expand Down Expand Up @@ -182,7 +186,7 @@ export class UsersController {
statusCode: result.statusCode || 200,
};
} else {
return result;
MyResponse.fail(result.statusCode, result.message, result.error);
}
}
// @UseGuards(JwtAuthGuard)
Expand Down Expand Up @@ -230,7 +234,7 @@ export class UsersController {
statusCode: 200,
};
} else {
return result;
MyResponse.fail(result.statusCode, result.message, result.error);
}
}

Expand All @@ -251,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(
{
Expand All @@ -266,7 +264,7 @@ export class UsersController {
? data.Value.SuscriptionState.SuscriptionState
: 'gratuito',
},
{ secret: jwtcontanst.secret, expiresIn: '24h' },
{ secret: jwtcontanst.secret, expiresIn: '10s' },
);

return {
Expand All @@ -283,7 +281,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),
Expand Down
9 changes: 9 additions & 0 deletions src/users/infrastructure/entities/AudithEntity.entity.ts
Original file line number Diff line number Diff line change
@@ -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;

}
6 changes: 0 additions & 6 deletions src/users/infrastructure/entities/tokenDeviceUser.entity.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
//Decoradores
import {
AfterInsert,
AfterUpdate,
AfterRemove,
Entity,
Column,
PrimaryGeneratedColumn,
OneToMany,
OneToOne,
Check,
JoinColumn, ManyToOne,
} from 'typeorm';
import {UserEntity} from "./users.entity";
Expand Down
20 changes: 20 additions & 0 deletions test/core/objects-mother/phone.object-mother.ts
Original file line number Diff line number Diff line change
@@ -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;
}

}
38 changes: 19 additions & 19 deletions test/core/repository-mocks/transactionHandler.mock.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
9 changes: 4 additions & 5 deletions test/users/SignUserIn.spec.ts
Original file line number Diff line number Diff line change
@@ -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.Value).not.toBeNull();
});
});

0 comments on commit a0e904c

Please sign in to comment.