• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

How to implement this simple agregate (nodejs, TS, mongoose)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
im creating an api for school project using node, typescript and moongose and i have a question about this:.

I have an agregate that have, as agregate root, the Entity "Path".

This path have some simple fields like name or whatever and an array ( or list) of "PathNodes"

PathNodes is an Entity inside this agregate but dont have an id ( teacher said that, whatever it means)

Path nodes have 2 Nodes, one inicial node and one final node -Node is the Entity of another agregate and is already implemented.

My question is how should i implement both the domain class of Path and PathNode and also how to implement the Schema for this ( i know i could use the schema as "domain" classes but teacher dont want that).

What im thinking is somehting like this

                               ---PathNode.ts ---
 import Node from '...'

Class PathNode
private Inicialnode : Node
private FinalNode : Node  
constructor(nodei:Node, nodef:Node   ){
this.Inicialnode =nodei; this.FinalNode  =nodef;
}    

                               ---PathNodeSchema.js ---

....new Shcema{  
nodei: { type: Schema.Types.ObjectId, ref: 'Node' },
nodef: { type: Schema.Types.ObjectId, ref: 'Node' },} }    


                                   ---Path.ts ---  

import PathNode from '...'

Class Path  

private name: String
private PathNode: PathNode[];

  constructor(obj :PathDTO   ){
this.name = obj.name;
for(pathNodes of obj.pathnodes){
this.pathNodesTemp = new PathNode(pathNodes );
PathNode.push(this.pathNodesTemp);
}  

                            ---PathSchema.js ---  

....new Shcema{  name: String ,
PathNode:[ { type: Schema.Types.ObjectId, ref: 'PathNodes' }],  }


------
What do you think of this? im also confused becouse i have a repository for path, but not for pathnodes as path is the agregate root. Inside the repository if i do PathSchema.create(path) will it create the path document along with the pathnodes? Or do i need to PathNodeSchema.create(pathNode) first?

as Path have a list of PathNodes, maybe PathNode should reference the Path it belongs to instead of Path referencing many PathNodes? If yes how should i implement it?



Thank you
 
My, my, aren't you a big fella. Here, have a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic