Skip to content

Commit

Permalink
include menuId in ordernote domain
Browse files Browse the repository at this point in the history
  • Loading branch information
olasunkanmi-SE committed Nov 19, 2023
1 parent fe23a3f commit f146115
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { Types } from 'mongoose';

export interface IOrderNoteModel {
orderId: Types.ObjectId;
menuId: Types.ObjectId;
note: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IOrderNoteModel } from '../models/order-note-model.interface';
import mongoose, { Document, Types } from 'mongoose';
import { Type } from 'class-transformer';
import { OrderDataModel } from './order.schema';
import { MenuDataModel } from './menu.schema';

export type OrderNoteDocument = OrderNoteModel & Document;
export class OrderNoteModel extends BaseDocument implements IOrderNoteModel {
Expand All @@ -13,6 +14,10 @@ export class OrderNoteModel extends BaseDocument implements IOrderNoteModel {
@Prop({ type: mongoose.Schema.Types.ObjectId })
@Type(() => OrderDataModel)
orderId: Types.ObjectId;

@Prop({ type: mongoose.Schema.Types.ObjectId })
@Type(() => MenuDataModel)
menuId: Types.ObjectId;
}

export const OrderNoteSchema = SchemaFactory.createForClass(OrderNoteModel);
5 changes: 5 additions & 0 deletions backend/src/order_notes/dto/create-order_note.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ export class CreateOrderNoteDTO {
@IsNotEmpty()
@Length(2, 128)
readonly orderId: Types.ObjectId;

@IsString()
@IsNotEmpty()
@Length(2, 128)
readonly menuId: Types.ObjectId;
}
1 change: 1 addition & 0 deletions backend/src/order_notes/interface/order-note.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Audit } from 'src/domain';

export interface IOrderNote {
orderId: Types.ObjectId;
menuId: Types.ObjectId;
note: string;
audit: Audit;
}
6 changes: 4 additions & 2 deletions backend/src/order_notes/order_note.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { OrderNote } from './order_note';
export class OrderNoteMapper implements IMapper<OrderNote, OrderNoteModel> {
constructor(private readonly auditMapper: AuditMapper) {}
toPersistence(entity: OrderNote): OrderNoteModel {
const { id, orderId, note, audit } = entity;
const { id, orderId, note, menuId, audit } = entity;
const {
auditCreatedBy,
auditCreatedDateTime,
Expand All @@ -20,6 +20,7 @@ export class OrderNoteMapper implements IMapper<OrderNote, OrderNoteModel> {
const orderNoteDocument: OrderNoteModel = {
_id: id,
orderId,
menuId,
note,
auditCreatedBy,
auditCreatedDateTime,
Expand All @@ -32,11 +33,12 @@ export class OrderNoteMapper implements IMapper<OrderNote, OrderNoteModel> {
}

toDomain(model: OrderNoteModel): OrderNote {
const { _id, orderId, note } = model;
const { _id, orderId, note, menuId } = model;
const entity: OrderNote = OrderNote.create(
{
orderId,
note,
menuId,
audit: this.auditMapper.toDomain(model),
},
_id,
Expand Down
10 changes: 10 additions & 0 deletions backend/src/order_notes/order_note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class OrderNote extends Entity<IOrderNote> {
private _orderId: Types.ObjectId;
private _note: string;
private _audit: Audit;
private _menuId: Types.ObjectId;

/**
* Creates an instance of OrderNotes.
Expand All @@ -24,16 +25,25 @@ export class OrderNote extends Entity<IOrderNote> {
this._orderId = props.orderId;
this._note = props.note;
this._audit = props.audit;
this._menuId = props.menuId;
}

get note(): string {
return this._note;
}

set note(note: string) {
this._note = note;
}

get orderId(): Types.ObjectId {
return this._orderId;
}

get menuId(): Types.ObjectId {
return this._menuId;
}

get audit() {
return this._audit;
}
Expand Down

0 comments on commit f146115

Please sign in to comment.