Presupuestador_web/server/src/contexts/sales/infrastructure/mappers/quoteChapter.mapper.ts

33 lines
1.4 KiB
TypeScript

import { ISequelizeMapper, SequelizeMapper } from "@/contexts/common/infrastructure";
import { Description, UniqueID } from "@shared/contexts";
import { QuoteChapter } from "../../domain";
import { QuoteChapterCreationAttributes, QuoteChapter_Model } from "../sequelize/quoteChapter.model";
export interface IQuoteChapterMapper extends ISequelizeMapper<
QuoteChapter_Model, QuoteChapterCreationAttributes, QuoteChapter
> {}
export const createQuoteChapterMapper = (): IQuoteChapterMapper => new QuoteChapterMapper({});
class QuoteChapterMapper extends SequelizeMapper<
QuoteChapter_Model, QuoteChapterCreationAttributes, QuoteChapter
> implements IQuoteChapterMapper {
protected toDomainMappingImpl(source: QuoteChapter_Model): QuoteChapter {
const result = QuoteChapter.create({
quoteId: this.mapsValue(source, "quote_id", UniqueID.create),
description: this.mapsValue(source, "description", Description.create),
}, this.mapsValue(source, "chapter_id", UniqueID.create));
if (result.isFailure) throw result.error;
return result.object;
}
protected toPersistenceMappingImpl(source: QuoteChapter, params: { index: number }): QuoteChapterCreationAttributes {
return {
quote_id: source.quoteId.toString(),
chapter_id: source.id.toString(),
description: source.description.toString(),
position: params.index,
};
}
}