Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add return type for CancelMerchOrder #404

Merged
merged 7 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions api/controllers/MerchStoreController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
CompleteOrderPickupEventResponse,
GetOrderPickupEventResponse,
CancelOrderPickupEventResponse,
CancelMerchOrderResponse,
} from '../../types';
import { UuidParam } from '../validators/GenericRequests';
import { AuthenticatedUser } from '../decorators/AuthenticatedUser';
Expand Down Expand Up @@ -309,10 +310,11 @@ export class MerchStoreController {
}

@Post('/order/:uuid/cancel')
async cancelMerchOrder(@Params() params: UuidParam, @AuthenticatedUser() user: UserModel) {
async cancelMerchOrder(@Params() params: UuidParam,
@AuthenticatedUser() user: UserModel): Promise<CancelMerchOrderResponse> {
if (!PermissionsService.canAccessMerchStore(user)) throw new ForbiddenError();
const order = await this.merchStoreService.cancelMerchOrder(params.uuid, user);
return { error: null, order };
return { error: null, order: order.getPublicOrderWithItems() };
}

@Post('/order/:uuid/fulfill')
Expand Down
3 changes: 2 additions & 1 deletion services/MerchStoreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ export default class MerchStoreService {
/**
* Cancels a merch order, refunding the user of its credits if the user is the one who cancelled the order.
*/
public async cancelMerchOrder(orderUuid: Uuid, user: UserModel): Promise<void> {
public async cancelMerchOrder(orderUuid: Uuid, user: UserModel): Promise<OrderModel> {
return this.transactions.readWrite(async (txn) => {
const orderRespository = Repositories.merchOrder(txn);
const order = await orderRespository.findByUuid(orderUuid);
Expand All @@ -785,6 +785,7 @@ export default class MerchStoreService {
type: ActivityType.ORDER_CANCELLED,
description: `Order ${order.uuid} cancelled and refunded to ${customer.uuid} by ${user.uuid}`,
});
return order;
});
}

Expand Down
9 changes: 6 additions & 3 deletions tests/merchOrder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ describe('merch orders', () => {

// cancel order
const { uuid } = placedOrderResponse.order;
await merchController.cancelMerchOrder({ uuid }, member);
const cancelOrderResponse = await merchController.cancelMerchOrder({ uuid }, member);
expect(cancelOrderResponse.order.uuid).toEqual(uuid);

// get order, making sure state was updated and user has been refunded
const cancelledOrderResponse = await merchController.getOneMerchOrder({ uuid }, member);
Expand Down Expand Up @@ -518,7 +519,8 @@ describe('merch orders', () => {

// cancel the order
const { uuid } = placedOrderResponse.order;
await merchController.cancelMerchOrder({ uuid }, member);
const cancelOrderResponse = await merchController.cancelMerchOrder({ uuid }, member);
expect(cancelOrderResponse.order.uuid).toEqual(uuid);

// make sure user has only been refunded 1 option worth of points
await member.reload();
Expand Down Expand Up @@ -890,7 +892,8 @@ describe('merch orders', () => {
const merchController = ControllerFactory.merchStore(conn, instance(emailService));
const placedOrder = await conn.manager.findOne(OrderModel, { user: member }, { relations: ['items'] });
const cancelOrderParams = { uuid: placedOrder.uuid };
await merchController.cancelMerchOrder(cancelOrderParams, member);
const cancelOrderResponse = await merchController.cancelMerchOrder(cancelOrderParams, member);
expect(cancelOrderResponse.order.uuid).toEqual(cancelOrderParams.uuid);

// place order with 2 items again
const secondOrder = [{ option: option.uuid, quantity: 2 }];
Expand Down
4 changes: 4 additions & 0 deletions types/ApiResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ export interface VerifyMerchOrderResponse extends ApiResponse {}

export interface EditMerchOrderResponse extends ApiResponse {}

export interface CancelMerchOrderResponse extends ApiResponse {
order: PublicOrderWithItems;
}

export interface GetCartResponse extends ApiResponse {
cart: PublicOrderMerchItemOption[];
}
Expand Down
Loading