Add account balance claims board with opt-in module and range settings.
EOF Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -10,7 +10,10 @@ import type {
|
||||
ActivityStageDto,
|
||||
ActivityStatus,
|
||||
} from '@mento/shared';
|
||||
import { ACTIVITY_STAGE_COLORS } from '@mento/shared';
|
||||
import {
|
||||
ACTIVITY_BOARD_SYSTEM_BALANCE_CLAIMS,
|
||||
ACTIVITY_STAGE_COLORS,
|
||||
} from '@mento/shared';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@@ -39,6 +42,7 @@ type BoardRow = {
|
||||
name: string;
|
||||
isDefault: boolean;
|
||||
position: number;
|
||||
systemKey: string | null;
|
||||
members: Array<{ userId: string }>;
|
||||
};
|
||||
|
||||
@@ -49,6 +53,7 @@ function toBoardDto(row: BoardRow): ActivityBoardDto {
|
||||
isDefault: row.isDefault,
|
||||
position: row.position,
|
||||
memberIds: row.members.map((member) => member.userId),
|
||||
systemKey: row.systemKey,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -69,6 +74,7 @@ const BOARD_SELECT = {
|
||||
id: true,
|
||||
name: true,
|
||||
isDefault: true,
|
||||
systemKey: true,
|
||||
position: true,
|
||||
members: { select: { userId: true } },
|
||||
} satisfies Prisma.ActivityBoardSelect;
|
||||
@@ -142,9 +148,35 @@ export class ActivityStagesService {
|
||||
});
|
||||
const boards = rows.map(toBoardDto);
|
||||
if (!actor || managesAllBoards(actor.role)) return boards;
|
||||
return boards.filter(
|
||||
(board) => board.memberIds.length === 0 || board.memberIds.includes(actor.userId),
|
||||
);
|
||||
|
||||
const claimBoardIds = boards
|
||||
.filter((b) => b.systemKey === ACTIVITY_BOARD_SYSTEM_BALANCE_CLAIMS)
|
||||
.map((b) => b.id);
|
||||
const assignedClaimBoardIds = new Set<string>();
|
||||
if (claimBoardIds.length) {
|
||||
const assigned = await this.prisma.activity.findMany({
|
||||
where: {
|
||||
organizationId,
|
||||
boardId: { in: claimBoardIds },
|
||||
OR: [
|
||||
{ assigneeId: actor.userId },
|
||||
{ assignees: { some: { id: actor.userId } } },
|
||||
],
|
||||
},
|
||||
select: { boardId: true },
|
||||
distinct: ['boardId'],
|
||||
});
|
||||
for (const row of assigned) {
|
||||
if (row.boardId) assignedClaimBoardIds.add(row.boardId);
|
||||
}
|
||||
}
|
||||
|
||||
return boards.filter((board) => {
|
||||
if (board.systemKey === ACTIVITY_BOARD_SYSTEM_BALANCE_CLAIMS) {
|
||||
return assignedClaimBoardIds.has(board.id);
|
||||
}
|
||||
return board.memberIds.length === 0 || board.memberIds.includes(actor.userId);
|
||||
});
|
||||
}
|
||||
|
||||
/** گروه بدون عضو برای همه باز است؛ مالک و مدیر همهٔ گروهها را میبینند */
|
||||
@@ -154,6 +186,25 @@ export class ActivityStagesService {
|
||||
actor: { userId: string; role: string },
|
||||
) {
|
||||
if (managesAllBoards(actor.role)) return;
|
||||
const board = await this.prisma.activityBoard.findFirst({
|
||||
where: { id: boardId, organizationId },
|
||||
select: { systemKey: true },
|
||||
});
|
||||
if (!board) throw new ForbiddenException('به این گروه فعالیت دسترسی ندارید');
|
||||
if (board.systemKey === ACTIVITY_BOARD_SYSTEM_BALANCE_CLAIMS) {
|
||||
const hit = await this.prisma.activity.count({
|
||||
where: {
|
||||
organizationId,
|
||||
boardId,
|
||||
OR: [
|
||||
{ assigneeId: actor.userId },
|
||||
{ assignees: { some: { id: actor.userId } } },
|
||||
],
|
||||
},
|
||||
});
|
||||
if (hit > 0) return;
|
||||
throw new ForbiddenException('به این گروه فعالیت دسترسی ندارید');
|
||||
}
|
||||
const members = await this.prisma.activityBoardMember.findMany({
|
||||
where: { boardId, board: { organizationId } },
|
||||
select: { userId: true },
|
||||
@@ -206,7 +257,13 @@ export class ActivityStagesService {
|
||||
id: string,
|
||||
dto: { name?: string; memberIds?: string[] },
|
||||
): Promise<ActivityBoardDto> {
|
||||
await this.getBoard(organizationId, id);
|
||||
const board = await this.getBoard(organizationId, id);
|
||||
if (board.systemKey && dto.name != null) {
|
||||
throw new BadRequestException('نام این گروه سیستمی قابل تغییر نیست');
|
||||
}
|
||||
if (board.systemKey && dto.memberIds !== undefined) {
|
||||
throw new BadRequestException('اعضای این گروه سیستمی از اینجا قابل تغییر نیست');
|
||||
}
|
||||
try {
|
||||
if (dto.name != null) {
|
||||
await this.prisma.activityBoard.update({
|
||||
@@ -255,6 +312,9 @@ export class ActivityStagesService {
|
||||
if (board.isDefault) {
|
||||
throw new BadRequestException('گروه پیشفرض قابل حذف نیست');
|
||||
}
|
||||
if (board.systemKey) {
|
||||
throw new BadRequestException('گروه سیستمی قابل حذف نیست');
|
||||
}
|
||||
await this.prisma.$transaction([
|
||||
this.prisma.activity.updateMany({
|
||||
where: { organizationId, boardId: id },
|
||||
|
||||
Reference in New Issue
Block a user