/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/javascript/code-412-113-003/main.js
43 строки
2 KB
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
// modules/food-delivery/module.ts class FoodDeliveryModule implements MiniAppModule { private coreApi: CoreApiInterface; private cart: OrderItem[] = []; constructor(coreApi: CoreApiInterface) { this.coreApi = coreApi; } async initialize(context: ModuleContext): Promise<void> { // Загрузка данных пользователя из ядра const userProfile = await this.coreApi.getUserProfile(); this.userAddress = userProfile.defaultAddress; } async placeOrder(restaurantId: string, items: OrderItem[]): Promise<OrderResult> { // Валидация данных перед вызовом ядра if (!this.coreApi.hasPermission('place_orders')) { throw new PermissionDeniedError('Недостаточно прав для оформления заказа'); } // Формирование запроса с минимальным набором данных const orderRequest: MinimalOrderRequest = { restaurantId: restaurantId, items: items.map(item => ({ id: item.id, quantity: item.quantity, price: item.price })), deliveryAddress: this.userAddress, paymentMethodId: await this.coreApi.getDefaultPaymentMethod() }; // Передача управления ядру для обработки платежа return await this.coreApi.processOrder(orderRequest); } // Изолированное хранилище данных модуля private saveToModuleStorage(key: string, value: any): void { // Данные сохраняются только в контексте модуля localStorage.setItem(`food_delivery_${key}`, JSON.stringify(value)); } }