Skip to content

Commit

Permalink
Patch: ai filter support for global views
Browse files Browse the repository at this point in the history
  • Loading branch information
saimanoj authored and harshithmullapudi committed Oct 9, 2024
1 parent 3cef0e6 commit 8142b6c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
7 changes: 2 additions & 5 deletions apps/server/src/modules/issues/issues-ai.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ export class IssuesAIController {

@Post('ai_filters')
@UseGuards(AuthGuard)
async aiFilters(
@Query() teamRequestParams: TeamRequestParamsDto,
@Body() filterInput: FilterInput,
) {
return await this.issuesAiService.aiFilters(teamRequestParams, filterInput);
async aiFilters(@Body() filterInput: FilterInput) {
return await this.issuesAiService.aiFilters(filterInput);
}

@Post('ai_title')
Expand Down
33 changes: 26 additions & 7 deletions apps/server/src/modules/issues/issues-ai.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
IssueWithRelations,
SubIssueInput,
} from './issues.interface';
import { getWorkspace } from './issues.utils';

@Injectable()
export default class IssuesAIService {
Expand Down Expand Up @@ -357,17 +356,26 @@ export default class IssuesAIService {
* @returns The generated AI filter.
*/
async aiFilters(
teamRequestParams: TeamRequestParamsDto,
filterInput: FilterInput,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): Promise<Record<string, any>> {
// Retrieve labels based on the provided workspace and team IDs
let teamIds = [filterInput.teamId];
if (!filterInput.teamId) {
const teams = await this.prisma.team.findMany({
where: { workspaceId: filterInput.workspaceId, deleted: null },
select: { id: true },
});

teamIds = teams.map((team) => team.id);
}

const labels = await this.prisma.label.findMany({
where: {
OR: [
{ workspaceId: filterInput.workspaceId },
{ teamId: teamRequestParams.teamId },
],
filterInput.teamId ? { teamId: filterInput.teamId } : {},
].filter(Boolean),
},
});

Expand All @@ -380,7 +388,11 @@ export default class IssuesAIService {

// Retrieve assignees based on the team ID
const assignee = await this.prisma.usersOnWorkspaces.findMany({
where: { teamIds: { has: teamRequestParams.teamId } },
where: {
teamIds: filterInput.teamId
? { has: filterInput.teamId }
: { hasSome: teamIds },
},
include: { user: true },
});

Expand All @@ -393,7 +405,12 @@ export default class IssuesAIService {

// Retrieve workflows based on the team ID
const workflow = await this.prisma.workflow.findMany({
where: { teamId: teamRequestParams.teamId },
where: {
...(filterInput.teamId
? { teamId: filterInput.teamId }
: { team: { workspaceId: filterInput.workspaceId } }),
deleted: null,
},
});

// Extract workflow names from the retrieved workflows
Expand All @@ -404,7 +421,9 @@ export default class IssuesAIService {
});

// Retrieve the workspace based on the team ID
const workspace = await getWorkspace(this.prisma, teamRequestParams.teamId);
const workspace = await this.prisma.workspace.findUnique({
where: { id: filterInput.workspaceId },
});
this.logger.debug({
message: `Retrieved workspace: ${workspace.name}`,
where: `IssuesAIService.aiFilters`,
Expand Down
6 changes: 5 additions & 1 deletion apps/server/src/modules/issues/issues.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Team,
User,
} from '@tegonhq/types';
import { IsArray, IsEnum, IsString } from 'class-validator';
import { IsArray, IsEnum, IsOptional, IsString } from 'class-validator';

export interface ApiResponse {
status: number;
Expand Down Expand Up @@ -48,6 +48,10 @@ export class FilterInput {

@IsString()
workspaceId: string;

@IsString()
@IsOptional()
teamId?: string;
}

export class SubIssueInput extends AIInput {
Expand Down

0 comments on commit 8142b6c

Please sign in to comment.