diff --git a/backend/src/infrastructure/data_access/repositories/models/order-status-model.interface.ts b/backend/src/infrastructure/data_access/repositories/models/order-status-model.interface.ts new file mode 100644 index 00000000..716831fe --- /dev/null +++ b/backend/src/infrastructure/data_access/repositories/models/order-status-model.interface.ts @@ -0,0 +1,6 @@ +export interface IOrderStatusModel { + readonly isActive: boolean; + readonly name: string; + readonly code: string; + readonly description?: string; +} diff --git a/backend/src/infrastructure/data_access/repositories/order-status.repository.ts b/backend/src/infrastructure/data_access/repositories/order-status.repository.ts new file mode 100644 index 00000000..859bb03f --- /dev/null +++ b/backend/src/infrastructure/data_access/repositories/order-status.repository.ts @@ -0,0 +1,20 @@ +import { Injectable } from '@nestjs/common'; +import { OrderStatusDocument, OrderStatusModel } from './schemas/order-status.schema'; +import { OrderStatus } from 'src/order_statuses/order_status'; +import { GenericDocumentRepository } from 'src/infrastructure/database'; +import { InjectConnection, InjectModel } from '@nestjs/mongoose'; +import { Connection, Model } from 'mongoose'; +import { orderStatusMapper } from 'src/order_statuses/order_status.mapper'; + +@Injectable() +export class OrderStatusRepository extends GenericDocumentRepository { + orderStatusMapper: orderStatusMapper; + constructor( + @InjectModel(OrderStatusModel.name) orderStatusDataModel: Model, + @InjectConnection() readonly connection: Connection, + orderStatusMapper: orderStatusMapper, + ) { + super(orderStatusDataModel, connection, orderStatusMapper); + this.orderStatusMapper = orderStatusMapper; + } +} diff --git a/backend/src/infrastructure/data_access/repositories/schemas/order-status.schema.ts b/backend/src/infrastructure/data_access/repositories/schemas/order-status.schema.ts new file mode 100644 index 00000000..fad40512 --- /dev/null +++ b/backend/src/infrastructure/data_access/repositories/schemas/order-status.schema.ts @@ -0,0 +1,26 @@ +import { BaseDocument } from 'src/infrastructure/database'; +import { IOrderStatusModel } from '../models/order-status-model.interface'; +import { Prop } from '@nestjs/mongoose'; +import mongoose from 'mongoose'; +import { OrderDataModel } from './order.schema'; +import { Type } from 'class-transformer'; +import { Document } from 'mongoose'; + +export type OrderStatusDocument = OrderStatusModel & Document; +export class OrderStatusModel extends BaseDocument implements IOrderStatusModel { + @Prop({ type: Boolean, required: true, default: true }) + isActive: boolean; + + @Prop({ type: String, required: true }) + code: string; + + @Prop({ type: String, required: true }) + name: string; + + @Prop({ type: String, required: true }) + description: string; + + @Prop({ type: [{ type: mongoose.Schema.Types.ObjectId, ref: OrderDataModel }] }) + @Type(() => OrderDataModel) + orders?: OrderDataModel[]; +} diff --git a/backend/src/order_statuses/order_status.entity.ts b/backend/src/order_statuses/order_status.entity.ts index 5a269767..b7b8501d 100644 --- a/backend/src/order_statuses/order_status.entity.ts +++ b/backend/src/order_statuses/order_status.entity.ts @@ -1,4 +1,4 @@ -import { Entity, Result } from 'src/domain'; +import { Audit, Entity, Result } from 'src/domain'; import { IOrderStatuses } from './order_status_entity.interface'; import { Types } from 'mongoose'; @@ -7,12 +7,14 @@ export class OrderStatus extends Entity implements IOrderStatuse _name: string; _code: string; _description?: string; + _audit: Audit; constructor(id: Types.ObjectId, props: IOrderStatuses) { super(id); this._isActive = props.isActive; this._name = props.name; this._code = props.code; this._description = props.description; + this._audit = props.audit; } get isActive(): boolean { @@ -47,6 +49,14 @@ export class OrderStatus extends Entity implements IOrderStatuse this._description = description; } + get audit(): Audit { + return this._audit; + } + + set audit(audit: Audit) { + this._audit = audit; + } + static create(props: IOrderStatuses, id?: Types.ObjectId) { return Result.ok(new OrderStatus(id, props)).getValue(); } diff --git a/backend/src/order_statuses/order_status.mapper.ts b/backend/src/order_statuses/order_status.mapper.ts new file mode 100644 index 00000000..661f6639 --- /dev/null +++ b/backend/src/order_statuses/order_status.mapper.ts @@ -0,0 +1,50 @@ +import { Injectable } from '@nestjs/common'; +import { IMapper } from 'src/domain'; +import { OrderStatus } from './order_status'; +import { OrderStatusModel } from 'src/infrastructure/data_access/repositories/schemas/order-status.schema'; +import { AuditMapper } from 'src/audit'; + +@Injectable() +export class orderStatusMapper implements IMapper { + constructor(private readonly auditMapper: AuditMapper) {} + toPersistence(entity: OrderStatus): OrderStatusModel { + const { id, isActive, name, code, description, audit } = entity; + const { + auditCreatedBy, + auditCreatedDateTime, + auditModifiedBy, + auditModifiedDateTime, + auditDeletedBy, + auditDeletedDateTime, + } = audit; + const orderStatusDocument: OrderStatusModel = { + _id: id, + name, + isActive, + code, + description, + auditCreatedBy, + auditCreatedDateTime, + auditModifiedBy, + auditModifiedDateTime, + auditDeletedDateTime, + auditDeletedBy, + }; + return orderStatusDocument; + } + + toDomain(model: OrderStatusModel): OrderStatus { + const { _id, isActive, name, code, description } = model; + const entity: OrderStatus = OrderStatus.create( + { + name, + code, + description, + isActive, + audit: this.auditMapper.toDomain(model), + }, + _id, + ); + return entity; + } +} diff --git a/backend/src/order_statuses/order_status.ts b/backend/src/order_statuses/order_status.ts new file mode 100644 index 00000000..b7b8501d --- /dev/null +++ b/backend/src/order_statuses/order_status.ts @@ -0,0 +1,63 @@ +import { Audit, Entity, Result } from 'src/domain'; +import { IOrderStatuses } from './order_status_entity.interface'; +import { Types } from 'mongoose'; + +export class OrderStatus extends Entity implements IOrderStatuses { + _isActive: boolean; + _name: string; + _code: string; + _description?: string; + _audit: Audit; + constructor(id: Types.ObjectId, props: IOrderStatuses) { + super(id); + this._isActive = props.isActive; + this._name = props.name; + this._code = props.code; + this._description = props.description; + this._audit = props.audit; + } + + get isActive(): boolean { + return this._isActive; + } + + set isActive(isActive: boolean) { + this._isActive = isActive; + } + + get name(): string { + return this._name; + } + + set name(name: string) { + this._name = name; + } + + get code(): string { + return this._code; + } + + set code(code: string) { + this._code = code; + } + + get description(): string { + return this._description; + } + + set description(description: string) { + this._description = description; + } + + get audit(): Audit { + return this._audit; + } + + set audit(audit: Audit) { + this._audit = audit; + } + + static create(props: IOrderStatuses, id?: Types.ObjectId) { + return Result.ok(new OrderStatus(id, props)).getValue(); + } +} diff --git a/backend/src/order_statuses/order_status_entity.interface.ts b/backend/src/order_statuses/order_status_entity.interface.ts index 76b545ab..7da39ad5 100644 --- a/backend/src/order_statuses/order_status_entity.interface.ts +++ b/backend/src/order_statuses/order_status_entity.interface.ts @@ -1,6 +1,8 @@ +import { Audit } from 'src/domain'; export interface IOrderStatuses { isActive: boolean; name: string; code: string; description?: string; + audit: Audit; }