From 738e9c9c69d63bda0f35a5489c3526ab522bc7e0 Mon Sep 17 00:00:00 2001 From: David Arranz Date: Fri, 12 Jul 2024 18:37:41 +0200 Subject: [PATCH] . --- .../profile/application/GetProfile.useCase.ts | 1 + .../infrastructure/mappers/profile.mapper.ts | 41 ++++++++----- .../profile/infrastructure/sequelize/index.ts | 1 - .../infrastructure/sequelize/profile.model.ts | 61 ------------------- .../application/Dealer/GetDealer.useCase.ts | 6 +- .../Dealer/GetDealerByUser.useCase.ts | 6 +- .../application/Quote/CreateQuote.useCase.ts | 3 +- .../Quote/GetQuoteByUser.useCase.ts | 6 +- .../application/Quote/UpdateQuote.useCase.ts | 3 +- .../infrastructure/mappers/quote.mapper.ts | 12 +++- 10 files changed, 56 insertions(+), 84 deletions(-) delete mode 100644 server/src/contexts/profile/infrastructure/sequelize/index.ts delete mode 100644 server/src/contexts/profile/infrastructure/sequelize/profile.model.ts diff --git a/server/src/contexts/profile/application/GetProfile.useCase.ts b/server/src/contexts/profile/application/GetProfile.useCase.ts index de08618..f82e4d9 100644 --- a/server/src/contexts/profile/application/GetProfile.useCase.ts +++ b/server/src/contexts/profile/application/GetProfile.useCase.ts @@ -62,6 +62,7 @@ export class GetProfileUseCase return Result.ok(profile!); } catch (error: unknown) { const _error = error as IInfrastructureError; + console.error(error); return Result.fail( UseCaseError.create(UseCaseError.REPOSITORY_ERROR, "Error al consultar el usuario", _error) ); diff --git a/server/src/contexts/profile/infrastructure/mappers/profile.mapper.ts b/server/src/contexts/profile/infrastructure/mappers/profile.mapper.ts index ee817b1..0b2aac5 100644 --- a/server/src/contexts/profile/infrastructure/mappers/profile.mapper.ts +++ b/server/src/contexts/profile/infrastructure/mappers/profile.mapper.ts @@ -4,17 +4,16 @@ import { SequelizeMapper, } from "@/contexts/common/infrastructure"; import { DealerStatus } from "@/contexts/sales/domain"; -import { Dealer_Model } from "@/contexts/sales/infrastructure/sequelize"; -import { CurrencyData, Language, Name, Note, UniqueID } from "@shared/contexts"; +import { Dealer_Model, DealerCreationAttributes } from "@/contexts/sales/infrastructure/sequelize"; +import { CurrencyData, Language, Name, TextValueObject, UniqueID } from "@shared/contexts"; import { IProfileProps, Profile } from "../../domain"; import { IProfileContext } from "../Profile.context"; -import { ProfileCreationAttributes, Profile_Model } from "../sequelize"; export interface IProfileMapper - extends ISequelizeMapper {} + extends ISequelizeMapper, Profile> {} class ProfileMapper - extends SequelizeMapper + extends SequelizeMapper, Profile> implements IProfileMapper { public constructor(props: { context: IProfileContext }) { @@ -27,11 +26,23 @@ class ProfileMapper const language = this.mapsValue(source, "lang_code", Language.createFromCode); const currency = this.mapsValue(source, "currency_code", CurrencyData.createFromCode); - const contactInformation = this.mapsValue(source, "contact_information", Note.create); - const defaultPaymentMethod = this.mapsValue(source, "default_payment_method", Note.create); - const defaultNotes = this.mapsValue(source, "default_notes", Note.create); - const defaultLegalTerms = this.mapsValue(source, "default_legal_terms", Note.create); - const defaultQuoteValidity = this.mapsValue(source, "default_quote_validity", Note.create); + const contactInformation = this.mapsValue( + source, + "contact_information", + TextValueObject.create + ); + const defaultPaymentMethod = this.mapsValue( + source, + "default_payment_method", + TextValueObject.create + ); + const defaultNotes = this.mapsValue(source, "default_notes", TextValueObject.create); + const defaultLegalTerms = this.mapsValue(source, "default_legal_terms", TextValueObject.create); + const defaultQuoteValidity = this.mapsValue( + source, + "default_quote_validity", + TextValueObject.create + ); const props: IProfileProps = { name, @@ -60,11 +71,11 @@ class ProfileMapper return { id: source.id.toPrimitive(), - contact_information: source.contactInformation, - default_payment_method: source.defaultPaymentMethod, - default_notes: source.defaultNotes, - default_legal_terms: source.defaultLegalTerms, - default_quote_validity: source.defaultQuoteValidity, + contact_information: source.contactInformation.toPrimitive(), + default_payment_method: source.defaultPaymentMethod.toPrimitive(), + default_notes: source.defaultNotes.toPrimitive(), + default_legal_terms: source.defaultLegalTerms.toPrimitive(), + default_quote_validity: source.defaultQuoteValidity.toPrimitive(), }; } } diff --git a/server/src/contexts/profile/infrastructure/sequelize/index.ts b/server/src/contexts/profile/infrastructure/sequelize/index.ts deleted file mode 100644 index c24024b..0000000 --- a/server/src/contexts/profile/infrastructure/sequelize/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./profile.model"; diff --git a/server/src/contexts/profile/infrastructure/sequelize/profile.model.ts b/server/src/contexts/profile/infrastructure/sequelize/profile.model.ts deleted file mode 100644 index 547618c..0000000 --- a/server/src/contexts/profile/infrastructure/sequelize/profile.model.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { - CreationOptional, - DataTypes, - InferAttributes, - InferCreationAttributes, - Model, - Sequelize, -} from "sequelize"; - -export type ProfileCreationAttributes = InferCreationAttributes; - -export class Profile_Model extends Model< - InferAttributes, - InferCreationAttributes -> { - // To avoid table creation - /*static async sync(): Promise { - return Promise.resolve(); - }*/ - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - static associate(connection: Sequelize) {} - - declare id: string; - declare contact_information: CreationOptional; - declare default_payment_method: CreationOptional; - declare default_notes: CreationOptional; - declare default_legal_terms: CreationOptional; - declare default_quote_validity: CreationOptional; -} - -export default (sequelize: Sequelize) => { - Profile_Model.init( - { - id: { - type: new DataTypes.UUID(), - primaryKey: true, - }, - - contact_information: DataTypes.TEXT, - default_payment_method: DataTypes.TEXT, - default_notes: DataTypes.TEXT, - default_legal_terms: DataTypes.TEXT, - default_quote_validity: DataTypes.TEXT, - }, - { - sequelize, - tableName: "dealers", - - paranoid: true, // softs deletes - timestamps: true, - //version: true, - - createdAt: "created_at", - updatedAt: "updated_at", - deletedAt: "deleted_at", - } - ); - - return Profile_Model; -}; diff --git a/server/src/contexts/sales/application/Dealer/GetDealer.useCase.ts b/server/src/contexts/sales/application/Dealer/GetDealer.useCase.ts index ee24b35..9b3e0bc 100644 --- a/server/src/contexts/sales/application/Dealer/GetDealer.useCase.ts +++ b/server/src/contexts/sales/application/Dealer/GetDealer.useCase.ts @@ -59,7 +59,11 @@ export class GetDealerUseCase } catch (error: unknown) { const _error = error as IInfrastructureError; return Result.fail( - UseCaseError.create(UseCaseError.REPOSITORY_ERROR, "Error al consultar el usuario", _error) + UseCaseError.create( + UseCaseError.REPOSITORY_ERROR, + "Error al consultar el distribuidor", + _error + ) ); } } diff --git a/server/src/contexts/sales/application/Dealer/GetDealerByUser.useCase.ts b/server/src/contexts/sales/application/Dealer/GetDealerByUser.useCase.ts index c594911..cd6db42 100644 --- a/server/src/contexts/sales/application/Dealer/GetDealerByUser.useCase.ts +++ b/server/src/contexts/sales/application/Dealer/GetDealerByUser.useCase.ts @@ -67,7 +67,11 @@ export class GetDealerByUserUseCase } catch (error: unknown) { const _error = error as IInfrastructureError; return Result.fail( - UseCaseError.create(UseCaseError.REPOSITORY_ERROR, "Error al consultar el usuario", _error) + UseCaseError.create( + UseCaseError.REPOSITORY_ERROR, + "Error al consultar el distribuidor", + _error + ) ); } } diff --git a/server/src/contexts/sales/application/Quote/CreateQuote.useCase.ts b/server/src/contexts/sales/application/Quote/CreateQuote.useCase.ts index b67fb0f..7c6b817 100644 --- a/server/src/contexts/sales/application/Quote/CreateQuote.useCase.ts +++ b/server/src/contexts/sales/application/Quote/CreateQuote.useCase.ts @@ -14,6 +14,7 @@ import { Percentage, Quantity, Result, + TextValueObject, UTCDateValue, UniqueID, UnitPrice, @@ -168,7 +169,7 @@ export class CreateQuoteUseCase return Result.fail(paymentOrError.error); } - const notesOrError = Note.create(quoteDTO.notes); + const notesOrError = TextValueObject.create(quoteDTO.notes); if (notesOrError.isFailure) { return Result.fail(notesOrError.error); } diff --git a/server/src/contexts/sales/application/Quote/GetQuoteByUser.useCase.ts b/server/src/contexts/sales/application/Quote/GetQuoteByUser.useCase.ts index bb7c0d2..ece03ed 100644 --- a/server/src/contexts/sales/application/Quote/GetQuoteByUser.useCase.ts +++ b/server/src/contexts/sales/application/Quote/GetQuoteByUser.useCase.ts @@ -66,7 +66,11 @@ export class GetQuoteByUserUseCase } catch (error: unknown) { const _error = error as IInfrastructureError; return Result.fail( - UseCaseError.create(UseCaseError.REPOSITORY_ERROR, "Error al consultar el usuario", _error) + UseCaseError.create( + UseCaseError.REPOSITORY_ERROR, + "Error al consultar la cotización", + _error + ) ); } } diff --git a/server/src/contexts/sales/application/Quote/UpdateQuote.useCase.ts b/server/src/contexts/sales/application/Quote/UpdateQuote.useCase.ts index bfd6439..0c6f26c 100644 --- a/server/src/contexts/sales/application/Quote/UpdateQuote.useCase.ts +++ b/server/src/contexts/sales/application/Quote/UpdateQuote.useCase.ts @@ -18,6 +18,7 @@ import { Percentage, Quantity, Result, + TextValueObject, UTCDateValue, UniqueID, UnitPrice, @@ -167,7 +168,7 @@ export class UpdateQuoteUseCase return Result.fail(paymentOrError.error); } - const notesOrError = Note.create(quoteDTO.notes); + const notesOrError = TextValueObject.create(quoteDTO.notes); if (notesOrError.isFailure) { return Result.fail(notesOrError.error); } diff --git a/server/src/contexts/sales/infrastructure/mappers/quote.mapper.ts b/server/src/contexts/sales/infrastructure/mappers/quote.mapper.ts index 0c846a2..315564c 100644 --- a/server/src/contexts/sales/infrastructure/mappers/quote.mapper.ts +++ b/server/src/contexts/sales/infrastructure/mappers/quote.mapper.ts @@ -1,4 +1,12 @@ -import { CurrencyData, Language, Note, Percentage, UTCDateValue, UniqueID } from "@shared/contexts"; +import { + CurrencyData, + Language, + Note, + Percentage, + TextValueObject, + UTCDateValue, + UniqueID, +} from "@shared/contexts"; import { ISequelizeMapper, SequelizeMapper } from "@/contexts/common/infrastructure"; import { IQuoteProps, Quote, QuoteCustomer, QuoteReference } from "../../domain"; @@ -41,7 +49,7 @@ class QuoteMapper validity: this.mapsValue(source, "validity", Note.create), paymentMethod: this.mapsValue(source, "payment_method", Note.create), - notes: this.mapsValue(source, "notes", Note.create), + notes: this.mapsValue(source, "notes", TextValueObject.create), items,