73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Post,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { SchemaPipe } from '../common/validation.pipe';
|
|
import {
|
|
CurrentPrincipal,
|
|
RequirePermission,
|
|
} from '../identity/access.decorator';
|
|
import type { Principal } from '../identity/identity.types';
|
|
import { PartnerOrderCancelStore } from './partner-order-cancel.store';
|
|
import { PartnerOrderStore } from './partner-order.store';
|
|
import {
|
|
cancelPartnerOrderSchema,
|
|
createPartnerOrderSchema,
|
|
partnerOrderQuerySchema,
|
|
type CancelPartnerOrderInput,
|
|
type CreatePartnerOrderInput,
|
|
type PartnerOrderQuery,
|
|
} from './partner-order.schemas';
|
|
|
|
@Controller('b2b/partner-orders')
|
|
export class PartnerOrdersController {
|
|
constructor(
|
|
private readonly orders: PartnerOrderStore,
|
|
private readonly cancellations: PartnerOrderCancelStore,
|
|
) {}
|
|
|
|
@Get()
|
|
@RequirePermission('b2b.order.read')
|
|
list(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Query(new SchemaPipe(partnerOrderQuerySchema)) query: PartnerOrderQuery,
|
|
) {
|
|
return this.orders.list(actor, query);
|
|
}
|
|
|
|
@Post()
|
|
@RequirePermission('b2b.order.manage')
|
|
create(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Body(new SchemaPipe(createPartnerOrderSchema))
|
|
input: CreatePartnerOrderInput,
|
|
) {
|
|
return this.orders.create(actor, input);
|
|
}
|
|
|
|
@Get(':id')
|
|
@RequirePermission('b2b.order.read')
|
|
get(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
) {
|
|
return this.orders.get(actor, id);
|
|
}
|
|
|
|
@Post(':id/cancel')
|
|
@RequirePermission('b2b.order.manage')
|
|
cancel(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body(new SchemaPipe(cancelPartnerOrderSchema))
|
|
input: CancelPartnerOrderInput,
|
|
) {
|
|
return this.cancellations.cancel(actor, id, input);
|
|
}
|
|
}
|