From 319d3a03c61abc867677cabe7d426f4bf1679eaf Mon Sep 17 00:00:00 2001 From: C102002 Date: Thu, 16 Jan 2025 01:11:31 -0400 Subject: [PATCH 1/8] fix: :bug: fix minor changes --- .../odm-bundle-query-repository.ts | 13 +++++++++---- .../controller/cupon.controller.ts | 4 ++-- .../find-all-cupons-infraestructure-request.ts | 16 ++-------------- .../controller/payment-method.controller.ts | 2 ++ .../odm-product-query-repository.ts | 10 ++++++---- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/bundle/infraestructure/repositories/odm-repository/odm-bundle-query-repository.ts b/src/bundle/infraestructure/repositories/odm-repository/odm-bundle-query-repository.ts index 4b287322..ffdc9bb9 100644 --- a/src/bundle/infraestructure/repositories/odm-repository/odm-bundle-query-repository.ts +++ b/src/bundle/infraestructure/repositories/odm-repository/odm-bundle-query-repository.ts @@ -14,6 +14,8 @@ import { IProductModel } from "src/product/application/model/product.model.inter import { NotFoundException } from "src/common/infraestructure/infraestructure-exception"; import { OdmBundleMapper } from "../../mapper/odm-mapper/odm-bundle-mapper"; import { OdmPromotionEntity, OdmPromotionSchema } from "src/promotion/infraestructure/entities/odm-entities/odm-promotion-entity"; +import { IPromotion } from "src/promotion/application/model/promotion.interface"; +import { IOdmModelPromotion } from "src/promotion/infraestructure/model-entity/odm-model-entity/odm-promotion-interface"; export class OdmBundleQueryRepository implements IQueryBundleRepository{ @@ -84,7 +86,7 @@ export class OdmBundleQueryRepository implements IQueryBundleRepository{ try { const query: any = {}; - const model:IBundleModel[]=[] + let model:IBundleModel[]=[] if (criteria.name) query.name = { $regex: criteria.name, $options: 'i' } @@ -93,10 +95,9 @@ export class OdmBundleQueryRepository implements IQueryBundleRepository{ query.category = { $elemMatch: { name: { $in: criteria.category.map((c: string) => new RegExp(c, 'i')) } } }; if (criteria.price) - query.price = { ...query.price, $lte: criteria.price } + query.price = { ...query.price, $gte: criteria.price } + - if (criteria.discount) - query.discount = { $gt: 0 }; const bundles = await this.model.find(query) .skip(criteria.page) @@ -107,6 +108,10 @@ export class OdmBundleQueryRepository implements IQueryBundleRepository{ model.push(await this.trasnformtoDataModel(b)) } + if (criteria.discount){ + model=model.filter(p=>p.promotion.length!==0) + } + return Result.success(model) } catch (error) { diff --git a/src/cupon/infraestructure/controller/cupon.controller.ts b/src/cupon/infraestructure/controller/cupon.controller.ts index 30b1ffe5..00c2bc69 100644 --- a/src/cupon/infraestructure/controller/cupon.controller.ts +++ b/src/cupon/infraestructure/controller/cupon.controller.ts @@ -62,12 +62,12 @@ export class CuponController { @Query() entry: FindAllCuponsInfraestructureRequestDTO) { if (!entry.page) entry.page = 1; - if (!entry.perPage) entry.perPage = 10; + if (!entry.perpage) entry.perpage = 10; const pagination: PaginationRequestDTO = { userId: credential.account.idUser, page: entry.page, - perPage: entry.perPage + perPage: entry.perpage }; let service = new ExceptionDecorator( diff --git a/src/cupon/infraestructure/dto-request/find-all-cupons-infraestructure-request.ts b/src/cupon/infraestructure/dto-request/find-all-cupons-infraestructure-request.ts index 3df439d7..d3fc1586 100644 --- a/src/cupon/infraestructure/dto-request/find-all-cupons-infraestructure-request.ts +++ b/src/cupon/infraestructure/dto-request/find-all-cupons-infraestructure-request.ts @@ -1,17 +1,5 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { Transform, Type } from "class-transformer"; -import { IsOptional, IsPositive } from "class-validator"; +import { PaginationDto } from "src/common/infraestructure/dto/entry/pagination.dto"; -export class FindAllCuponsInfraestructureRequestDTO { - @ApiProperty({ required: false, default: 1, minimum: 1 }) - @IsOptional() - @IsPositive() - @Transform(({ value }) => { return Number(value); }) - page?: number; +export class FindAllCuponsInfraestructureRequestDTO extends PaginationDto{ - @ApiProperty({ required: false, default: 10, minimum: 1 }) - @IsOptional() - @IsPositive() - @Transform(({ value }) => { return Number(value); }) - perPage?: number; } diff --git a/src/payment-methods/infraestructure/controller/payment-method.controller.ts b/src/payment-methods/infraestructure/controller/payment-method.controller.ts index 2f15451c..d5adf702 100644 --- a/src/payment-methods/infraestructure/controller/payment-method.controller.ts +++ b/src/payment-methods/infraestructure/controller/payment-method.controller.ts @@ -217,6 +217,8 @@ export class PaymentMethodController { userId: credential.account.idUser, ...data } + if (!values.page) values.page = 1; + if (!values.perPage) values.perPage = 10; let getAllPaymentMethodService = new ExceptionDecorator( new LoggerDecorator( diff --git a/src/product/infraestructure/repositories/odm-repository/odm-product-query-repository.ts b/src/product/infraestructure/repositories/odm-repository/odm-product-query-repository.ts index d2f352c4..7224375c 100644 --- a/src/product/infraestructure/repositories/odm-repository/odm-product-query-repository.ts +++ b/src/product/infraestructure/repositories/odm-repository/odm-product-query-repository.ts @@ -70,7 +70,7 @@ export class OdmProductQueryRepository implements IQueryProductRepository { async findAllProducts(criteria: FindAllProductsApplicationRequestDTO): Promise> { try { const query: any = {}; - const model:IProductModel[]=[] + let model:IProductModel[]=[] if (criteria.name) query.name = { $regex: criteria.name, $options: 'i' } @@ -81,9 +81,6 @@ export class OdmProductQueryRepository implements IQueryProductRepository { if (criteria.price) query.price = { ...query.price, $gte: criteria.price } - if (criteria.discount) - query.discount = { $gt: 0 }; - const products = await this.model.find(query) .skip(criteria.page) .limit(criteria.perPage) @@ -93,6 +90,11 @@ export class OdmProductQueryRepository implements IQueryProductRepository { model.push(await this.trasnformtoDataModel(p)) } + if (criteria.discount){ + model=model.filter(p=>p.promotion.length!==0) + } + + return Result.success(model) } catch (error) { From 61a899a3042f06684408dc802570f24f7aed616c Mon Sep 17 00:00:00 2001 From: C102002 Date: Thu, 16 Jan 2025 02:01:56 -0400 Subject: [PATCH 2/8] feat: :construction_worker: log in construction cqrs --- .../application/messages/password-change.ts | 51 +++++++++++++++++++ .../messages/session-registered.ts | 24 ++++----- .../log-in-user-application.service.ts | 21 ++++++-- .../controller/auth.controller.ts | 18 ++++++- .../infraestructure/queues/auth.queues.ts | 1 + ...ount-log-in-infraestructure-request-dto.ts | 1 + .../account-log-in-syncronice.service.ts | 23 +++++++++ 7 files changed, 119 insertions(+), 20 deletions(-) create mode 100644 src/auth/application/messages/password-change.ts create mode 100644 src/auth/infraestructure/services/syncronice/account-log-in-syncronice.service.ts diff --git a/src/auth/application/messages/password-change.ts b/src/auth/application/messages/password-change.ts new file mode 100644 index 00000000..a97c3f15 --- /dev/null +++ b/src/auth/application/messages/password-change.ts @@ -0,0 +1,51 @@ +import { Message } from 'src/common/application/events/message/message'; +import { ISession } from '../model/session.interface'; + +export class AccountRegistered extends Message { + serialize(): string { + let data= { + id: this.id, + password: this.password + } + return JSON.stringify(data) + } + static create( + sessions: ISession[], + id: string, + email: string, + password: string, + created_at: Date, + isConfirmed:boolean, + code: null, + code_created_at:null, + idUser:string, + idStripe:string + ){ + return new AccountRegistered( + sessions, + id, + email, + password, + created_at, + isConfirmed, + code, + code_created_at, + idUser, + idStripe + ) + } + constructor( + public sessions: ISession[], + public id: string, + public email: string, + public password: string, + public created_at: Date, + public isConfirmed:boolean, + public code: null, + public code_created_at:null, + public idUser:string, + public idStripe:string + ){ + super() + } +} \ No newline at end of file diff --git a/src/auth/application/messages/session-registered.ts b/src/auth/application/messages/session-registered.ts index 824e6186..a0335036 100644 --- a/src/auth/application/messages/session-registered.ts +++ b/src/auth/application/messages/session-registered.ts @@ -1,33 +1,31 @@ import { Message } from 'src/common/application/events/message/message'; +import { ISession } from '../model/session.interface'; export class SessionRegistered extends Message { serialize(): string { let data= { id: this.id, - expired_at: this.expired_at, - push_token: this.push_token, - accountId:this.accountId + session:{ + id: this.id, + expired_at: this.session.expired_at, + push_token: this.session.push_token, + accountId:this.session.accountId + } } return JSON.stringify(data) } static create( - id: string, - expired_at: Date, - push_token: string, - accountId:string + id:string, + session:ISession ){ return new SessionRegistered( id, - expired_at, - push_token, - accountId + session ) } constructor( public id: string, - public expired_at: Date, - public push_token: string, - public accountId:string + public session:ISession ){ super() } diff --git a/src/auth/application/services/command/log-in-user-application.service.ts b/src/auth/application/services/command/log-in-user-application.service.ts index b6a3e32d..9d2af886 100644 --- a/src/auth/application/services/command/log-in-user-application.service.ts +++ b/src/auth/application/services/command/log-in-user-application.service.ts @@ -16,6 +16,8 @@ import { IQueryUserRepository } from "src/user/application/repository/user.query import { UserId } from "src/user/domain/value-object/user-id"; import { ErrorRegisteringSessionApplicationException } from "../../application-exception/error-registering-session-application-exception"; import { AccountNotFoundApplicationException } from "../../application-exception/account-not-found-application-exception"; +import { IMessagesPublisher } from "src/common/application/messages/messages-publisher/messages-publisher.interface"; +import { SessionRegistered } from "../../messages/session-registered"; export class LogInUserApplicationService extends IApplicationService { @@ -27,7 +29,8 @@ export class LogInUserApplicationService extends IApplicationService private readonly encryptor: IEncryptor, private readonly idGen:IIdGen, private readonly jwtGen:IJwtGenerator, - private readonly dateHandler:IDateHandler + private readonly dateHandler:IDateHandler, + private readonly messagePublisher:IMessagesPublisher ){ super() } @@ -56,18 +59,26 @@ export class LogInUserApplicationService extends IApplicationService const idSession = await this.idGen.genId() const jwt = this.jwtGen.generateJwt( idSession ) - - let sessionResponse=await this.commandTokenSessionRepository.createSession( - { + + const session={ expired_at: this.dateHandler.getExpiry(), id: idSession, push_token: null, accountId: account.id - }) + } + + let sessionResponse=await this.commandTokenSessionRepository.createSession(session) if (!sessionResponse.isSuccess()) return Result.fail(new ErrorRegisteringSessionApplicationException()) + this.messagePublisher.publish([ + SessionRegistered.create( + account.id, + session + ) + ]) + return Result.success({ id: user.getId().Value, email: account.email, diff --git a/src/auth/infraestructure/controller/auth.controller.ts b/src/auth/infraestructure/controller/auth.controller.ts index 366ab588..2b192665 100644 --- a/src/auth/infraestructure/controller/auth.controller.ts +++ b/src/auth/infraestructure/controller/auth.controller.ts @@ -138,7 +138,15 @@ export class AuthController { this.syncAccountRegistered(data) return } - ) + ) + + this.messageSuscriber.consume( + { name: 'Messages/SessionRegistered' }, + (data):Promise=>{ + this.syncAccountLogIn(data) + return + } + ) } async syncAccountRegistered(data:IAccountRegistered){ @@ -146,6 +154,11 @@ export class AuthController { await service.execute(data) } + async syncAccountLogIn(data:IAccountRegistered){ + let service = new AccountRegisteredSyncroniceService(mongoose) + await service.execute(data) + } + @Post('register') @ApiResponse({ status: 200, @@ -199,7 +212,8 @@ export class AuthController { this.encryptor, this.idGen, this.jwtGen, - this.dateHandler + this.dateHandler, + this.messagePubliser ), new NestTimer(), new NestLogger(new Logger()) // ),new NestLogger(new Logger()) ),this.auditRepository,this.dateHandler diff --git a/src/auth/infraestructure/queues/auth.queues.ts b/src/auth/infraestructure/queues/auth.queues.ts index 743dd784..de4f6969 100644 --- a/src/auth/infraestructure/queues/auth.queues.ts +++ b/src/auth/infraestructure/queues/auth.queues.ts @@ -1,3 +1,4 @@ export const AuthQueues = [ { name: 'Messages/AccountRegistered', pattern: 'AccountRegistered' }, + { name: 'Messages/SessionRegistered', pattern: 'SessionRegistered' }, ] \ No newline at end of file diff --git a/src/auth/infraestructure/services/dto/request/account-log-in-infraestructure-request-dto.ts b/src/auth/infraestructure/services/dto/request/account-log-in-infraestructure-request-dto.ts index a4081407..01321cfb 100644 --- a/src/auth/infraestructure/services/dto/request/account-log-in-infraestructure-request-dto.ts +++ b/src/auth/infraestructure/services/dto/request/account-log-in-infraestructure-request-dto.ts @@ -1,4 +1,5 @@ export interface AccountLogInInfraestructureRequestDTO { + id:string sessions: { id: string expired_at: Date diff --git a/src/auth/infraestructure/services/syncronice/account-log-in-syncronice.service.ts b/src/auth/infraestructure/services/syncronice/account-log-in-syncronice.service.ts new file mode 100644 index 00000000..730a0026 --- /dev/null +++ b/src/auth/infraestructure/services/syncronice/account-log-in-syncronice.service.ts @@ -0,0 +1,23 @@ +import { Result } from 'src/common/utils/result-handler/result'; +import { ISycnchronizeService } from 'src/common/infraestructure/synchronize-service/synchronize.service.interface'; +import { Model, Mongoose } from 'mongoose'; +import { OdmAccount, OdmAccountSchema } from '../../account/odm-entities/odm-account-entity'; +import { AccountLogInInfraestructureRequestDTO } from '../dto/request/account-log-in-infraestructure-request-dto'; + +export class AccountLogInSyncroniceService implements +ISycnchronizeService{ + + private readonly model: Model + + + constructor( mongoose: Mongoose ) { + this.model = mongoose.model('odmaccount', OdmAccountSchema) + } + + async execute(event: AccountLogInInfraestructureRequestDTO): Promise> { + + const account = this.model.findOne({id:event.id}) + await this.model.create(account) + return Result.success(undefined) + } +} \ No newline at end of file From ebdeca3e9c56d55c6abdf11ef52874b0b3b19065 Mon Sep 17 00:00:00 2001 From: C102002 Date: Thu, 16 Jan 2025 04:25:15 -0400 Subject: [PATCH 3/8] feat: :construction_worker: continuing user cqrs --- .../controller/auth.controller.ts | 10 ++- .../interface/account-log-in.interface.ts | 9 ++ ...ount-log-in-infraestructure-request-dto.ts | 10 +-- .../account-log-in-syncronice.service.ts | 5 +- .../odm-entities/odm-bundle-entity.ts | 11 --- src/user/domain/aggregate/user.aggregate.ts | 3 +- .../domain-events/user-direction-added.ts | 8 +- .../domain-events/user-direction-updated.ts | 8 +- .../domain/domain-events/user-registered.ts | 15 ++-- .../controller/user.controller.ts | 15 ++++ .../entities/odm-entities/odm-user-entity.ts | 83 +++++++++++++++++++ .../user-balance-amount-added.interface.ts | 8 ++ ...er-balance-amount-decremented.interface.ts | 7 ++ .../user-coupon-aplied.interface.ts | 7 ++ .../user-direction-added.interface.ts | 10 +++ .../user-direction-deleted.interface.ts | 7 ++ .../user-direction-updated.interface.ts | 10 +++ .../user-image-updated.interface.ts | 4 + .../interfaces/user-name-updated.interface.ts | 4 + .../user-phone-updated.interface.ts | 4 + .../interfaces/user-registered.interface.ts | 18 ++++ .../odm-model-entity/odm-user-interface.ts | 21 +++++ .../infraestructure/queues/user.queues.ts | 12 ++- .../odm-transaction-query-repository.ts | 15 ++++ .../odm-user-query-repository.ts | 34 ++++++++ ...-registered-infraestructure-request-dto.ts | 18 ++++ ...ser-updated-infraestructure-request-dto.ts | 17 ++++ .../user-registered-syncronice.service.ts | 37 +++++++++ .../user-updated-syncronice.service.ts | 53 ++++++++++++ 29 files changed, 426 insertions(+), 37 deletions(-) create mode 100644 src/auth/infraestructure/interface/account-log-in.interface.ts create mode 100644 src/user/infraestructure/entities/odm-entities/odm-user-entity.ts create mode 100644 src/user/infraestructure/interfaces/user-balance-amount-added.interface.ts create mode 100644 src/user/infraestructure/interfaces/user-balance-amount-decremented.interface.ts create mode 100644 src/user/infraestructure/interfaces/user-coupon-aplied.interface.ts create mode 100644 src/user/infraestructure/interfaces/user-direction-added.interface.ts create mode 100644 src/user/infraestructure/interfaces/user-direction-deleted.interface.ts create mode 100644 src/user/infraestructure/interfaces/user-direction-updated.interface.ts create mode 100644 src/user/infraestructure/interfaces/user-image-updated.interface.ts create mode 100644 src/user/infraestructure/interfaces/user-name-updated.interface.ts create mode 100644 src/user/infraestructure/interfaces/user-phone-updated.interface.ts create mode 100644 src/user/infraestructure/interfaces/user-registered.interface.ts create mode 100644 src/user/infraestructure/model-entity/odm-model-entity/odm-user-interface.ts create mode 100644 src/user/infraestructure/repositories/odm-repository/odm-transaction-query-repository.ts create mode 100644 src/user/infraestructure/repositories/odm-repository/odm-user-query-repository.ts create mode 100644 src/user/infraestructure/services/dto/request/user-registered-infraestructure-request-dto.ts create mode 100644 src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts create mode 100644 src/user/infraestructure/services/syncronice/user-registered-syncronice.service.ts create mode 100644 src/user/infraestructure/services/syncronice/user-updated-syncronice.service.ts diff --git a/src/auth/infraestructure/controller/auth.controller.ts b/src/auth/infraestructure/controller/auth.controller.ts index 2b192665..76f4551d 100644 --- a/src/auth/infraestructure/controller/auth.controller.ts +++ b/src/auth/infraestructure/controller/auth.controller.ts @@ -70,6 +70,8 @@ import { AuthQueues } from "../queues/auth.queues" import { IAccountRegistered } from "../interface/account-registered.interface" import { AccountRegisteredSyncroniceService } from "../services/syncronice/account-registered-syncronice.service" import mongoose, { Mongoose } from "mongoose" +import { IAccountLogIn } from "../interface/account-log-in.interface" +import { AccountLogInSyncroniceService } from "../services/syncronice/account-log-in-syncronice.service" @ApiTags('Auth') @Controller('auth') @@ -140,7 +142,7 @@ export class AuthController { } ) - this.messageSuscriber.consume( + this.messageSuscriber.consume( { name: 'Messages/SessionRegistered' }, (data):Promise=>{ this.syncAccountLogIn(data) @@ -154,9 +156,9 @@ export class AuthController { await service.execute(data) } - async syncAccountLogIn(data:IAccountRegistered){ - let service = new AccountRegisteredSyncroniceService(mongoose) - await service.execute(data) + async syncAccountLogIn(data:IAccountLogIn){ + let service = new AccountLogInSyncroniceService(mongoose) + await service.execute({...data}) } @Post('register') diff --git a/src/auth/infraestructure/interface/account-log-in.interface.ts b/src/auth/infraestructure/interface/account-log-in.interface.ts new file mode 100644 index 00000000..b70c4bfe --- /dev/null +++ b/src/auth/infraestructure/interface/account-log-in.interface.ts @@ -0,0 +1,9 @@ +export interface IAccountLogIn { + id:string + session: { + id: string; + expired_at: Date; + push_token: string; + accountId: string; + } +} \ No newline at end of file diff --git a/src/auth/infraestructure/services/dto/request/account-log-in-infraestructure-request-dto.ts b/src/auth/infraestructure/services/dto/request/account-log-in-infraestructure-request-dto.ts index 01321cfb..f894b3e3 100644 --- a/src/auth/infraestructure/services/dto/request/account-log-in-infraestructure-request-dto.ts +++ b/src/auth/infraestructure/services/dto/request/account-log-in-infraestructure-request-dto.ts @@ -1,9 +1,9 @@ export interface AccountLogInInfraestructureRequestDTO { id:string - sessions: { - id: string - expired_at: Date - push_token: null - accountId:string + session: { + id: string; + expired_at: Date; + push_token: string; + accountId: string; } } \ No newline at end of file diff --git a/src/auth/infraestructure/services/syncronice/account-log-in-syncronice.service.ts b/src/auth/infraestructure/services/syncronice/account-log-in-syncronice.service.ts index 730a0026..a1e49b77 100644 --- a/src/auth/infraestructure/services/syncronice/account-log-in-syncronice.service.ts +++ b/src/auth/infraestructure/services/syncronice/account-log-in-syncronice.service.ts @@ -16,8 +16,9 @@ ISycnchronizeService{ async execute(event: AccountLogInInfraestructureRequestDTO): Promise> { - const account = this.model.findOne({id:event.id}) - await this.model.create(account) + const account = await this.model.findOne({id:event.id}) + account.sessions.push(event.session) + await account.save() return Result.success(undefined) } } \ No newline at end of file diff --git a/src/bundle/infraestructure/entities/odm-entities/odm-bundle-entity.ts b/src/bundle/infraestructure/entities/odm-entities/odm-bundle-entity.ts index 26eee225..df350162 100644 --- a/src/bundle/infraestructure/entities/odm-entities/odm-bundle-entity.ts +++ b/src/bundle/infraestructure/entities/odm-entities/odm-bundle-entity.ts @@ -1,8 +1,6 @@ import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose" import mongoose, { Document, SchemaTypes } from "mongoose" -import { OdmCategory } from "src/category/infraestructure/entities/odm-entities/odm-category.entity" import { IOdmBundle } from "../../model-entity/odm-model-entity/odm-bundle-interface" -import { OdmProduct } from "src/product/infraestructure/entities/odm-entities/odm-product-entity" @Schema({ collection: 'odmbundle' }) export class OdmBundle extends Document implements IOdmBundle { @@ -69,15 +67,6 @@ export class OdmBundle extends Document implements IOdmBundle { id:string, name:string }[] - - // @Prop({ type: [Object], unique: false, required: false }) - // category?: OdmCategory[] - - - // @Prop({ type: [Object], unique: false, required: true }) - // products: OdmProduct[] - - } export const OdmBundleSchema = SchemaFactory.createForClass( OdmBundle ) diff --git a/src/user/domain/aggregate/user.aggregate.ts b/src/user/domain/aggregate/user.aggregate.ts index d9e9981e..e85f51cd 100644 --- a/src/user/domain/aggregate/user.aggregate.ts +++ b/src/user/domain/aggregate/user.aggregate.ts @@ -146,7 +146,8 @@ export class User extends AggregateRoot { userPhone, userImage, wallet, - userCoupon + userCoupon, + userRole ) ) return user diff --git a/src/user/domain/domain-events/user-direction-added.ts b/src/user/domain/domain-events/user-direction-added.ts index 9e860290..8657093a 100644 --- a/src/user/domain/domain-events/user-direction-added.ts +++ b/src/user/domain/domain-events/user-direction-added.ts @@ -9,10 +9,10 @@ export class UserDirectionAdded extends DomainEvent { userId:this.userId.Value, userDirection:{ id: this.userDirection.getId().Value, - name: this.userDirection.DirectionName, - favorite: this.userDirection.DirectionFavorite, - lat: this.userDirection.DirectionLat, - lng: this.userDirection.DirectionLng + name: this.userDirection.DirectionName.Value, + favorite: this.userDirection.DirectionFavorite.Value, + lat: this.userDirection.DirectionLat.Value, + lng: this.userDirection.DirectionLng.Value } } return JSON.stringify(data) diff --git a/src/user/domain/domain-events/user-direction-updated.ts b/src/user/domain/domain-events/user-direction-updated.ts index f6722b38..3142dd8c 100644 --- a/src/user/domain/domain-events/user-direction-updated.ts +++ b/src/user/domain/domain-events/user-direction-updated.ts @@ -9,10 +9,10 @@ export class UserDirectionUpdated extends DomainEvent { userId:this.userId.Value, userDirection:{ id: this.userDirection.getId().Value, - name: this.userDirection.DirectionName, - favorite: this.userDirection.DirectionFavorite, - lat: this.userDirection.DirectionLat, - lng: this.userDirection.DirectionLng + name: this.userDirection.DirectionName.Value, + favorite: this.userDirection.DirectionFavorite.Value, + lat: this.userDirection.DirectionLat.Value, + lng: this.userDirection.DirectionLng.Value } } return JSON.stringify(data) diff --git a/src/user/domain/domain-events/user-registered.ts b/src/user/domain/domain-events/user-registered.ts index 67047e7c..e331c0d0 100644 --- a/src/user/domain/domain-events/user-registered.ts +++ b/src/user/domain/domain-events/user-registered.ts @@ -1,11 +1,11 @@ import { DomainEvent } from '../../../common/domain/domain-event/domain-event'; import { UserCoupon } from '../entities/coupon/user-coupon.entity'; import { Wallet } from '../entities/wallet/wallet.entity'; -import { UserEmail } from '../value-object/user-email'; import { UserId } from '../value-object/user-id'; import { UserImage } from '../value-object/user-image'; import { UserName } from '../value-object/user-name'; import { UserPhone } from '../value-object/user-phone'; +import { UserRole } from '../value-object/user-role'; export class UserRegistered extends DomainEvent { serialize(): string { @@ -26,7 +26,8 @@ export class UserRegistered extends DomainEvent { state:c.CuponState.Value })) : [], - userImage: this.userImage ? this.userImage.Value : undefined + userImage: this.userImage ? this.userImage.Value : undefined, + userRole: this.userRole.Value } return JSON.stringify(data) } @@ -36,7 +37,8 @@ export class UserRegistered extends DomainEvent { userPhone:UserPhone, userImage:UserImage, wallet:Wallet, - userCoupon:UserCoupon[] + userCoupon:UserCoupon[], + userRole:UserRole ){ return new UserRegistered( userId, @@ -44,7 +46,8 @@ export class UserRegistered extends DomainEvent { userPhone, userImage, wallet, - userCoupon + userCoupon, + userRole ) } constructor( @@ -53,7 +56,9 @@ export class UserRegistered extends DomainEvent { public userPhone:UserPhone, public userImage:UserImage, public Wallet:Wallet, - public userCoupon:UserCoupon[] + public userCoupon:UserCoupon[], + public userRole:UserRole, + ){ super() } diff --git a/src/user/infraestructure/controller/user.controller.ts b/src/user/infraestructure/controller/user.controller.ts index aa5e60ff..77614317 100644 --- a/src/user/infraestructure/controller/user.controller.ts +++ b/src/user/infraestructure/controller/user.controller.ts @@ -61,6 +61,8 @@ import { Mongoose } from "mongoose" import { FileInterceptor } from '@nestjs/platform-express'; import { UpdateProfileApplicationRequestDTO } from "src/user/application/dto/request/update-profile-application-request-dto" import { UpdateProfileApplicationResponseDTO } from "src/user/application/dto/response/update-profile-application-response-dto" +import { IUserRegistered } from "../interfaces/user-registered.interface" +import { UserRegisteredSyncroniceService } from "../services/syncronice/user-registered-syncronice.service" @ApiBearerAuth() @UseGuards(JwtAuthGuard) @@ -125,6 +127,19 @@ export class UserController { return } ) + + this.subscriber.consume( + { name: 'UserSync/UserRegistered'}, + (data):Promise=>{ + this.userregisteredsync(data) + return + } + ) + } + + async userregisteredsync(data:IUserRegistered){ + let service=new UserRegisteredSyncroniceService(this.mongoose) + await service.execute(data) } @Patch('update/profile') diff --git a/src/user/infraestructure/entities/odm-entities/odm-user-entity.ts b/src/user/infraestructure/entities/odm-entities/odm-user-entity.ts new file mode 100644 index 00000000..298eab09 --- /dev/null +++ b/src/user/infraestructure/entities/odm-entities/odm-user-entity.ts @@ -0,0 +1,83 @@ +import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; +import { Document, SchemaTypes } from 'mongoose'; +import { UserRoles } from 'src/user/domain/value-object/enum/user.roles'; +import { IOdmUser } from '../../model-entity/odm-model-entity/odm-user-interface'; + +@Schema({ collection: 'odmuser' }) +export class OdmUserEntity extends Document implements IOdmUser{ + + @Prop({ type: String, unique: true, required: true }) + id: string + + @Prop({ type: String, unique: false, required: true }) + name: string; + + @Prop({ type: String, unique: true, required: true }) + phone: string; + + @Prop({ type: String, unique: true, required: false }) + image: string; + + @Prop({ type: String, enum: UserRoles, required: true }) + type: UserRoles + + + @Prop({ + type: [ + { + _id:false, + id: SchemaTypes.String, + favorite: SchemaTypes.Boolean, + lat: SchemaTypes.Number, + lng: SchemaTypes.Number, + name: SchemaTypes.String + } + ], + unique: false, + required: false + }) + direction: { + id: string; + favorite: boolean; + lat: number; + lng: number; + name: string; + }[]; + + @Prop({ + type: + { + _id:false, + id: SchemaTypes.String, + currency: SchemaTypes.String, + amount: SchemaTypes.String + } + , + unique: false, + required: false + }) + wallet:{ + id:string, + currency:string, + amount:number + } + + @Prop({ + type: [ + { + _id:false, + id: SchemaTypes.String, + state: SchemaTypes.String, + } + ] + , + unique: false, + required: false + }) + coupon:{ + id:string, + state:string, + }[] + +} +export const OdmUserSchema = SchemaFactory.createForClass(OdmUserEntity); diff --git a/src/user/infraestructure/interfaces/user-balance-amount-added.interface.ts b/src/user/infraestructure/interfaces/user-balance-amount-added.interface.ts new file mode 100644 index 00000000..d51b285e --- /dev/null +++ b/src/user/infraestructure/interfaces/user-balance-amount-added.interface.ts @@ -0,0 +1,8 @@ + +export interface IUserBalanceAmountAdded { + userId:string + userWallet: { + amount: number; + currency: string; + } +} diff --git a/src/user/infraestructure/interfaces/user-balance-amount-decremented.interface.ts b/src/user/infraestructure/interfaces/user-balance-amount-decremented.interface.ts new file mode 100644 index 00000000..6804cf13 --- /dev/null +++ b/src/user/infraestructure/interfaces/user-balance-amount-decremented.interface.ts @@ -0,0 +1,7 @@ +export interface IUserBalanceAmountDecremented { + userId:string + userWallet: { + amount: number; + currency: string; + } +} diff --git a/src/user/infraestructure/interfaces/user-coupon-aplied.interface.ts b/src/user/infraestructure/interfaces/user-coupon-aplied.interface.ts new file mode 100644 index 00000000..8ecea176 --- /dev/null +++ b/src/user/infraestructure/interfaces/user-coupon-aplied.interface.ts @@ -0,0 +1,7 @@ +export interface UserCouponAplied { + userId:string, + coupons: { + id: string; + state: string; + } +} \ No newline at end of file diff --git a/src/user/infraestructure/interfaces/user-direction-added.interface.ts b/src/user/infraestructure/interfaces/user-direction-added.interface.ts new file mode 100644 index 00000000..0d29dfe2 --- /dev/null +++ b/src/user/infraestructure/interfaces/user-direction-added.interface.ts @@ -0,0 +1,10 @@ +export interface IUserDirectionAdded { + userId: string + userDirection: { + id: string; + name: string; + favorite: boolean; + lat: number; + lng: number; + } +} \ No newline at end of file diff --git a/src/user/infraestructure/interfaces/user-direction-deleted.interface.ts b/src/user/infraestructure/interfaces/user-direction-deleted.interface.ts new file mode 100644 index 00000000..67e976f0 --- /dev/null +++ b/src/user/infraestructure/interfaces/user-direction-deleted.interface.ts @@ -0,0 +1,7 @@ + +export interface IUserDirectionDeleted { + userId: string + userDirection: { + id: string; + } +} \ No newline at end of file diff --git a/src/user/infraestructure/interfaces/user-direction-updated.interface.ts b/src/user/infraestructure/interfaces/user-direction-updated.interface.ts new file mode 100644 index 00000000..c4f615c7 --- /dev/null +++ b/src/user/infraestructure/interfaces/user-direction-updated.interface.ts @@ -0,0 +1,10 @@ +export interface IUserDirectionUpdated { + userId: string + userDirection: { + id: string; + name: string; + favorite: boolean; + lat: number; + lng: number; + } +} \ No newline at end of file diff --git a/src/user/infraestructure/interfaces/user-image-updated.interface.ts b/src/user/infraestructure/interfaces/user-image-updated.interface.ts new file mode 100644 index 00000000..9ba6974b --- /dev/null +++ b/src/user/infraestructure/interfaces/user-image-updated.interface.ts @@ -0,0 +1,4 @@ +export interface IUserImageUpdated{ + userId: string; + userImage: string; +} diff --git a/src/user/infraestructure/interfaces/user-name-updated.interface.ts b/src/user/infraestructure/interfaces/user-name-updated.interface.ts new file mode 100644 index 00000000..51d01cd2 --- /dev/null +++ b/src/user/infraestructure/interfaces/user-name-updated.interface.ts @@ -0,0 +1,4 @@ +export interface IUserNameUpdated{ + userId: string; + userName: string; +} diff --git a/src/user/infraestructure/interfaces/user-phone-updated.interface.ts b/src/user/infraestructure/interfaces/user-phone-updated.interface.ts new file mode 100644 index 00000000..db5e264b --- /dev/null +++ b/src/user/infraestructure/interfaces/user-phone-updated.interface.ts @@ -0,0 +1,4 @@ +export interface IPhoneUpdated{ + userId: string; + userPhone: string; +} diff --git a/src/user/infraestructure/interfaces/user-registered.interface.ts b/src/user/infraestructure/interfaces/user-registered.interface.ts new file mode 100644 index 00000000..cb73287c --- /dev/null +++ b/src/user/infraestructure/interfaces/user-registered.interface.ts @@ -0,0 +1,18 @@ +export interface IUserRegistered{ + userId: string; + userName: string; + userPhone: string; + wallet: { + walletId: string; + ballance: { + currency: string; + amount: number; + }; + }; + coupons: { + id: string; + state: string; + }[]; + userImage: string; + userRole: string +} diff --git a/src/user/infraestructure/model-entity/odm-model-entity/odm-user-interface.ts b/src/user/infraestructure/model-entity/odm-model-entity/odm-user-interface.ts new file mode 100644 index 00000000..07a0b328 --- /dev/null +++ b/src/user/infraestructure/model-entity/odm-model-entity/odm-user-interface.ts @@ -0,0 +1,21 @@ +import { UserRoles } from "src/user/domain/value-object/enum/user.roles" + +export interface IOdmUser{ + id:string, + name:string, + phone:string, + image:string + type: UserRoles + direction:{ + id: string, + favorite:boolean, + lat:number, + lng: number + name:string + }[] + wallet:{ + id:string, + currency:string, + amount:number + } +} \ No newline at end of file diff --git a/src/user/infraestructure/queues/user.queues.ts b/src/user/infraestructure/queues/user.queues.ts index 17038fe3..9e75a2d3 100644 --- a/src/user/infraestructure/queues/user.queues.ts +++ b/src/user/infraestructure/queues/user.queues.ts @@ -1,3 +1,13 @@ export const UserQueues = [ { name: 'ApplyCoupon/OrderRegistered', pattern: 'OrderRegistered' }, -] \ No newline at end of file + { name: 'UserSync/UserBalanceAmountAdded', pattern: 'UserBalanceAmountAdded' }, + { name: 'UserSync/UserBalanceAmountDecremented', pattern: 'UserBalanceAmountDecremented' }, + { name: 'UserSync/UserCouponAplied', pattern: 'UserCouponAplied' }, + { name: 'UserSync/UserDirectionAdded', pattern: 'UserDirectionAdded' }, + { name: 'UserSync/UserDirectionDeleted', pattern: 'UserDirectionDeleted' }, + { name: 'UserSync/UserDirectionUpdated', pattern: 'UserDirectionUpdated' }, + { name: 'UserSync/UserImageUpdated', pattern: 'UserImageUpdated' }, + { name: 'UserSync/UserNameUpdated', pattern: 'UserNameUpdated' }, + { name: 'UserSync/UserPhoneUpdated', pattern: 'UserPhoneUpdated' }, + { name: 'UserSync/UserRegistered', pattern: 'UserRegistered' }, +] diff --git a/src/user/infraestructure/repositories/odm-repository/odm-transaction-query-repository.ts b/src/user/infraestructure/repositories/odm-repository/odm-transaction-query-repository.ts new file mode 100644 index 00000000..69190ee5 --- /dev/null +++ b/src/user/infraestructure/repositories/odm-repository/odm-transaction-query-repository.ts @@ -0,0 +1,15 @@ +import { Result } from "src/common/utils/result-handler/result" +import { ITransaction } from "src/user/application/model/transaction-interface" +import { IQueryTransactionRepository } from "src/user/application/repository/wallet-transaction/transaction-query-repository.interface" + + +export class OdmTransactionQueryRepository implements IQueryTransactionRepository{ + + getAllTransactionsByWalletId(walletId: string, page: number, perPage: number): Promise> { + throw new Error("Method not implemented.") + } + getTransactionById(id: string): Promise> { + throw new Error("Method not implemented.") + } + +} \ No newline at end of file diff --git a/src/user/infraestructure/repositories/odm-repository/odm-user-query-repository.ts b/src/user/infraestructure/repositories/odm-repository/odm-user-query-repository.ts new file mode 100644 index 00000000..37089bd7 --- /dev/null +++ b/src/user/infraestructure/repositories/odm-repository/odm-user-query-repository.ts @@ -0,0 +1,34 @@ +import { Result } from "src/common/utils/result-handler/result"; +import { IDirection } from "src/user/application/model/direction-interface"; +import { IUserDirection } from "src/user/application/model/user.direction.interface"; +import { IQueryUserRepository } from "src/user/application/repository/user.query.repository.interface"; +import { User } from "src/user/domain/aggregate/user.aggregate"; +import { UserDirection } from "src/user/domain/entities/directions/direction.entity"; +import { DirectionId } from "src/user/domain/entities/directions/value-objects/direction-id"; +import { UserId } from "src/user/domain/value-object/user-id"; +import { UserPhone } from "src/user/domain/value-object/user-phone"; + + +export class OdmUserQueryRepository implements IQueryUserRepository{ + + findUserById(id: UserId): Promise> { + throw new Error("Method not implemented."); + } + findUserByPhoneNumber(phoneNumber: UserPhone): Promise> { + throw new Error("Method not implemented."); + } + verifyUserExistenceByPhoneNumber(phoneNumber: UserPhone): Promise> { + throw new Error("Method not implemented."); + } + findUserDirectionsByUserId(id: UserId): Promise> { + throw new Error("Method not implemented."); + } + findDirectionsByLatAndLng(userDirection: UserDirection[]): Promise> { + throw new Error("Method not implemented."); + } + findDirectionById(id: DirectionId, userId: UserId): Promise> { + throw new Error("Method not implemented."); + } + + +} \ No newline at end of file diff --git a/src/user/infraestructure/services/dto/request/user-registered-infraestructure-request-dto.ts b/src/user/infraestructure/services/dto/request/user-registered-infraestructure-request-dto.ts new file mode 100644 index 00000000..00796436 --- /dev/null +++ b/src/user/infraestructure/services/dto/request/user-registered-infraestructure-request-dto.ts @@ -0,0 +1,18 @@ +export interface UserRegistredInfraestructureRequestDTO { + userId: string; + userName: string; + userPhone: string; + wallet: { + walletId: string; + ballance: { + currency: string; + amount: number; + }; + }; + coupons: { + id: string; + state: string; + }[]; + userImage: string; + userRole: string +} \ No newline at end of file diff --git a/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts b/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts new file mode 100644 index 00000000..a073827a --- /dev/null +++ b/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts @@ -0,0 +1,17 @@ +export interface UserUpdatedInfraestructureRequestDTO { + userId: string; + userName?: string; + userPhone?: string; + wallet?: { + walletId: string; + ballance: { + currency: string; + amount: number; + }; + }; + coupons?: { + id: string; + state: string; + }[]; + userImage?: string; +} \ No newline at end of file diff --git a/src/user/infraestructure/services/syncronice/user-registered-syncronice.service.ts b/src/user/infraestructure/services/syncronice/user-registered-syncronice.service.ts new file mode 100644 index 00000000..c41e4e1f --- /dev/null +++ b/src/user/infraestructure/services/syncronice/user-registered-syncronice.service.ts @@ -0,0 +1,37 @@ +import { Result } from 'src/common/utils/result-handler/result'; +import { ISycnchronizeService } from 'src/common/infraestructure/synchronize-service/synchronize.service.interface'; +import { Model, Mongoose } from 'mongoose'; +import { OdmUserEntity, OdmUserSchema } from '../../entities/odm-entities/odm-user-entity'; +import { UserRegistredInfraestructureRequestDTO } from '../dto/request/user-registered-infraestructure-request-dto'; +import { UserRoles } from 'src/user/domain/value-object/enum/user.roles'; + +export class UserRegisteredSyncroniceService +implements ISycnchronizeService{ + + private readonly model: Model + + + constructor( mongoose: Mongoose ) { + this.model = mongoose.model('odmuser', OdmUserSchema) + } + + async execute(event: UserRegistredInfraestructureRequestDTO): Promise> { + + const user = new this.model({ + id:event.userId, + name:event.userName, + phone:event.userPhone, + image:event.userImage, + type:event.userRole as UserRoles, + direction:[], + wallet:{ + id:event.wallet.walletId, + currency:event.wallet.ballance.currency, + amount: event.wallet.ballance.amount + }, + coupon:[] + }) + await this.model.create(user) + return Result.success(undefined) + } +} \ No newline at end of file diff --git a/src/user/infraestructure/services/syncronice/user-updated-syncronice.service.ts b/src/user/infraestructure/services/syncronice/user-updated-syncronice.service.ts new file mode 100644 index 00000000..17d261c3 --- /dev/null +++ b/src/user/infraestructure/services/syncronice/user-updated-syncronice.service.ts @@ -0,0 +1,53 @@ +import { Result } from 'src/common/utils/result-handler/result'; +import { ISycnchronizeService } from 'src/common/infraestructure/synchronize-service/synchronize.service.interface'; +import { Model, Mongoose } from 'mongoose'; +import { OdmUserEntity, OdmUserSchema } from '../../entities/odm-entities/odm-user-entity'; +import { UserUpdatedInfraestructureRequestDTO } from '../dto/request/user-updated-infraestructure-request-dto'; + +export class UserUpdatedSyncroniceService +implements ISycnchronizeService{ + + private readonly model: Model + + + constructor( mongoose: Mongoose ) { + this.model = mongoose.model('odmuser', OdmUserSchema) + } + + async execute(event: UserUpdatedInfraestructureRequestDTO): Promise> { + + let user= await this.model.findOne({id:event.userId}) + + if(event.userImage) + await this.model.updateOne({ id: event.userId }, {$set: {image: event.userImage}}) + + if(event.userName) + await this.model.updateOne({ id: event.userId }, {$set: {name: event.userName}}) + + if(event.userPhone) + await this.model.updateOne({ id: event.userId }, {$set: {phone: event.userPhone}}) + + if(event.wallet) + await this.model.updateOne({ id: event.userId }, {$set: {wallet: { + id:event.wallet.walletId, + currency:event.wallet.ballance.currency, + amount:event.wallet.ballance.amount + }}}) + + if (event.coupons) { + for (const newCoupon of event.coupons) { + let coupon = user.coupon.find(c => c.id === newCoupon.id); + if (!coupon) { + user.coupon.push(newCoupon) + } else { + user.coupon = user.coupon.filter(c => c.id !== newCoupon.id) + user.coupon.unshift(newCoupon) + } + } + await user.save() + } + + + return Result.success(undefined) + } +} \ No newline at end of file From d987ce1d966ede1bd9ff0be47f0aa787200a0d99 Mon Sep 17 00:00:00 2001 From: C102002 Date: Thu, 16 Jan 2025 14:03:23 -0400 Subject: [PATCH 4/8] feat: :building_construction: add user modify cqrs --- .../odm-bundle-query-repository.ts | 2 +- .../odm-product-query-repository.ts | 4 +- .../controller/user.controller.ts | 87 +++++++++++++++++++ .../user-coupon-aplied.interface.ts | 2 +- .../user-phone-updated.interface.ts | 2 +- ...ser-updated-infraestructure-request-dto.ts | 8 ++ 6 files changed, 100 insertions(+), 5 deletions(-) diff --git a/src/bundle/infraestructure/repositories/odm-repository/odm-bundle-query-repository.ts b/src/bundle/infraestructure/repositories/odm-repository/odm-bundle-query-repository.ts index ffdc9bb9..84f11770 100644 --- a/src/bundle/infraestructure/repositories/odm-repository/odm-bundle-query-repository.ts +++ b/src/bundle/infraestructure/repositories/odm-repository/odm-bundle-query-repository.ts @@ -95,7 +95,7 @@ export class OdmBundleQueryRepository implements IQueryBundleRepository{ query.category = { $elemMatch: { name: { $in: criteria.category.map((c: string) => new RegExp(c, 'i')) } } }; if (criteria.price) - query.price = { ...query.price, $gte: criteria.price } + query.price = { ...query.price, $lt: criteria.price } diff --git a/src/product/infraestructure/repositories/odm-repository/odm-product-query-repository.ts b/src/product/infraestructure/repositories/odm-repository/odm-product-query-repository.ts index 7224375c..5ba64c56 100644 --- a/src/product/infraestructure/repositories/odm-repository/odm-product-query-repository.ts +++ b/src/product/infraestructure/repositories/odm-repository/odm-product-query-repository.ts @@ -79,8 +79,8 @@ export class OdmProductQueryRepository implements IQueryProductRepository { query.category = { $elemMatch: { name: { $in: criteria.category.map((c: string) => new RegExp(c, 'i')) } } }; if (criteria.price) - query.price = { ...query.price, $gte: criteria.price } - + query.price = { ...query.price, $lt: criteria.price } + const products = await this.model.find(query) .skip(criteria.page) .limit(criteria.perPage) diff --git a/src/user/infraestructure/controller/user.controller.ts b/src/user/infraestructure/controller/user.controller.ts index d5e728b8..c6e9e4d7 100644 --- a/src/user/infraestructure/controller/user.controller.ts +++ b/src/user/infraestructure/controller/user.controller.ts @@ -64,6 +64,17 @@ import { UpdateProfileApplicationResponseDTO } from "src/user/application/dto/re import { OdmCuponQueryRepository } from "src/cupon/infraestructure/repository/odm-repository/odm-query-coupon-repository" import { IUserRegistered } from "../interfaces/user-registered.interface" import { UserRegisteredSyncroniceService } from "../services/syncronice/user-registered-syncronice.service" +import { UserUpdatedInfraestructureRequestDTO } from "../services/dto/request/user-updated-infraestructure-request-dto" +import { UserUpdatedSyncroniceService } from "../services/syncronice/user-updated-syncronice.service" +import { IUserBalanceAmountAdded } from "../interfaces/user-balance-amount-added.interface" +import { IUserBalanceAmountDecremented } from "../interfaces/user-balance-amount-decremented.interface" +import { IUserCouponAplied } from "../interfaces/user-coupon-aplied.interface" +import { IUserDirectionAdded } from "../interfaces/user-direction-added.interface" +import { IUserDirectionDeleted } from "../interfaces/user-direction-deleted.interface" +import { IUserDirectionUpdated } from "../interfaces/user-direction-updated.interface" +import { IUserImageUpdated } from "../interfaces/user-image-updated.interface" +import { IUserNameUpdated } from "../interfaces/user-name-updated.interface" +import { IUserPhoneUpdated } from "../interfaces/user-phone-updated.interface" @ApiBearerAuth() @UseGuards(JwtAuthGuard) @@ -129,6 +140,77 @@ export class UserController { } ) + this.subscriber.consume( + { name: 'UserSync/UserBalanceAmountAdded'}, + (data):Promise=>{ + this.userupdatedsync(data) + return + } + ) + + this.subscriber.consume( + { name: 'UserSync/UserBalanceAmountDecremented'}, + (data):Promise=>{ + this.userupdatedsync(data) + return + } + ) + + this.subscriber.consume( + { name: 'UserSync/UserCouponAplied'}, + (data):Promise=>{ + this.userupdatedsync({...data,coupons:[{...data.coupons}]}) + return + } + ) + + this.subscriber.consume( + { name: 'UserSync/UserDirectionAdded'}, + (data):Promise=>{ + this.userupdatedsync({...data}) + return + } + ) + + // this.subscriber.consume( + // { name: 'UserSync/UserDirectionDeleted'}, + // (data):Promise=>{ + // this.userupdatedsync({...data,}) + // return + // } + // ) + + this.subscriber.consume( + { name: 'UserSync/UserDirectionUpdated'}, + (data):Promise=>{ + this.userupdatedsync({...data}) + return + } + ) + this.subscriber.consume( + { name: 'UserSync/UserImageUpdated'}, + (data):Promise=>{ + this.userupdatedsync({...data}) + return + } + ) + + this.subscriber.consume( + { name: 'UserSync/UserNameUpdated' }, + (data):Promise=>{ + this.userupdatedsync({...data}) + return + } + ) + + this.subscriber.consume( + { name: 'UserSync/UserPhoneUpdated'}, + (data):Promise=>{ + this.userupdatedsync({...data}) + return + } + ) + this.subscriber.consume( { name: 'UserSync/UserRegistered'}, (data):Promise=>{ @@ -143,6 +225,11 @@ export class UserController { await service.execute(data) } + async userupdatedsync(data:UserUpdatedInfraestructureRequestDTO){ + let service=new UserUpdatedSyncroniceService(this.mongoose) + await service.execute(data) + } + @Patch('update/profile') @ApiResponse({ status: 200, diff --git a/src/user/infraestructure/interfaces/user-coupon-aplied.interface.ts b/src/user/infraestructure/interfaces/user-coupon-aplied.interface.ts index 8ecea176..341744e7 100644 --- a/src/user/infraestructure/interfaces/user-coupon-aplied.interface.ts +++ b/src/user/infraestructure/interfaces/user-coupon-aplied.interface.ts @@ -1,4 +1,4 @@ -export interface UserCouponAplied { +export interface IUserCouponAplied { userId:string, coupons: { id: string; diff --git a/src/user/infraestructure/interfaces/user-phone-updated.interface.ts b/src/user/infraestructure/interfaces/user-phone-updated.interface.ts index db5e264b..2d834052 100644 --- a/src/user/infraestructure/interfaces/user-phone-updated.interface.ts +++ b/src/user/infraestructure/interfaces/user-phone-updated.interface.ts @@ -1,4 +1,4 @@ -export interface IPhoneUpdated{ +export interface IUserPhoneUpdated{ userId: string; userPhone: string; } diff --git a/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts b/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts index a073827a..de896600 100644 --- a/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts +++ b/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts @@ -14,4 +14,12 @@ export interface UserUpdatedInfraestructureRequestDTO { state: string; }[]; userImage?: string; + + userDirection?: { + id: string; + name: string; + favorite: boolean; + lat: number; + lng: number; + } } \ No newline at end of file From 2e2dc50395732a85c9a51f08451e910dd2617e98 Mon Sep 17 00:00:00 2001 From: C102002 Date: Thu, 16 Jan 2025 18:14:13 -0400 Subject: [PATCH 5/8] feat: :sparkles: continuin user cqrs --- .../odm-account-query-repository.ts | 80 ++++++++++++++--- .../odm-token-query-session-repository.ts | 28 +++++- .../odm-bundle-query-repository.ts | 7 -- .../entities/orm-entities/orm-order-entity.ts | 2 +- .../controller/user.controller.ts | 31 ++++--- .../mapper/odm-mapper/odm-user-mapper.ts | 73 ++++++++++++++++ .../odm-user-query-repository.ts | 87 ++++++++++++++++--- ...ser-updated-infraestructure-request-dto.ts | 8 +- .../user-updated-syncronice.service.ts | 3 +- 9 files changed, 265 insertions(+), 54 deletions(-) create mode 100644 src/user/infraestructure/mapper/odm-mapper/odm-user-mapper.ts diff --git a/src/auth/infraestructure/repositories/odm-repository/odm-account-query-repository.ts b/src/auth/infraestructure/repositories/odm-repository/odm-account-query-repository.ts index f76c8a43..2d45f343 100644 --- a/src/auth/infraestructure/repositories/odm-repository/odm-account-query-repository.ts +++ b/src/auth/infraestructure/repositories/odm-repository/odm-account-query-repository.ts @@ -1,30 +1,82 @@ import { IQueryAccountRepository } from "src/auth/application/repository/query-account-repository.interface" -import { OrmAccountEntity } from "../../account/orm-entities/orm-account-entity" -import { DataSource, Repository } from "typeorm" import { IAccount } from "src/auth/application/model/account.interface" import { Result } from "src/common/utils/result-handler/result" import { NotFoundException } from "src/common/infraestructure/infraestructure-exception" +import { OdmAccount, OdmAccountSchema } from "../../account/odm-entities/odm-account-entity" +import { Model, Mongoose } from "mongoose" export class OdmAccountQueryRepository implements IQueryAccountRepository{ - constructor(dataSource:DataSource){} - - findAccountByEmail(email: string): Promise> { - throw new Error("Method not implemented.") + private readonly model: Model; + + constructor( mongoose: Mongoose ) { + this.model = mongoose.model('odmaccount', OdmAccountSchema) + } + + async findAccountByEmail(email: string): Promise> { + try{ + let odm=await this.model.findOne({email}) + + if(!odm) + return Result.fail( new NotFoundException('Find account by email unsucssessfully')) + + return Result.success(odm) + } + catch(e){ + return Result.fail( new NotFoundException('Find account by email unsucssessfully')) + } } - findAccountById(id: string): Promise> { - throw new Error("Method not implemented.") + async findAccountById(id: string): Promise> { + try{ + let odm=await this.model.findOne({id}) + + if(!odm) + return Result.fail( new NotFoundException('Find account by id unsucssessfully')) + + return Result.success(odm) + } + catch(e){ + return Result.fail( new NotFoundException('Find account by id unsucssessfully')) + } } - findAccountByUserId(userId: string): Promise> { - throw new Error("Method not implemented.") + async findAccountByUserId(userId: string): Promise> { + try{ + let odm=await this.model.findOne({idUser:userId}) + + if(!odm) + return Result.fail( new NotFoundException('Find account by user id unsucssessfully')) + + return Result.success(odm) + } + catch(e){ + return Result.fail( new NotFoundException('Find account by user id unsucssessfully')) + } } - verifyAccountExistanceByEmail(email: string): Promise> { - throw new Error("Method not implemented.") + async verifyAccountExistanceByEmail(email: string): Promise> { + try{ + let odm=await this.model.findOne({email}) + if(!odm) + return Result.success(false) + return Result.success(true) + } + catch(e){ + return Result.fail( new NotFoundException('Verify account by email unsucssessfully')) + } } - findAllEmails(): Promise> { - throw new Error("Method not implemented.") + async findAllEmails(): Promise> { + try{ + let odm=await this.model.find() + if(!odm) + return Result.success(odm + ? odm.map(o=>o.email) + : [] + ) + } + catch(e){ + return Result.fail( new NotFoundException('Find all emails unsucssessfully')) + } } } \ No newline at end of file diff --git a/src/auth/infraestructure/repositories/odm-repository/odm-token-query-session-repository.ts b/src/auth/infraestructure/repositories/odm-repository/odm-token-query-session-repository.ts index 4913f595..e7d8dc09 100644 --- a/src/auth/infraestructure/repositories/odm-repository/odm-token-query-session-repository.ts +++ b/src/auth/infraestructure/repositories/odm-repository/odm-token-query-session-repository.ts @@ -1,23 +1,43 @@ +import { Model, Mongoose } from "mongoose"; import { ISession } from "src/auth/application/model/session.interface" import { IQueryTokenSessionRepository } from "src/auth/application/repository/query-token-session-repository.interface" import { Result } from "src/common/utils/result-handler/result" import { UserId } from "src/user/domain/value-object/user-id" +import { OdmAccount, OdmAccountSchema } from "../../account/odm-entities/odm-account-entity"; +import { NotFoundException } from "src/common/infraestructure/infraestructure-exception"; export class OrmTokenQueryRepository implements IQueryTokenSessionRepository{ + + private readonly model: Model; + + constructor( mongoose: Mongoose ) { + this.model = mongoose.model('odmaccount', OdmAccountSchema) + } findAllLastTokenSessions(): Promise> { throw new Error("Method not implemented.") } - findSessionById(id: string): Promise> { - throw new Error("Method not implemented.") + async findSessionById(id: string): Promise> { + try{ + //TODO + let odm=await this.model.find({"sessions.id":id}) + } + catch(e){ + return Result.fail( new NotFoundException('Find session unsucssessfully')) + } } findAllTokenSessions(): Promise> { throw new Error("Method not implemented.") } - findSessionLastSessionByUserId(id: UserId): Promise> { - throw new Error("Method not implemented.") + async findSessionLastSessionByUserId(id: UserId): Promise> { + try{ + let odm=await this.model.find({idUser:id.Value}) + } + catch(e){ + return Result.fail( new NotFoundException('Find all emails unsucssessfully')) + } } } \ No newline at end of file diff --git a/src/bundle/infraestructure/repositories/odm-repository/odm-bundle-query-repository.ts b/src/bundle/infraestructure/repositories/odm-repository/odm-bundle-query-repository.ts index 84f11770..bf8dde3f 100644 --- a/src/bundle/infraestructure/repositories/odm-repository/odm-bundle-query-repository.ts +++ b/src/bundle/infraestructure/repositories/odm-repository/odm-bundle-query-repository.ts @@ -64,13 +64,6 @@ export class OdmBundleQueryRepository implements IQueryBundleRepository{ discount:p.discount })) : [], - // odm.promotions - // ? odm.promotions.map(promotion=>({ - // id:promotion.id, - // name:promotion.name, - // discount:Number(promotion.discount) - // })) - // : [] products: odm.products ? odm.products.map(p=>({ id:p.id, diff --git a/src/order/infraestructure/entities/orm-entities/orm-order-entity.ts b/src/order/infraestructure/entities/orm-entities/orm-order-entity.ts index 62eb1b62..0d3ab678 100644 --- a/src/order/infraestructure/entities/orm-entities/orm-order-entity.ts +++ b/src/order/infraestructure/entities/orm-entities/orm-order-entity.ts @@ -56,7 +56,7 @@ export class OrmOrderEntity implements IOrderInterface { @JoinColumn() order_report?: OrmOrderReportEntity; - @OneToOne( () => OrmCourierEntity, (courier) => courier.orders, { nullable: true, eager: true} ) + @ManyToOne( () => OrmCourierEntity, (courier) => courier.orders, { nullable: true, eager: true} ) @JoinColumn({ name: 'courier_id' }) order_courier?: OrmCourierEntity | null; diff --git a/src/user/infraestructure/controller/user.controller.ts b/src/user/infraestructure/controller/user.controller.ts index c6e9e4d7..ca4987f1 100644 --- a/src/user/infraestructure/controller/user.controller.ts +++ b/src/user/infraestructure/controller/user.controller.ts @@ -75,6 +75,8 @@ import { IUserDirectionUpdated } from "../interfaces/user-direction-updated.inte import { IUserImageUpdated } from "../interfaces/user-image-updated.interface" import { IUserNameUpdated } from "../interfaces/user-name-updated.interface" import { IUserPhoneUpdated } from "../interfaces/user-phone-updated.interface" +import { OdmUserQueryRepository } from '../repositories/odm-repository/odm-user-query-repository'; +import { OdmAccountQueryRepository } from "src/auth/infraestructure/repositories/odm-repository/odm-account-query-repository" @ApiBearerAuth() @UseGuards(JwtAuthGuard) @@ -94,6 +96,10 @@ export class UserController { private readonly hereMapsSingelton: HereMapsSingelton; private readonly ormCuponQueryRepo: IQueryCuponRepository; private readonly subscriber: RabbitMQSubscriber; + private readonly odmUserQueryRepository:IQueryUserRepository + private readonly odmAccountQueryRepo:IQueryAccountRepository + private readonly odmCuponQueryRepo: IQueryCuponRepository; + private initializeQueues():void{ UserQueues.forEach(queue => this.buildQueue(queue.name, queue.pattern)) @@ -129,6 +135,9 @@ export class UserController { this.geocodification= new GeocodificationOpenStreeMapsDomainService() this.ormCuponQueryRepo = new OdmCuponQueryRepository(mongoose); this.subscriber= new RabbitMQSubscriber(this.channel); + this.odmAccountQueryRepo= new OdmAccountQueryRepository(mongoose) + this.odmUserQueryRepository= new OdmUserQueryRepository(mongoose), + this.odmCuponQueryRepo= new OdmCuponQueryRepository(mongoose) this.initializeQueues(); @@ -172,13 +181,13 @@ export class UserController { } ) - // this.subscriber.consume( - // { name: 'UserSync/UserDirectionDeleted'}, - // (data):Promise=>{ - // this.userupdatedsync({...data,}) - // return - // } - // ) + this.subscriber.consume( + { name: 'UserSync/UserDirectionDeleted'}, + (data):Promise=>{ + this.userupdatedsync({...data,userDirection:{id:data.userDirection.id}}) + return + } + ) this.subscriber.consume( { name: 'UserSync/UserDirectionUpdated'}, @@ -259,7 +268,7 @@ export class UserController { new PerformanceDecorator( new UpdateProfileApplicationService( this.ormUserCommandRepo, - this.ormUserQueryRepo, + this.odmUserQueryRepository, this.ormAccountCommandRepo, this.ormAccountQueryRepo, new RabbitMQPublisher(this.channel), @@ -305,7 +314,7 @@ export class UserController { new PerformanceDecorator( new UpdateProfileApplicationService( this.ormUserCommandRepo, - this.ormUserQueryRepo, + this.odmUserQueryRepository, this.ormAccountCommandRepo, this.ormAccountQueryRepo, new RabbitMQPublisher(this.channel), @@ -342,7 +351,7 @@ export class UserController { new LoggerDecorator( new PerformanceDecorator( new FindUserDirectionApplicationService ( - this.ormUserQueryRepo, + this.odmUserQueryRepository, this.geocodification ), new NestTimer(), new NestLogger(new Logger()) ), new NestLogger(new Logger()) @@ -484,7 +493,7 @@ export class UserController { new PerformanceDecorator( new AddUserCouponApplicationService ( this.ormUserCommandRepo, - this.ormUserQueryRepo, + this.odmUserQueryRepository, this.ormCuponQueryRepo, new RabbitMQPublisher(this.channel) ), new NestTimer(), new NestLogger(new Logger()) diff --git a/src/user/infraestructure/mapper/odm-mapper/odm-user-mapper.ts b/src/user/infraestructure/mapper/odm-mapper/odm-user-mapper.ts new file mode 100644 index 00000000..cda8334d --- /dev/null +++ b/src/user/infraestructure/mapper/odm-mapper/odm-user-mapper.ts @@ -0,0 +1,73 @@ +import { IMapper } from "src/common/application/mappers/mapper.interface" +import { User } from "src/user/domain/aggregate/user.aggregate" +import { UserId } from "src/user/domain/value-object/user-id" +import { UserImage } from "src/user/domain/value-object/user-image" +import { UserName } from "src/user/domain/value-object/user-name" +import { UserPhone } from "src/user/domain/value-object/user-phone" +import { UserRole } from "src/user/domain/value-object/user-role" +import { UserRoles } from "src/user/domain/value-object/enum/user.roles" +import { IIdGen } from "src/common/application/id-gen/id-gen.interface" +import { IQueryUserRepository } from 'src/user/application/repository/user.query.repository.interface'; +import { Wallet } from 'src/user/domain/entities/wallet/wallet.entity'; +import { WalletId } from 'src/user/domain/entities/wallet/value-objects/wallet-id'; +import { Ballance } from 'src/user/domain/entities/wallet/value-objects/balance'; +import { OrmWalletEntity } from '../../entities/orm-entities/orm-wallet-entity'; +import { UserDirection } from 'src/user/domain/entities/directions/direction.entity'; +import { DirectionId } from 'src/user/domain/entities/directions/value-objects/direction-id';import { DirectionFavorite } from 'src/user/domain/entities/directions/value-objects/direction-favorite'; +import { DirectionLat } from 'src/user/domain/entities/directions/value-objects/direction-lat'; +import { DirectionLng } from 'src/user/domain/entities/directions/value-objects/direction-lng'; +import { DirectionName } from 'src/user/domain/entities/directions/value-objects/direction-name'; +import { UserCoupon } from "src/user/domain/entities/coupon/user-coupon.entity" +import { CuponId } from "src/cupon/domain/value-object/cupon-id" +import { CuponState } from "src/user/domain/entities/coupon/value-objects/cupon-state" +import { OrmCuponEntity } from "src/cupon/infraestructure/entities/orm-entities/orm-cupon-entity" +import { OrmCuponUserEntity } from "../../entities/orm-entities/orm-coupon-user-entity" +import { OdmUserEntity } from "../../entities/odm-entities/odm-user-entity" + + +export class OdmUserMapper implements IMapper { + + constructor(){} + + async fromDomaintoPersistence(domainEntity: User): Promise { + throw new Error('') + } + async fromPersistencetoDomain(infraEstructure: OdmUserEntity): Promise { + + + let user=User.initializeAggregate( + UserId.create(infraEstructure.id), + UserName.create(infraEstructure.name), + UserPhone.create(infraEstructure.phone), + UserRole.create(infraEstructure.type), + infraEstructure.direction + ? infraEstructure.direction.map(odmdirection=> + UserDirection.create( + DirectionId.create(odmdirection.id), + DirectionFavorite.create(odmdirection.favorite), + DirectionLat.create(odmdirection.lat), + DirectionLng.create(odmdirection.lng), + DirectionName.create(odmdirection.name) + )) + : [], + Wallet.create( + WalletId.create(infraEstructure.wallet.id), + Ballance.create( + infraEstructure.wallet.id + ? Number(Number(infraEstructure.wallet.amount).toFixed(2)) + : 0 + , infraEstructure.wallet.currency, + ) + ), + infraEstructure.coupon + ? infraEstructure.coupon.map(c=> + UserCoupon.create( + CuponId.create(c.id), + CuponState.create(c.state) + )) + : [], + infraEstructure.image ? UserImage.create(infraEstructure.image) : undefined + ) + return user + } +} \ No newline at end of file diff --git a/src/user/infraestructure/repositories/odm-repository/odm-user-query-repository.ts b/src/user/infraestructure/repositories/odm-repository/odm-user-query-repository.ts index 37089bd7..020b89a5 100644 --- a/src/user/infraestructure/repositories/odm-repository/odm-user-query-repository.ts +++ b/src/user/infraestructure/repositories/odm-repository/odm-user-query-repository.ts @@ -7,28 +7,93 @@ import { UserDirection } from "src/user/domain/entities/directions/direction.ent import { DirectionId } from "src/user/domain/entities/directions/value-objects/direction-id"; import { UserId } from "src/user/domain/value-object/user-id"; import { UserPhone } from "src/user/domain/value-object/user-phone"; +import { OdmUserEntity, OdmUserSchema } from "../../entities/odm-entities/odm-user-entity"; +import { OdmUserMapper } from "../../mapper/odm-mapper/odm-user-mapper"; +import { Model, Mongoose } from "mongoose"; +import { OdmPromotionEntity, OdmPromotionSchema } from "src/promotion/infraestructure/entities/odm-entities/odm-promotion-entity"; +import { NotFoundException } from "src/common/infraestructure/infraestructure-exception"; export class OdmUserQueryRepository implements IQueryUserRepository{ + + private readonly model: Model; + private readonly odmMapper: OdmUserMapper + + constructor( mongoose: Mongoose ) { + this.model = mongoose.model('odmuser', OdmUserSchema) + this.odmMapper= new OdmUserMapper() + } - findUserById(id: UserId): Promise> { - throw new Error("Method not implemented."); + async findUserById(id: UserId): Promise> { + try{ + let odm=await this.model.findOne({id:id.Value}) + + if(!odm) + return Result.fail( new NotFoundException('Find User unsucssessfully')) + + return Result.success(await this.odmMapper.fromPersistencetoDomain(odm)) + } + catch(e){ + return Result.fail( new NotFoundException('Find User unsucssessfully')) + } } - findUserByPhoneNumber(phoneNumber: UserPhone): Promise> { - throw new Error("Method not implemented."); + async findUserByPhoneNumber(phoneNumber: UserPhone): Promise> { + try{ + let odm=await this.model.findOne({phone:phoneNumber.Value}) + + if(!odm) + return Result.fail( new NotFoundException('Find User unsucssessfully')) + + return Result.success(await this.odmMapper.fromPersistencetoDomain(odm)) + } + catch(e){ + return Result.fail( new NotFoundException('Find User unsucssessfully')) + } } - verifyUserExistenceByPhoneNumber(phoneNumber: UserPhone): Promise> { - throw new Error("Method not implemented."); + async verifyUserExistenceByPhoneNumber(phoneNumber: UserPhone): Promise> { + try{ + let odm=await this.model.findOne({phone:phoneNumber.Value}) + if(!odm) + return Result.success(false) + return Result.success(true) + } + catch(e){ + return Result.fail( new NotFoundException('Find User unsucssessfully')) + } } - findUserDirectionsByUserId(id: UserId): Promise> { - throw new Error("Method not implemented."); + async findUserDirectionsByUserId(id: UserId): Promise> { + try{ + let odm=await this.model.findOne({id:id.Value}) + if(!odm) + return Result.fail( new NotFoundException('Find User unsucssessfully')) + let domain=await this.odmMapper.fromPersistencetoDomain(odm) + return Result.success(domain.UserDirections.map(d=>({ + id:d.getId().Value, + name: d.DirectionName.Value, + isFavorite: d.DirectionFavorite.Value, + lat: Number(d.DirectionLat.Value), + lng: Number(d.DirectionLng.Value) + }))) + } + catch(e){ + return Result.fail( new NotFoundException('Find User unsucssessfully')) + } } findDirectionsByLatAndLng(userDirection: UserDirection[]): Promise> { throw new Error("Method not implemented."); } - findDirectionById(id: DirectionId, userId: UserId): Promise> { - throw new Error("Method not implemented."); + async findDirectionById(id: DirectionId, userId: UserId): Promise> { + try{ + let odm=await this.model.findOne({id:userId.Value, + "direction.id": id.Value + }) + if(!odm) + return Result.fail( new NotFoundException('Find User unsucssessfully')) + let domain=await this.odmMapper.fromPersistencetoDomain(odm) + } + catch(e){ + return Result.fail( new NotFoundException('Find User unsucssessfully')) + } } - } \ No newline at end of file diff --git a/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts b/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts index de896600..24bffafa 100644 --- a/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts +++ b/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts @@ -17,9 +17,9 @@ export interface UserUpdatedInfraestructureRequestDTO { userDirection?: { id: string; - name: string; - favorite: boolean; - lat: number; - lng: number; + name?: string; + favorite?: boolean; + lat?: number; + lng?: number; } } \ No newline at end of file diff --git a/src/user/infraestructure/services/syncronice/user-updated-syncronice.service.ts b/src/user/infraestructure/services/syncronice/user-updated-syncronice.service.ts index 17d261c3..04c72691 100644 --- a/src/user/infraestructure/services/syncronice/user-updated-syncronice.service.ts +++ b/src/user/infraestructure/services/syncronice/user-updated-syncronice.service.ts @@ -45,8 +45,7 @@ implements ISycnchronizeService{ } } await user.save() - } - + } return Result.success(undefined) } From ced960f3b62d2401c79448ad9e529681a6b151d8 Mon Sep 17 00:00:00 2001 From: C102002 Date: Thu, 16 Jan 2025 19:12:28 -0400 Subject: [PATCH 6/8] fix: :ambulance: fix lowercase in pay order --- src/order/infraestructure/controller/order.controller.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/order/infraestructure/controller/order.controller.ts b/src/order/infraestructure/controller/order.controller.ts index a5cb33f2..3803b54a 100644 --- a/src/order/infraestructure/controller/order.controller.ts +++ b/src/order/infraestructure/controller/order.controller.ts @@ -344,7 +344,9 @@ export class OrderController { paymentId: data.paymentId ? data.paymentId : paymentId, - currency: data.currency.toLowerCase(), + currency: data.currency + ? data.currency.toLowerCase() + : 'usd', paymentMethod: data.paymentMethod, directionId: data.idUserDirection, products: data.products, From 57102f59fa4407c73380b54de3157213335c2c3d Mon Sep 17 00:00:00 2001 From: C102002 Date: Thu, 16 Jan 2025 20:42:32 -0400 Subject: [PATCH 7/8] fix: :bug: fix user sunz and category controller --- .../controller/category.controller.ts | 7 ++++++- .../controller/user.controller.ts | 10 +++++----- ...ser-updated-infraestructure-request-dto.ts | 12 ++++++++---- .../user-updated-syncronice.service.ts | 19 ++++++++++++++++++- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/category/infraestructure/controller/category.controller.ts b/src/category/infraestructure/controller/category.controller.ts index 9a9ec48d..15becc8d 100644 --- a/src/category/infraestructure/controller/category.controller.ts +++ b/src/category/infraestructure/controller/category.controller.ts @@ -198,7 +198,12 @@ export class CategoryController { ); const buffer = image.buffer; - const response = await service.execute({ userId: credential.account.idUser, ...entry, image: buffer }); + const response = await service.execute({ + userId: credential.account.idUser, + name:entry.name, + products:entry.products, + bundles:entry.bundles, + image: buffer }); return response.getValue } diff --git a/src/user/infraestructure/controller/user.controller.ts b/src/user/infraestructure/controller/user.controller.ts index ca4987f1..1a707d11 100644 --- a/src/user/infraestructure/controller/user.controller.ts +++ b/src/user/infraestructure/controller/user.controller.ts @@ -184,7 +184,7 @@ export class UserController { this.subscriber.consume( { name: 'UserSync/UserDirectionDeleted'}, (data):Promise=>{ - this.userupdatedsync({...data,userDirection:{id:data.userDirection.id}}) + this.userupdatedsync({userId:data.userId, userDirectionDelete:{id:data.userDirection.id}}) return } ) @@ -268,7 +268,7 @@ export class UserController { new PerformanceDecorator( new UpdateProfileApplicationService( this.ormUserCommandRepo, - this.odmUserQueryRepository, + this.ormUserQueryRepo, this.ormAccountCommandRepo, this.ormAccountQueryRepo, new RabbitMQPublisher(this.channel), @@ -314,7 +314,7 @@ export class UserController { new PerformanceDecorator( new UpdateProfileApplicationService( this.ormUserCommandRepo, - this.odmUserQueryRepository, + this.ormUserQueryRepo, this.ormAccountCommandRepo, this.ormAccountQueryRepo, new RabbitMQPublisher(this.channel), @@ -351,7 +351,7 @@ export class UserController { new LoggerDecorator( new PerformanceDecorator( new FindUserDirectionApplicationService ( - this.odmUserQueryRepository, + this.ormUserQueryRepo, this.geocodification ), new NestTimer(), new NestLogger(new Logger()) ), new NestLogger(new Logger()) @@ -493,7 +493,7 @@ export class UserController { new PerformanceDecorator( new AddUserCouponApplicationService ( this.ormUserCommandRepo, - this.odmUserQueryRepository, + this.ormUserQueryRepo, this.ormCuponQueryRepo, new RabbitMQPublisher(this.channel) ), new NestTimer(), new NestLogger(new Logger()) diff --git a/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts b/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts index 24bffafa..bb8fffdd 100644 --- a/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts +++ b/src/user/infraestructure/services/dto/request/user-updated-infraestructure-request-dto.ts @@ -17,9 +17,13 @@ export interface UserUpdatedInfraestructureRequestDTO { userDirection?: { id: string; - name?: string; - favorite?: boolean; - lat?: number; - lng?: number; + name: string; + favorite: boolean; + lat: number; + lng: number; + } + + userDirectionDelete?:{ + id:string } } \ No newline at end of file diff --git a/src/user/infraestructure/services/syncronice/user-updated-syncronice.service.ts b/src/user/infraestructure/services/syncronice/user-updated-syncronice.service.ts index 04c72691..5545a0c1 100644 --- a/src/user/infraestructure/services/syncronice/user-updated-syncronice.service.ts +++ b/src/user/infraestructure/services/syncronice/user-updated-syncronice.service.ts @@ -18,6 +18,8 @@ implements ISycnchronizeService{ let user= await this.model.findOne({id:event.userId}) + console.log(event) + if(event.userImage) await this.model.updateOne({ id: event.userId }, {$set: {image: event.userImage}}) @@ -45,7 +47,22 @@ implements ISycnchronizeService{ } } await user.save() - } + } + if (event.userDirectionDelete){ + user.direction.filter(d=>d.id!==event.userDirectionDelete.id) + await user.save() + } + + if (event.userDirection){ + let direction = user.direction.find(d=>d.id==event.userDirection.id); + if (!direction) { + user.direction.push(event.userDirection) + } else { + user.direction = user.direction.filter(d => d.id !== event.userDirection.id) + user.direction.unshift(direction) + } + await user.save() + } return Result.success(undefined) } From 3c3f9afd961e9c89a0d06c7fe3ee069f9b60ba8a Mon Sep 17 00:00:00 2001 From: C102002 Date: Thu, 16 Jan 2025 21:02:51 -0400 Subject: [PATCH 8/8] fix: :bug: find all last token session --- .../orm-token-query-session-repository.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/auth/infraestructure/repositories/orm-repository/orm-token-query-session-repository.ts b/src/auth/infraestructure/repositories/orm-repository/orm-token-query-session-repository.ts index ec07c167..70bff028 100644 --- a/src/auth/infraestructure/repositories/orm-repository/orm-token-query-session-repository.ts +++ b/src/auth/infraestructure/repositories/orm-repository/orm-token-query-session-repository.ts @@ -27,13 +27,15 @@ export class OrmTokenQueryRepository extends Repository implem try{ const sessions = await this.createQueryBuilder("session") .select("session.push_token") - .orderBy("session.created_at", "DESC") + .orderBy("session.expired_at", "DESC") .limit(1) .getMany() - const tokens = sessions.map(session => session.push_token) - return Result.success(tokens) + return Result.success(sessions + ? sessions.map(session => session.push_token) + : [] + ) }catch(e){ - return Result.fail( new NotFoundException('Error finding all emails')) + return Result.fail( new NotFoundException('Error finding all tokens')) } }