53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Post,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { CurrentPrincipal } from '../identity/access.decorator';
|
|
import type { Principal } from '../identity/identity.types';
|
|
import { SchemaPipe } from '../common/validation.pipe';
|
|
import { pageSchema, type PageInput } from '../identity/identity.schemas';
|
|
import { checkoutSchema, type CheckoutInput } from './checkout.schemas';
|
|
import { CheckoutStore } from './checkout.store';
|
|
import { OrderStore } from './order.store';
|
|
|
|
@Controller()
|
|
export class OrdersController {
|
|
constructor(
|
|
private readonly checkout: CheckoutStore,
|
|
private readonly orders: OrderStore,
|
|
) {}
|
|
@Post('checkout')
|
|
create(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Body(new SchemaPipe(checkoutSchema)) input: CheckoutInput,
|
|
) {
|
|
return this.checkout.create(actor, input);
|
|
}
|
|
@Get('orders')
|
|
list(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Query(new SchemaPipe(pageSchema)) page: PageInput,
|
|
) {
|
|
return this.orders.list(actor, page);
|
|
}
|
|
@Get('orders/:id')
|
|
get(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
) {
|
|
return this.orders.get(actor, id);
|
|
}
|
|
@Post('orders/:id/cancel')
|
|
cancel(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
) {
|
|
return this.orders.cancel(actor, id);
|
|
}
|
|
}
|