feat: separate prior records behind an owner switch and count last-period questions

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-15 10:48:30 +03:30
co-authored by Cursor
parent 3a8a684aa4
commit 6bc5e1bec7
29 changed files with 775 additions and 77 deletions
+15
View File
@@ -96,6 +96,21 @@ export class UsersController {
);
}
@Patch(':id/prior-archive')
@Roles('owner')
updatePriorArchive(
@CurrentUser() user: { organizationId: string; role: UserRole },
@Param('id') id: string,
@Body() body: { enabled?: boolean },
) {
return this.usersService.updatePriorArchive(
user.organizationId,
user.role,
id,
body.enabled === true,
);
}
@Patch(':id/visibility')
@Roles('owner', 'admin')
updateVisibility(
+28
View File
@@ -44,6 +44,7 @@ type MembershipRow = {
commissionPercent: { toString(): string } | number | null;
dataVisibility?: string | null;
dataVisibilityScopes?: unknown;
priorArchiveEnabled?: boolean;
createdAt: Date;
orgRole: { id: string; name: string; color: string } | null;
user: {
@@ -241,6 +242,32 @@ export class UsersService {
return this.dtoOf(organizationId, targetId);
}
async updatePriorArchive(
organizationId: string,
actorRole: UserRole,
targetId: string,
enabled: boolean,
): Promise<OrgUserDto> {
if (actorRole !== 'owner') {
throw new ForbiddenException('فقط مالک می‌تواند بایگانی اطلاعات قبل را برای کاربران روشن کند');
}
const target = await this.memberships.findUserInOrgById(organizationId, targetId);
if (enabled) {
const org = await this.prisma.organization.findUnique({
where: { id: organizationId },
select: { enabledModules: true },
});
if (!org?.enabledModules?.includes('prior_data_archive')) {
throw new ForbiddenException('بایگانی اطلاعات قبل برای این محیط فعال نیست');
}
}
await this.prisma.membership.update({
where: { id: target.id },
data: { priorArchiveEnabled: enabled },
});
return this.dtoOf(organizationId, targetId);
}
async updateVisibility(
organizationId: string,
actorRole: UserRole,
@@ -478,6 +505,7 @@ export class UsersService {
row.role === 'owner' || row.role === 'admin'
? {}
: parseVisibilityScopes(row.dataVisibilityScopes),
priorArchiveEnabled: Boolean(row.priorArchiveEnabled),
createdAt: row.createdAt.toISOString(),
};
}