42 lines
1.6 KiB
TypeScript
42 lines
1.6 KiB
TypeScript
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';
|
||
|
|
import { UpdateAccountBalanceSettingsDto } from './dto';
|
||
|
|
|
||
|
|
@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);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** اجرای دستی همان جاب دورهای برای محیط جاری */
|
||
|
|
@Post('evaluate')
|
||
|
|
@Roles('owner', 'admin')
|
||
|
|
async evaluate(@CurrentUser() user: Actor) {
|
||
|
|
await this.claims.evaluateOrganization(user.organizationId);
|
||
|
|
return { ok: true };
|
||
|
|
}
|
||
|
|
}
|