40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Put,
|
|
} from '@nestjs/common';
|
|
import { CurrentPrincipal } from '../identity/access.decorator';
|
|
import type { Principal } from '../identity/identity.types';
|
|
import { SchemaPipe } from '../common/validation.pipe';
|
|
import { cartLineSchema, cartVersionSchema } from './checkout.schemas';
|
|
import { CartStore } from './cart.store';
|
|
@Controller('cart')
|
|
export class CartController {
|
|
constructor(private readonly carts: CartStore) {}
|
|
@Get()
|
|
get(@CurrentPrincipal() actor: Principal) {
|
|
return this.carts.get(actor);
|
|
}
|
|
@Put('lines/:variantId')
|
|
set(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('variantId', ParseUUIDPipe) id: string,
|
|
@Body(new SchemaPipe(cartLineSchema))
|
|
input: { quantity: number; version: number },
|
|
) {
|
|
return this.carts.set(actor, id, input.version, input.quantity);
|
|
}
|
|
@Delete('lines/:variantId')
|
|
remove(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('variantId', ParseUUIDPipe) id: string,
|
|
@Body(new SchemaPipe(cartVersionSchema)) input: { version: number },
|
|
) {
|
|
return this.carts.set(actor, id, input.version, 0);
|
|
}
|
|
}
|