I'm trying to apply object orientation in a study project, but see my problems. I have an Order class when creating an order my request has the following parameters ts { "clientId": "1234", "table": "30", "products": [ { "product": "a7f68a1c-acdb-4b4f-8037-3258b5050a14", "quantity": 1 } ] } When trying to use my domain class to create ```ts
@Injectable()
export class CreateOrderUseCase {
constructor(private readonly orderRepository: OrderRepository) {}
async execute(
clientId: string,
orderDetailsInput: OrderDetailsInput,
): Promise<Order> {
const { table, products } = orderDetailsInput;
const order = Order.create({ clientId, table, products });
await this.orderRepository.save(order);
return order;
}
}
Order classts
type ProductInput = {
productId: string;
quantity: number;
};
type Input = {
clientId: string;
table: string;
products: ProductInput[];
};
export class Order extends BaseEntity {
updatedAt?: Date;
finishedAt?: Date;
constructor(
readonly clientId: string,
private table: string,
private status: OrderStatus,
private input: ProductInput[],
) {
super();
this.clientId = clientId;
this.table = table;
}
static create({ clientId, table, products }: Input) {
const status = OrderStatus.WAITING;
return new Order(clientId, table, status, products);
}
Then persist the data in the database and this flow worksts
async save(order: Order): Promise<void> {
try {
console.log('ORDER', order);
const newOrder = await this.orderModel.create(order);
await newOrder.save({ validateBeforeSave: false });
} catch (error) {
this.logger.error(error.message);
throw new InternalServerErrorException();
}
}