-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfae634
commit 538e07f
Showing
7 changed files
with
178 additions
and
1 deletion.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
backend/src/infrastructure/data_access/repositories/models/order-status-model.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/infrastructure/data_access/repositories/order-status.repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
backend/src/infrastructure/data_access/repositories/schemas/order-status.schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |