feat: tenant list search filter
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
f516e98f7f
commit
0823c750b2
@ -1,5 +1,6 @@
|
|||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
||||||
|
import { PageQuery } from '../common/page.dto.js';
|
||||||
|
|
||||||
export class CreateTenantDto {
|
export class CreateTenantDto {
|
||||||
@ApiProperty({ description: '租户编码' })
|
@ApiProperty({ description: '租户编码' })
|
||||||
@ -39,3 +40,20 @@ export class UpdateTenantDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
remark?: string;
|
remark?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ListTenantQuery extends PageQuery {
|
||||||
|
@ApiPropertyOptional({ description: '租户名称(模糊)' })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
name?: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: '租户编码(模糊)' })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
code?: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: '状态:enabled/disabled' })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
status?: string;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common';
|
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common';
|
||||||
import { PageQuery } from '../common/page.dto.js';
|
|
||||||
import { Permissions } from '../common/permissions.js';
|
import { Permissions } from '../common/permissions.js';
|
||||||
import { AuditLog, RequirePermissions } from '../auth/decorators.js';
|
import { AuditLog, RequirePermissions } from '../auth/decorators.js';
|
||||||
import { CreateTenantDto, UpdateTenantDto } from './dto.js';
|
import { CreateTenantDto, ListTenantQuery, UpdateTenantDto } from './dto.js';
|
||||||
import { TenantsService } from './tenants.service.js';
|
import { TenantsService } from './tenants.service.js';
|
||||||
|
|
||||||
@Controller('tenants')
|
@Controller('tenants')
|
||||||
@ -11,8 +10,8 @@ export class TenantsController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequirePermissions(Permissions.tenant.list)
|
@RequirePermissions(Permissions.tenant.list)
|
||||||
list(@Query() q: PageQuery) {
|
list(@Query() q: ListTenantQuery) {
|
||||||
return this.service.paginate(q.page, q.pageSize);
|
return this.service.listTenants(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { BaseCrudService } from '../common/base-crud.service.js';
|
import { BaseCrudService } from '../common/base-crud.service.js';
|
||||||
import { PrismaService } from '../prisma/prisma.service.js';
|
import { PrismaService } from '../prisma/prisma.service.js';
|
||||||
import { CreateTenantDto, UpdateTenantDto } from './dto.js';
|
import { CreateTenantDto, ListTenantQuery, UpdateTenantDto } from './dto.js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TenantsService extends BaseCrudService {
|
export class TenantsService extends BaseCrudService {
|
||||||
@ -13,6 +13,14 @@ export class TenantsService extends BaseCrudService {
|
|||||||
return this.create({ ...dto });
|
return this.create({ ...dto });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listTenants(q: ListTenantQuery) {
|
||||||
|
const where: Record<string, unknown> = {};
|
||||||
|
if (q.name) where.name = { contains: q.name };
|
||||||
|
if (q.code) where.code = { contains: q.code };
|
||||||
|
if (q.status) where.status = q.status;
|
||||||
|
return this.paginate(q.page, q.pageSize, where);
|
||||||
|
}
|
||||||
|
|
||||||
async updateTenant(id: string, dto: UpdateTenantDto) {
|
async updateTenant(id: string, dto: UpdateTenantDto) {
|
||||||
const existing = await this.findById(id);
|
const existing = await this.findById(id);
|
||||||
if (!existing) throw new NotFoundException('租户不存在');
|
if (!existing) throw new NotFoundException('租户不存在');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user