Add a small internal warehouse and party balances when Tahesab is off.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
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')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user