Files
hedena_gold/apps/api/src/modules/admin-customers/admin-customers.controller.ts
T
mahmoodandClaude Sonnet 5.5 0156a976e7 feat(customers): opt-in debug block on the omde lists, printed in the panel console
Sending X-Debug: 1 makes the five wholesale list endpoints return a counts-only
`debug` block next to the rows: the WHERE that actually ran, how many customers
the scope matches before the grid's own filters, how many customers exist per
kind/active/archived/step and how many are an expert's trading account. The
panel sends the header and console-logs the block when localStorage.debug === '1'.

Off by default; DIAG_LOG=false disables it server-side. No names or mobiles.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-26 08:59:33 +03:30

204 lines
6.6 KiB
TypeScript

import { Body, Controller, Get, Headers, HttpCode, Param, Post, Put } from '@nestjs/common';
import { AdminCustomersService, type OmdeScope } from './admin-customers.service';
import { TableQueryDto } from '../admin-table/table-query.dto';
import { CurrentAdmin, RequirePermission, SuperAdminOnly } from '../auth/guards';
import type { AuthenticatedAdmin } from '../auth/jwt.strategy';
/**
* Wholesale customer lists. Legacy endpoints, one per near-identical view:
* POST customer -> OmdeList
* POST banker -> BankerList
* POST shopkeeper -> ShopkeeperList
* POST major/verify/table -> OmdeNonVerifiedList
* POST major/archive/table -> OmdeArchivedList
* POST customer/toggle-active, customer/toggle-sts, major/verify
* GET major/archive/{id}, major/dashboard/{id}
*/
@Controller('admin/customers-omde')
export class AdminCustomersController {
constructor(private readonly customers: AdminCustomersService) {}
// `X-Debug: 1` (set by the panel when localStorage.debug === '1') adds a
// counts-only `debug` block to the response — see AdminCustomersService.listDebug.
private list(query: TableQueryDto, scope: OmdeScope, debug?: string) {
return this.customers.list(query, scope, debug === '1');
}
@Post('list')
@HttpCode(200)
@RequirePermission('persons.list.client.omde')
listAll(@Body() query: TableQueryDto, @Headers('x-debug') debug?: string) {
return this.list(query, 'all', debug);
}
@Post('banker/list')
@HttpCode(200)
@SuperAdminOnly()
@RequirePermission('persons.list.client.omde')
listBanker(@Body() query: TableQueryDto, @Headers('x-debug') debug?: string) {
return this.list(query, 'banker', debug);
}
@Post('shopkeeper/list')
@HttpCode(200)
@SuperAdminOnly()
@RequirePermission('persons.list.client.omde')
listShopkeeper(@Body() query: TableQueryDto, @Headers('x-debug') debug?: string) {
return this.list(query, 'shopkeeper', debug);
}
@Post('non-verified/list')
@HttpCode(200)
@RequirePermission('persons.list.client.omde')
listNonVerified(@Body() query: TableQueryDto, @Headers('x-debug') debug?: string) {
return this.list(query, 'non_verified', debug);
}
@Post('archived/list')
@HttpCode(200)
@RequirePermission('persons.list.client.omde')
listArchived(@Body() query: TableQueryDto, @Headers('x-debug') debug?: string) {
return this.list(query, 'archived', debug);
}
/** Legacy POST single-customer — the retail customer list. */
@Post('single/list')
@HttpCode(200)
@SuperAdminOnly({ allowBranch: true })
@RequirePermission('persons.list.client.single')
listSingle(@Body() query: TableQueryDto, @CurrentAdmin() admin: AuthenticatedAdmin) {
return this.customers.listSingle(query, admin.branchId ?? undefined);
}
/** Legacy `POST single` — singleCustomer.vue, the retail customer form. */
@Post('single')
@HttpCode(200)
@SuperAdminOnly({ allowBranch: true })
@RequirePermission('persons.create')
createSingle(@Body() data: Record<string, unknown>) {
return this.customers.createSingle(data);
}
/**
* Legacy `GET query/reagent` — the sales-expert picker used by the customer
* form. Returns a plain array of {id, name}, as legacy did.
*/
@Get('query/reagent')
@RequirePermission('persons.create')
queryReagents() {
return this.customers.queryReagents();
}
/** Legacy POST wallet/charge. */
@Post('wallet/charge')
@HttpCode(200)
@RequirePermission('wallet')
chargeWallet(@Body() body: { customer_id: string; value: string | number }) {
return this.customers.chargeWallet(body);
}
@Post('create')
@HttpCode(200)
@RequirePermission('persons.create')
create(@Body() data: Record<string, unknown>) {
return this.customers.create(data);
}
@Put(':id')
@RequirePermission('persons.list.client.omde.edit')
update(@Param('id') id: string, @Body() data: Record<string, unknown>) {
return this.customers.update(id, data);
}
/** Legacy POST reagent — the sales-expert list. */
@Post('reagent/list')
@HttpCode(200)
@RequirePermission('persons.list.sellers')
listReagents(@Body() query: TableQueryDto) {
return this.customers.listReagents(query);
}
/** A sales agent's own detail screen — see reagentDetail()'s header comment. */
@Get('reagent/:id')
@RequirePermission('persons.list.sellers.view')
reagentDetail(@Param('id') id: string) {
return this.customers.reagentDetail(id);
}
/** Legacy `GET single/order/{id}` — that customer's orders. */
@Get(':id/orders')
@RequirePermission('persons.list.client.omde.view.orders')
customerOrders(@Param('id') id: string) {
return this.customers.customerOrders(id);
}
/** Legacy `GET single/report/{id}` — that customer's ledger documents. */
@Get(':id/documents')
@RequirePermission('persons.list.client.omde.view.documents')
customerDocuments(@Param('id') id: string) {
return this.customers.customerDocuments(id);
}
/** Legacy `GET single/wallet/{id}` — that customer's wallet bonuses. */
@Get(':id/wallet')
@RequirePermission('wallet')
customerWallet(@Param('id') id: string) {
return this.customers.customerWallet(id);
}
@Get('dashboard/:id')
@RequirePermission('persons.list.client.omde.view')
dashboard(@Param('id') id: string) {
return this.customers.dashboard(id);
}
@Get('archive/:id')
@RequirePermission('persons.list.client.omde.edit')
toggleArchive(@Param('id') id: string) {
return this.customers.toggleArchive(id);
}
@Post('toggle-active')
@HttpCode(200)
@RequirePermission('persons.list.client.omde.edit')
toggleActive(@Body() body: { id: string }) {
return this.customers.toggleActive(body.id);
}
@Post('toggle-sts')
@HttpCode(200)
@RequirePermission('persons.list.client.omde.edit')
toggleSts(@Body() body: { id: string }) {
return this.customers.toggleSts(body.id);
}
@Post('verify')
@HttpCode(200)
@RequirePermission('persons.list.client.omde.edit')
verify(
@Body()
body: {
customer_id: string;
sts_verify_step_one?: number;
sts_verify_step_two?: number;
/** Optional, only read on a reject. */
reason?: string | null;
},
) {
return this.customers.verify(body);
}
@Post('credit')
@HttpCode(200)
@RequirePermission('persons.list.client.omde.edit')
updateCredit(@Body() body: { id: string; gram_level?: string; percent?: string }) {
return this.customers.updateCredit(body.id, body);
}
@Get(':id')
@RequirePermission('persons.list.client.omde.view')
findOne(@Param('id') id: string) {
return this.customers.findOne(id);
}
}