Files
hedena_gold/apps/api/src/modules/accounting-sync/accounting-quick.controller.ts
T

49 lines
1.8 KiB
TypeScript
Raw Normal View History

import { Controller, Get, HttpCode, Post } from '@nestjs/common';
import { CurrentCustomer, CustomerAuth } from '../customer-auth/customer.guards';
import type { AuthenticatedCustomer } from '../customer-auth/customer-jwt.strategy';
import { RequirePermission } from '../auth/guards';
import { AccountingAdminService } from './accounting-admin.service';
import { AccountingSyncService } from './accounting-sync.service';
/**
* D27, plan §12 — sync where people work, on top of the «اتصال حسابداری»
* screen: a button on the wholesale-customer list and on the product list,
* and the customer's own balance read live each time the app's profile opens.
* Each is behind the permission of the screen it sits on, and works whenever a
* provider is connected, whatever the feature switches say (owner's ruling).
*/
@Controller()
export class AccountingQuickController {
constructor(
private readonly admin: AccountingAdminService,
private readonly sync: AccountingSyncService,
) {}
/** Whether to show the sync buttons. Any signed-in admin; reveals no settings. */
@Get('admin/accounting-status')
status() {
return this.admin.connectionStatus();
}
@Post('admin/customers-omde/accounting-sync')
@HttpCode(200)
@RequirePermission('persons.list.client.omde')
syncCustomers() {
return this.admin.syncNow(['customers', 'balances']);
}
@Post('admin/products/accounting-sync')
@HttpCode(200)
@RequirePermission('product.list')
syncProducts() {
return this.admin.syncNow(['products']);
}
/** The app's profile: this customer's balance, read from the software now. */
@CustomerAuth()
@Get('customer/me/accounting-balance')
myBalance(@CurrentCustomer() me: AuthenticatedCustomer) {
return this.sync.customerBalanceLive(me.id);
}
}