.
This commit is contained in:
parent
533b22dd98
commit
738e9c9c69
@ -62,6 +62,7 @@ export class GetProfileUseCase
|
||||
return Result.ok<Profile>(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)
|
||||
);
|
||||
|
||||
@ -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<Profile_Model, ProfileCreationAttributes, Profile> {}
|
||||
extends ISequelizeMapper<Dealer_Model, Partial<DealerCreationAttributes>, Profile> {}
|
||||
|
||||
class ProfileMapper
|
||||
extends SequelizeMapper<Profile_Model, ProfileCreationAttributes, Profile>
|
||||
extends SequelizeMapper<Dealer_Model, Partial<DealerCreationAttributes>, 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(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1 +0,0 @@
|
||||
export * from "./profile.model";
|
||||
@ -1,61 +0,0 @@
|
||||
import {
|
||||
CreationOptional,
|
||||
DataTypes,
|
||||
InferAttributes,
|
||||
InferCreationAttributes,
|
||||
Model,
|
||||
Sequelize,
|
||||
} from "sequelize";
|
||||
|
||||
export type ProfileCreationAttributes = InferCreationAttributes<Profile_Model>;
|
||||
|
||||
export class Profile_Model extends Model<
|
||||
InferAttributes<Profile_Model>,
|
||||
InferCreationAttributes<Profile_Model>
|
||||
> {
|
||||
// To avoid table creation
|
||||
/*static async sync(): Promise<any> {
|
||||
return Promise.resolve();
|
||||
}*/
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
static associate(connection: Sequelize) {}
|
||||
|
||||
declare id: string;
|
||||
declare contact_information: CreationOptional<string>;
|
||||
declare default_payment_method: CreationOptional<string>;
|
||||
declare default_notes: CreationOptional<string>;
|
||||
declare default_legal_terms: CreationOptional<string>;
|
||||
declare default_quote_validity: CreationOptional<string>;
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user