# Exposing get fields

In the <mark style="color:purple;">order-item.entity</mark> file, we still need to add the <mark style="color:blue;">`get`</mark> field that calculates the <mark style="color:blue;">`subTotal`</mark> of an item.

```typescript
get subTotal() {
  return this.quantity * this.price;
}
```

And in <mark style="color:purple;">order.entity</mark>, calculate the <mark style="color:blue;">`total`</mark> by adding the **subTotals** of its <mark style="color:blue;">`items`</mark>.

```typescript
get total() {
  return this.items?.reduce((total, item) => total + item.subTotal, 0);
}
```

> Due to the **optional chaining operator** (<mark style="color:blue;">`?`</mark>), this calculation only occurs if the <mark style="color:blue;">`items`</mark> field is present. This is a good safety measure as <mark style="color:blue;">`items`</mark> is a **relation** and may <mark style="color:red;">not</mark> be present.

It would be even better if these <mark style="color:blue;">`get`</mark> fields were automatically included in their respective entities when they are fetched, like if they were attributes. To achieve this, we first need to enable the <mark style="color:blue;">`ClassSerializerInterceptor`</mark> globally. We can do this in the <mark style="color:blue;">`providers`</mark> array of the <mark style="color:blue;">`CommonModule`</mark>.

```typescript
{
  provide: APP_INTERCEPTOR,
  useClass: ClassSerializerInterceptor,
},
```

After that, we just need to add on top of both these fields the <mark style="color:blue;">`@Expose()`</mark> decorator, and we're done.

<mark style="color:green;">**Commit**</mark> - Using serialization to return get fields
