2026-09-10 22:24:16 +03:30
|
|
|
import {
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
Param,
|
|
|
|
|
Patch,
|
|
|
|
|
Post,
|
|
|
|
|
Query,
|
|
|
|
|
UseGuards,
|
|
|
|
|
} from '@nestjs/common';
|
|
|
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
2026-10-21 13:45:16 +03:30
|
|
|
import { RequirePermission, SectionPermissionGuard } from '../auth/section-permission.guard';
|
2026-09-10 22:24:16 +03:30
|
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
|
|
|
|
import { Roles } from '../auth/roles.decorator';
|
|
|
|
|
import { RolesGuard } from '../auth/roles.guard';
|
|
|
|
|
import { CreateStockMovementDto, UpdatePartyOpeningDto } from './dto';
|
|
|
|
|
import { InventoryService } from './inventory.service';
|
|
|
|
|
|
|
|
|
|
type AuthUser = { organizationId: string };
|
|
|
|
|
|
|
|
|
|
@Controller('inventory')
|
2026-10-21 13:45:16 +03:30
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard, SectionPermissionGuard)
|
|
|
|
|
@RequirePermission('products')
|
2026-09-10 22:24:16 +03:30
|
|
|
export class InventoryController {
|
|
|
|
|
constructor(private readonly inventory: InventoryService) {}
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
summary(@CurrentUser() user: AuthUser) {
|
|
|
|
|
return this.inventory.getSummary(user.organizationId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('movements')
|
|
|
|
|
movements(
|
|
|
|
|
@CurrentUser() user: AuthUser,
|
|
|
|
|
@Query('productId') productId?: string,
|
|
|
|
|
) {
|
|
|
|
|
return this.inventory.listMovements(user.organizationId, productId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('movements')
|
|
|
|
|
@Roles('owner', 'admin')
|
|
|
|
|
addMovement(
|
|
|
|
|
@CurrentUser() user: AuthUser,
|
|
|
|
|
@Body() dto: CreateStockMovementDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.inventory.addManualMovement(user.organizationId, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('party/:personId')
|
|
|
|
|
partyBalance(
|
|
|
|
|
@CurrentUser() user: AuthUser,
|
|
|
|
|
@Param('personId') personId: string,
|
|
|
|
|
) {
|
|
|
|
|
return this.inventory.getPartyBalance(user.organizationId, personId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Patch('party/:personId/opening')
|
|
|
|
|
@Roles('owner', 'admin')
|
|
|
|
|
setOpening(
|
|
|
|
|
@CurrentUser() user: AuthUser,
|
|
|
|
|
@Param('personId') personId: string,
|
|
|
|
|
@Body() dto: UpdatePartyOpeningDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.inventory.setPartyOpening(
|
|
|
|
|
user.organizationId,
|
|
|
|
|
personId,
|
|
|
|
|
dto.amount,
|
|
|
|
|
dto.note,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|