Skip to content

Commit

Permalink
Development (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
olasunkanmi-SE authored Nov 13, 2023
1 parent bfae634 commit 538e07f
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface IOrderStatusModel {
readonly isActive: boolean;
readonly name: string;
readonly code: string;
readonly description?: string;
}
Original file line number Diff line number Diff line change
@@ -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<OrderStatus, OrderStatusDocument> {
orderStatusMapper: orderStatusMapper;
constructor(
@InjectModel(OrderStatusModel.name) orderStatusDataModel: Model<OrderStatusDocument>,
@InjectConnection() readonly connection: Connection,
orderStatusMapper: orderStatusMapper,
) {
super(orderStatusDataModel, connection, orderStatusMapper);
this.orderStatusMapper = orderStatusMapper;
}
}
Original file line number Diff line number Diff line change
@@ -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[];
}
12 changes: 11 additions & 1 deletion backend/src/order_statuses/order_status.entity.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -7,12 +7,14 @@ export class OrderStatus extends Entity<IOrderStatuses> 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 {
Expand Down Expand Up @@ -47,6 +49,14 @@ export class OrderStatus extends Entity<IOrderStatuses> 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();
}
Expand Down
50 changes: 50 additions & 0 deletions backend/src/order_statuses/order_status.mapper.ts
Original file line number Diff line number Diff line change
@@ -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<OrderStatus, OrderStatusModel> {
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;
}
}
63 changes: 63 additions & 0 deletions backend/src/order_statuses/order_status.ts
Original file line number Diff line number Diff line change
@@ -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<IOrderStatuses> 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();
}
}
2 changes: 2 additions & 0 deletions backend/src/order_statuses/order_status_entity.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Audit } from 'src/domain';
export interface IOrderStatuses {
isActive: boolean;
name: string;
code: string;
description?: string;
audit: Audit;
}

0 comments on commit 538e07f

Please sign in to comment.