0

我正在使用 Next.js 和amplify add api. 在schema.graphql中,有以下实体:

type Quotation @model {
    id: ID!
    name: String!
    jobs: [Job]
}

type Job @model {
    id: ID!
    name: String!
    cost: Float!
    revenue: Float!
}

有了这两个实体,我想实现两件事(模型情况,实际用例显然更复杂) - 计算工作利润(收入 - 成本)和计算报价利润(所有工作利润之和)。

在 NET Core 中,它就像定义以下 DTO 并在 automapper 中映射它们一样简单:

public class QuotationDto 
{
   public Guid Id { get; set; }
   public string Name { get; set; }
   public ICollection<JobDto> Jobs { get; set; }
   public double Profit => Jobs.Sum(e => e.Profit);
}

public class JobDto
{
   public Guid Id { get; set; }
   public string Name { get; set; }
   public double Cost { get; set; }
   public double Revenue { get; set; }
   public double Profit => Revenue - Cost;
}

在放大/应用同步工作流程中实现这一目标的正确方法是什么,最好不离开 VS Code?

4

0 回答 0