.
This commit is contained in:
parent
533b22dd98
commit
738e9c9c69
@ -62,6 +62,7 @@ export class GetProfileUseCase
|
|||||||
return Result.ok<Profile>(profile!);
|
return Result.ok<Profile>(profile!);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const _error = error as IInfrastructureError;
|
const _error = error as IInfrastructureError;
|
||||||
|
console.error(error);
|
||||||
return Result.fail(
|
return Result.fail(
|
||||||
UseCaseError.create(UseCaseError.REPOSITORY_ERROR, "Error al consultar el usuario", _error)
|
UseCaseError.create(UseCaseError.REPOSITORY_ERROR, "Error al consultar el usuario", _error)
|
||||||
);
|
);
|
||||||
|
|||||||
@ -4,17 +4,16 @@ import {
|
|||||||
SequelizeMapper,
|
SequelizeMapper,
|
||||||
} from "@/contexts/common/infrastructure";
|
} from "@/contexts/common/infrastructure";
|
||||||
import { DealerStatus } from "@/contexts/sales/domain";
|
import { DealerStatus } from "@/contexts/sales/domain";
|
||||||
import { Dealer_Model } from "@/contexts/sales/infrastructure/sequelize";
|
import { Dealer_Model, DealerCreationAttributes } from "@/contexts/sales/infrastructure/sequelize";
|
||||||
import { CurrencyData, Language, Name, Note, UniqueID } from "@shared/contexts";
|
import { CurrencyData, Language, Name, TextValueObject, UniqueID } from "@shared/contexts";
|
||||||
import { IProfileProps, Profile } from "../../domain";
|
import { IProfileProps, Profile } from "../../domain";
|
||||||
import { IProfileContext } from "../Profile.context";
|
import { IProfileContext } from "../Profile.context";
|
||||||
import { ProfileCreationAttributes, Profile_Model } from "../sequelize";
|
|
||||||
|
|
||||||
export interface IProfileMapper
|
export interface IProfileMapper
|
||||||
extends ISequelizeMapper<Profile_Model, ProfileCreationAttributes, Profile> {}
|
extends ISequelizeMapper<Dealer_Model, Partial<DealerCreationAttributes>, Profile> {}
|
||||||
|
|
||||||
class ProfileMapper
|
class ProfileMapper
|
||||||
extends SequelizeMapper<Profile_Model, ProfileCreationAttributes, Profile>
|
extends SequelizeMapper<Dealer_Model, Partial<DealerCreationAttributes>, Profile>
|
||||||
implements IProfileMapper
|
implements IProfileMapper
|
||||||
{
|
{
|
||||||
public constructor(props: { context: IProfileContext }) {
|
public constructor(props: { context: IProfileContext }) {
|
||||||
@ -27,11 +26,23 @@ class ProfileMapper
|
|||||||
const language = this.mapsValue(source, "lang_code", Language.createFromCode);
|
const language = this.mapsValue(source, "lang_code", Language.createFromCode);
|
||||||
const currency = this.mapsValue(source, "currency_code", CurrencyData.createFromCode);
|
const currency = this.mapsValue(source, "currency_code", CurrencyData.createFromCode);
|
||||||
|
|
||||||
const contactInformation = this.mapsValue(source, "contact_information", Note.create);
|
const contactInformation = this.mapsValue(
|
||||||
const defaultPaymentMethod = this.mapsValue(source, "default_payment_method", Note.create);
|
source,
|
||||||
const defaultNotes = this.mapsValue(source, "default_notes", Note.create);
|
"contact_information",
|
||||||
const defaultLegalTerms = this.mapsValue(source, "default_legal_terms", Note.create);
|
TextValueObject.create
|
||||||
const defaultQuoteValidity = this.mapsValue(source, "default_quote_validity", Note.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 = {
|
const props: IProfileProps = {
|
||||||
name,
|
name,
|
||||||
@ -60,11 +71,11 @@ class ProfileMapper
|
|||||||
return {
|
return {
|
||||||
id: source.id.toPrimitive(),
|
id: source.id.toPrimitive(),
|
||||||
|
|
||||||
contact_information: source.contactInformation,
|
contact_information: source.contactInformation.toPrimitive(),
|
||||||
default_payment_method: source.defaultPaymentMethod,
|
default_payment_method: source.defaultPaymentMethod.toPrimitive(),
|
||||||
default_notes: source.defaultNotes,
|
default_notes: source.defaultNotes.toPrimitive(),
|
||||||
default_legal_terms: source.defaultLegalTerms,
|
default_legal_terms: source.defaultLegalTerms.toPrimitive(),
|
||||||
default_quote_validity: source.defaultQuoteValidity,
|
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) {
|
} catch (error: unknown) {
|
||||||
const _error = error as IInfrastructureError;
|
const _error = error as IInfrastructureError;
|
||||||
return Result.fail(
|
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) {
|
} catch (error: unknown) {
|
||||||
const _error = error as IInfrastructureError;
|
const _error = error as IInfrastructureError;
|
||||||
return Result.fail(
|
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,
|
Percentage,
|
||||||
Quantity,
|
Quantity,
|
||||||
Result,
|
Result,
|
||||||
|
TextValueObject,
|
||||||
UTCDateValue,
|
UTCDateValue,
|
||||||
UniqueID,
|
UniqueID,
|
||||||
UnitPrice,
|
UnitPrice,
|
||||||
@ -168,7 +169,7 @@ export class CreateQuoteUseCase
|
|||||||
return Result.fail(paymentOrError.error);
|
return Result.fail(paymentOrError.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const notesOrError = Note.create(quoteDTO.notes);
|
const notesOrError = TextValueObject.create(quoteDTO.notes);
|
||||||
if (notesOrError.isFailure) {
|
if (notesOrError.isFailure) {
|
||||||
return Result.fail(notesOrError.error);
|
return Result.fail(notesOrError.error);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,7 +66,11 @@ export class GetQuoteByUserUseCase
|
|||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const _error = error as IInfrastructureError;
|
const _error = error as IInfrastructureError;
|
||||||
return Result.fail(
|
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,
|
Percentage,
|
||||||
Quantity,
|
Quantity,
|
||||||
Result,
|
Result,
|
||||||
|
TextValueObject,
|
||||||
UTCDateValue,
|
UTCDateValue,
|
||||||
UniqueID,
|
UniqueID,
|
||||||
UnitPrice,
|
UnitPrice,
|
||||||
@ -167,7 +168,7 @@ export class UpdateQuoteUseCase
|
|||||||
return Result.fail(paymentOrError.error);
|
return Result.fail(paymentOrError.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const notesOrError = Note.create(quoteDTO.notes);
|
const notesOrError = TextValueObject.create(quoteDTO.notes);
|
||||||
if (notesOrError.isFailure) {
|
if (notesOrError.isFailure) {
|
||||||
return Result.fail(notesOrError.error);
|
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 { ISequelizeMapper, SequelizeMapper } from "@/contexts/common/infrastructure";
|
||||||
import { IQuoteProps, Quote, QuoteCustomer, QuoteReference } from "../../domain";
|
import { IQuoteProps, Quote, QuoteCustomer, QuoteReference } from "../../domain";
|
||||||
@ -41,7 +49,7 @@ class QuoteMapper
|
|||||||
|
|
||||||
validity: this.mapsValue(source, "validity", Note.create),
|
validity: this.mapsValue(source, "validity", Note.create),
|
||||||
paymentMethod: this.mapsValue(source, "payment_method", 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,
|
items,
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user