зеркало из https://github.com/mozilla/fxa.git
feat(payments-ui): add updateCart server action
Because: * We need a server action to be able to update the cart details This commit: * Adds a server action to be able to update the cart details Closes FXA-8900
This commit is contained in:
Родитель
a9d97ffa05
Коммит
e62224e759
|
@ -0,0 +1,18 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
'use server';
|
||||||
|
|
||||||
|
import { UpdateCart } from '@fxa/payments/cart';
|
||||||
|
import { app } from '../nestapp/app';
|
||||||
|
|
||||||
|
export const updateCartAction = async (
|
||||||
|
cartId: string,
|
||||||
|
version: number,
|
||||||
|
cartDetails: UpdateCart
|
||||||
|
) => {
|
||||||
|
const actionsService = await app.getActionsService();
|
||||||
|
|
||||||
|
await actionsService.updateCart(cartId, version, cartDetails);
|
||||||
|
};
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
import { CartService } from '@fxa/payments/cart';
|
import { CartService, UpdateCart } from '@fxa/payments/cart';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,8 +15,21 @@ export class NextJSActionsService {
|
||||||
constructor(private cartService: CartService) {}
|
constructor(private cartService: CartService) {}
|
||||||
|
|
||||||
async getCart(cartId: string) {
|
async getCart(cartId: string) {
|
||||||
|
// TODO: validate incoming arguments with class-validator
|
||||||
|
|
||||||
const cart = await this.cartService.getCart(cartId);
|
const cart = await this.cartService.getCart(cartId);
|
||||||
|
|
||||||
return cart;
|
return cart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateCart(cartId: string, version: number, cartDetails: UpdateCart) {
|
||||||
|
// TODO: validate incoming arguments with class-validator
|
||||||
|
|
||||||
|
await this.cartService.updateCart(cartId, version, {
|
||||||
|
uid: cartDetails.uid,
|
||||||
|
taxAddress: cartDetails.taxAddress,
|
||||||
|
couponCode: cartDetails.couponCode,
|
||||||
|
email: cartDetails.email,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче