2026-11-17 21:24:15 +03:30
|
|
|
import { Body, Controller, Get, Post, Put, UseGuards } from '@nestjs/common';
|
|
|
|
|
import { Roles } from '../auth/roles.decorator';
|
|
|
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
|
|
|
import { RolesGuard } from '../auth/roles.guard';
|
|
|
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
|
|
|
|
import type { Actor } from '../common/record-scope';
|
|
|
|
|
import { RequireOrgModule } from '../billing/org-module.decorator';
|
|
|
|
|
import { OrgModuleGuard } from '../billing/org-module.guard';
|
|
|
|
|
import { AccountBalanceSettingsService } from './account-balance-settings.service';
|
|
|
|
|
import { BalanceClaimsService } from './balance-claims.service';
|
2026-11-18 13:22:38 +03:30
|
|
|
import { EvaluateAccountBalancesDto, UpdateAccountBalanceSettingsDto } from './dto';
|
2026-11-17 21:24:15 +03:30
|
|
|
|
|
|
|
|
@Controller('account-balances')
|
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard, OrgModuleGuard)
|
|
|
|
|
@RequireOrgModule('account_balances')
|
|
|
|
|
export class AccountBalancesController {
|
|
|
|
|
constructor(
|
|
|
|
|
private readonly settings: AccountBalanceSettingsService,
|
|
|
|
|
private readonly claims: BalanceClaimsService,
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
@Get('settings')
|
|
|
|
|
@Roles('owner', 'admin')
|
|
|
|
|
getSettings(@CurrentUser() user: Actor) {
|
|
|
|
|
return this.settings.get(user.organizationId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put('settings')
|
|
|
|
|
@Roles('owner', 'admin')
|
|
|
|
|
updateSettings(@CurrentUser() user: Actor, @Body() dto: UpdateAccountBalanceSettingsDto) {
|
|
|
|
|
return this.settings.update(user.organizationId, dto);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-18 13:22:38 +03:30
|
|
|
/** یک تکه از ارزیابی (حداکثر ۲۰۰۰ نفر)؛ کلاینت تکهها را پشت سر هم میزند */
|
2026-11-17 21:24:15 +03:30
|
|
|
@Post('evaluate')
|
|
|
|
|
@Roles('owner', 'admin')
|
2026-11-18 13:22:38 +03:30
|
|
|
evaluate(@CurrentUser() user: Actor, @Body() dto: EvaluateAccountBalancesDto) {
|
|
|
|
|
return this.claims.evaluateOrganization(user.organizationId, {
|
|
|
|
|
offset: dto.offset,
|
|
|
|
|
limit: dto.limit,
|
|
|
|
|
});
|
2026-11-17 21:24:15 +03:30
|
|
|
}
|
|
|
|
|
}
|