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:
Julian Poyourow 2024-04-09 11:28:48 -07:00
Родитель a9d97ffa05
Коммит e62224e759
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: EA0570ABC73D47D3
2 изменённых файлов: 32 добавлений и 1 удалений

Просмотреть файл

@ -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
* 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';
/**
@ -15,8 +15,21 @@ export class NextJSActionsService {
constructor(private cartService: CartService) {}
async getCart(cartId: string) {
// TODO: validate incoming arguments with class-validator
const cart = await this.cartService.getCart(cartId);
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,
});
}
}