Skip to content
This repository was archived by the owner on Jan 28, 2026. It is now read-only.

Commit f8423b5

Browse files
committed
feat: Enhance findAll method to support optional filtering by organization approval status
1 parent fa901c0 commit f8423b5

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

src/organization/organization.controller.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import {
1515
NotFoundException,
1616
Version,
1717
HttpCode,
18+
Query,
1819
} from '@nestjs/common';
1920
import { FilesInterceptor } from '@nestjs/platform-express';
20-
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiConsumes, ApiBody } from '@nestjs/swagger';
21+
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiConsumes, ApiBody, ApiQuery } from '@nestjs/swagger';
2122
import { Response } from 'express';
2223
import { OrganizationService } from './organization.service';
2324
import { S3Service } from './s3.service';
@@ -70,11 +71,36 @@ export class OrganizationController {
7071
@Get()
7172
@UseGuards(JwtAuthGuard)
7273
@ApiBearerAuth()
73-
@ApiOperation({ summary: 'Получить все организации1' })
74+
@ApiOperation({
75+
summary: 'Получить все организации',
76+
description: 'Возвращает список организаций. Выводятся только не удалённые записи (record_status != "DELETED").'
77+
})
78+
@ApiQuery({
79+
name: 'filteredByStatus',
80+
required: false,
81+
type: Boolean,
82+
description: 'Фильтр по статусу подтверждения организации (isApproved). ' +
83+
'По умолчанию (если параметр не указан) выводятся все организации, кроме удалённых (подтверждённые и не подтверждённые). ' +
84+
'Возможные значения:\n' +
85+
'- true: только подтверждённые организации (isApproved = true)\n' +
86+
'- false: только не подтверждённые организации (isApproved = false)',
87+
example: true,
88+
enum: [true, false]
89+
})
7490
@ApiResponse({ status: 200, description: 'Список организаций' })
7591
@ApiResponse({ status: 401, description: 'Не авторизован' })
76-
findAll() {
77-
return this.organizationService.findAll();
92+
findAll(@Query('filteredByStatus') filteredByStatus?: string) {
93+
// Преобразуем строку в boolean, если параметр передан
94+
let isApproved: boolean | undefined = undefined;
95+
if (filteredByStatus !== undefined) {
96+
if (filteredByStatus === 'true') {
97+
isApproved = true;
98+
} else if (filteredByStatus === 'false') {
99+
isApproved = false;
100+
}
101+
// Если передано что-то другое, оставляем undefined (выводим все)
102+
}
103+
return this.organizationService.findAll(isApproved);
78104
}
79105

80106
@Get(':id')

src/organization/organization.repository.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,17 @@ export class OrganizationRepository {
6363

6464
/**
6565
* Получить все организации с связанными данными (города, типы организаций)
66+
* @param filteredByStatus - опциональный фильтр по статусу подтверждения (true - только подтверждённые, false - только не подтверждённые)
6667
*/
67-
async findAll(): Promise<OrganizationWithRelations[]> {
68+
async findAll(filteredByStatus?: boolean): Promise<OrganizationWithRelations[]> {
6869
try {
70+
const conditions = [ne(organizations.recordStatus, 'DELETED')];
71+
72+
// Добавляем фильтр по статусу подтверждения, если он указан
73+
if (filteredByStatus !== undefined) {
74+
conditions.push(eq(organizations.isApproved, filteredByStatus));
75+
}
76+
6977
return await this.db
7078
.select({
7179
id: organizations.id,
@@ -101,7 +109,7 @@ export class OrganizationRepository {
101109
eq(organizations.organizationTypeId, organizationTypes.id),
102110
ne(organizationTypes.recordStatus, 'DELETED')
103111
))
104-
.where(ne(organizations.recordStatus, 'DELETED'));
112+
.where(and(...conditions));
105113
} catch (error: any) {
106114
this.logger.error('Ошибка в findAll:', error);
107115
this.logger.error('Детали ошибки:', {

src/organization/organization.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ export class OrganizationService {
124124
return organization;
125125
}
126126

127-
async findAll() {
127+
async findAll(filteredByStatus?: boolean) {
128128
try {
129-
const orgs = await this.repository.findAll();
129+
const orgs = await this.repository.findAll(filteredByStatus);
130130

131131
// Получаем helpTypes для всех организаций
132132
const orgIds = orgs.map(org => org.id);

0 commit comments

Comments
 (0)