Add prior promotion endpoints

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-17 17:13:01 +03:30
co-authored by Cursor
parent c5708ed59b
commit 008733d338
6 changed files with 272 additions and 1 deletions
@@ -267,6 +267,11 @@ export class ActivitiesController {
return this.activitiesService.get(user.organizationId, id, user);
}
@Post(':id/promote-from-prior')
promoteFromPrior(@CurrentUser() user: Actor, @Param('id') id: string) {
return this.activitiesService.promoteFromPrior(user, id);
}
@Post()
create(@CurrentUser() user: Actor, @Body() dto: CreateActivityDto) {
return this.activitiesService.create(
@@ -1,5 +1,6 @@
import {
BadRequestException,
ForbiddenException,
Injectable,
NotFoundException,
} from '@nestjs/common';
@@ -616,6 +617,38 @@ export class ActivitiesService {
return this.toDto(row, await this.ctx(organizationId));
}
async promoteFromPrior(actor: Actor, id: string): Promise<ActivityDto> {
if (
(actor.priorLens !== 'current' && actor.priorLens !== 'archive') ||
!actor.priorCutoff
) {
throw new ForbiddenException('بایگانی اطلاعات قبل برای شما فعال نیست.');
}
const row = await this.prisma.activity.findFirst({
where: {
id,
organizationId: actor.organizationId,
...activityAccessWhere(actor),
},
select: { id: true, createdAt: true, promotedFromPriorAt: true },
});
if (!row) throw new NotFoundException('فعالیت پیدا نشد');
if (row.promotedFromPriorAt) {
throw new BadRequestException('این فعالیت قبلاً منتقل شده است.');
}
if (row.createdAt >= actor.priorCutoff) {
throw new BadRequestException('این فعالیت در بایگانی نیست.');
}
const updated = await this.prisma.activity.update({
where: { id },
data: { promotedFromPriorAt: new Date() },
include,
});
return this.toDto(updated, await this.ctx(actor.organizationId));
}
async remove(
organizationId: string,
id: string,