Add prior promotion endpoints
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
ForbiddenException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
@@ -38,7 +39,7 @@ const dealInclude = {
|
||||
|
||||
type DealActor = Pick<
|
||||
Actor,
|
||||
'userId' | 'role' | 'dataVisibility' | 'visibleUserIds'
|
||||
'userId' | 'role' | 'dataVisibility' | 'visibleUserIds' | 'priorLens' | 'priorCutoff'
|
||||
>;
|
||||
|
||||
@Injectable()
|
||||
@@ -443,6 +444,38 @@ export class DealsService {
|
||||
return this.pipelines.toDealDto(row);
|
||||
}
|
||||
|
||||
async promoteFromPrior(actor: Actor, id: string): Promise<DealDto> {
|
||||
if (
|
||||
(actor.priorLens !== 'current' && actor.priorLens !== 'archive') ||
|
||||
!actor.priorCutoff
|
||||
) {
|
||||
throw new ForbiddenException('بایگانی اطلاعات قبل برای شما فعال نیست.');
|
||||
}
|
||||
|
||||
const row = await this.prisma.deal.findFirst({
|
||||
where: {
|
||||
id,
|
||||
organizationId: actor.organizationId,
|
||||
...dealAccessWhere(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.deal.update({
|
||||
where: { id },
|
||||
data: { promotedFromPriorAt: new Date() },
|
||||
include: dealInclude,
|
||||
});
|
||||
return this.pipelines.toDealDto(updated);
|
||||
}
|
||||
|
||||
async remove(
|
||||
organizationId: string,
|
||||
id: string,
|
||||
|
||||
Reference in New Issue
Block a user