Reputation: 1739
Let's say we have multiple stations and each station has many station machines and station machine can't exist without the station id. Each machine can have various sockets and each machine is of a particular brand. The application needs to create a station and all its dependent machines.
It means we need to create the station first, and then pass the machines, however station depends on the machine.
Domain Entities Props:
IStationProps {
name: string;
machines: Machine[];
location: string
}
IMachineProps {
name: string;
sockets: Socket[],
}
ISocket {
name: string;
}
IBrand {
name: string
}
If a request contains the socket list which can either be already in system and some which are created at time of station creation.
How to validate the socket if they already exist in the system and if the given id is not valid we need to make it as new entry.
Example
"socket": [
{
"socket_id": "some_id",
"name" : "Alpha"
},
{
"name": "delta"
},
{
"socket_id": "some_id_which_is_not_in_db"
name: "gamma"
}
]
Here, after validating all the sockets, second and third socket id need to be also created in the system and also added to the station machine. Similarly with brand.
Also in below code the machines list also need station id to be validated as machine for creation and station need machines as list for creation, how to handle this dependent situation?
const machines = Machines.create(machines_array)
const station = Station.create({
name,
machines
});
Upvotes: 1
Views: 139