Files
minishop/src/app/services/order.service.ts

32 lines
742 B
TypeScript

import { Injectable } from '@angular/core';
import { IOrder } from '../models/order.interface';
@Injectable({
providedIn: 'root',
})
export class OrderService {
private currentOrder: IOrder = {};
public getOrder(): IOrder {
return this.currentOrder;
}
public updateOrder(partialOrder: Partial<IOrder>): void {
this.currentOrder = { ...this.currentOrder, ...partialOrder };
}
public placeOrder(): IOrder {
// Logic to send order
const finalOrder = this.getOrder();
const shippingID = "SC-" + Math.floor(Math.random() * 1000000).toString().padStart(6, '0');
this.updateOrder({ shippingNumber: shippingID });
console.log('Order placed:', this.getOrder());
return this.getOrder();
}
}