如何实施域实体及其业务逻辑以获取依赖数据

发布于 2025-01-17 12:02:08 字数 1048 浏览 5 评论 0原文

假设我们有多个车站,每个车站有许多车站机器,没有车站 ID 就不可能存在车站机器。 每台机器可以有不同的插座,并且每台机器都有特定的品牌。 应用程序需要创建一个站及其所有相关机器。

这意味着我们需要先创建站点,然后通过机器,但是站点取决于机器。

域实体属性:

IStationProps {
  name: string;
  machines: Machine[];
  location: string
}

IMachineProps {
   name: string;
   sockets: Socket[],
   
}

ISocket {
   name: string;
}

IBrand {
  name: string
}

如果请求包含套接字列表,该列表可以是系统中已有的,也可以是在创建站时创建的。

如何验证套接字是否已存在于系统中,并且如果给定的 id 无效,我们需要将其设置为新条目。

示例

"socket": [
        {
          "socket_id": "some_id",
          "name" : "Alpha" 
        },
        {
         "name": "delta"
        },
        {
         "socket_id": "some_id_which_is_not_in_db"
         name: "gamma"
        }
      ]

此处,验证所有套接字后,还需要在系统中创建第二个和第三个套接字 ID,并将其添加到工作站机器中。品牌也同样如此。

另外,在下面的代码中,机器列表还需要验证工作站 ID 作为创建机器,并且工作站需要机器作为创建列表,如何处理这种依赖情况?

const machines = Machines.create(machines_array) 

const station = Station.create({
        name,
        machines 
      });

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 
      });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文