104 lines
2.8 KiB
TypeScript
104 lines
2.8 KiB
TypeScript
import { Body, Controller, Delete, Get, Param, Post, Put, Query, UseGuards } from '@nestjs/common';
|
|
import { HqAuthGuard } from '../../common/guards/hq-auth.guard';
|
|
import { HqOperation } from '../../common/hq-operation/hq-operation.decorator';
|
|
import { HqOperationAction } from '../../common/hq-operation/hq-operation.constants';
|
|
import { AdminPartnersService } from './admin-partners.service';
|
|
import { AdminPartnerAccountsQueryDto, AdminPartnersQueryDto } from './dto/admin-query.dto';
|
|
import {
|
|
CreatePartnerAccountDto,
|
|
CreatePartnerDto,
|
|
UpdatePartnerAccountDto,
|
|
UpdatePartnerDto,
|
|
} from './dto/admin-mutate.dto';
|
|
|
|
@Controller('admin/partners')
|
|
@UseGuards(HqAuthGuard)
|
|
export class AdminPartnersController {
|
|
constructor(private readonly service: AdminPartnersService) {}
|
|
|
|
@Get()
|
|
list(@Query() query: AdminPartnersQueryDto) {
|
|
return this.service.listPartners(query);
|
|
}
|
|
|
|
@Get(':id')
|
|
detail(@Param('id') id: string) {
|
|
return this.service.detailPartner(BigInt(id));
|
|
}
|
|
|
|
@Post()
|
|
@HqOperation({
|
|
action: HqOperationAction.PARTNER_CREATE,
|
|
refType: 'PARTNER',
|
|
refIdField: 'id',
|
|
includeBody: true,
|
|
})
|
|
create(@Body() dto: CreatePartnerDto) {
|
|
return this.service.createPartner(dto);
|
|
}
|
|
|
|
@Put(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.PARTNER_UPDATE,
|
|
refType: 'PARTNER',
|
|
refIdParam: 'id',
|
|
includeBody: true,
|
|
})
|
|
update(@Param('id') id: string, @Body() dto: UpdatePartnerDto) {
|
|
return this.service.updatePartner(BigInt(id), dto);
|
|
}
|
|
}
|
|
|
|
@Controller('admin/partner-accounts')
|
|
@UseGuards(HqAuthGuard)
|
|
export class AdminPartnerAccountsController {
|
|
constructor(private readonly service: AdminPartnersService) {}
|
|
|
|
@Get('tree')
|
|
tree(@Query('partnerId') partnerId?: string) {
|
|
return this.service.listPartnerAccountTree(partnerId ? BigInt(partnerId) : undefined);
|
|
}
|
|
|
|
@Get()
|
|
list(@Query() query: AdminPartnerAccountsQueryDto) {
|
|
return this.service.listPartnerAccounts(query);
|
|
}
|
|
|
|
@Get(':id')
|
|
detail(@Param('id') id: string) {
|
|
return this.service.detailPartnerAccount(BigInt(id));
|
|
}
|
|
|
|
@Post()
|
|
@HqOperation({
|
|
action: HqOperationAction.PARTNER_ACCOUNT_CREATE,
|
|
refType: 'PARTNER_ACCOUNT',
|
|
refIdField: 'id',
|
|
includeBody: true,
|
|
})
|
|
create(@Body() dto: CreatePartnerAccountDto) {
|
|
return this.service.createPartnerAccount(dto);
|
|
}
|
|
|
|
@Put(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.PARTNER_ACCOUNT_UPDATE,
|
|
refType: 'PARTNER_ACCOUNT',
|
|
refIdParam: 'id',
|
|
includeBody: true,
|
|
})
|
|
update(@Param('id') id: string, @Body() dto: UpdatePartnerAccountDto) {
|
|
return this.service.updatePartnerAccount(BigInt(id), dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.PARTNER_ACCOUNT_DELETE,
|
|
refType: 'PARTNER_ACCOUNT',
|
|
refIdParam: 'id',
|
|
})
|
|
remove(@Param('id') id: string) {
|
|
return this.service.deletePartnerSubAccount(BigInt(id));
|
|
}
|
|
}
|