Deals Excel import/export aligned with Didar: browser-side import, new deal fields (code, probability, closedAt, creator, lostNote, referrer), Didar custom fields
This commit is contained in:
@@ -30,6 +30,7 @@ const dealInclude = {
|
||||
person: { select: { id: true, firstName: true, lastName: true } },
|
||||
company: { select: { id: true, name: true } },
|
||||
owner: { select: { id: true, fullName: true } },
|
||||
createdBy: { select: { id: true, fullName: true } },
|
||||
assignees: { select: { id: true, fullName: true } },
|
||||
lineItems: { orderBy: { position: 'asc' as const } },
|
||||
} satisfies Prisma.DealInclude;
|
||||
@@ -138,6 +139,18 @@ export class DealsService {
|
||||
expectedCloseAt: dto.expectedCloseAt
|
||||
? new Date(dto.expectedCloseAt)
|
||||
: null,
|
||||
code: emptyToNull(dto.code),
|
||||
probability: normalizeProbability(dto.probability),
|
||||
sourceDetail: emptyToNull(dto.sourceDetail),
|
||||
referrer: emptyToNull(dto.referrer),
|
||||
lostReason: emptyToNull(dto.lostReason),
|
||||
lostNote: emptyToNull(dto.lostNote),
|
||||
closedAt: dto.closedAt
|
||||
? new Date(dto.closedAt)
|
||||
: status !== 'open'
|
||||
? new Date()
|
||||
: null,
|
||||
createdById: actor.userId,
|
||||
personId: emptyToNull(dto.personId ?? null),
|
||||
companyId: emptyToNull(dto.companyId ?? null),
|
||||
ownerId: resolveOwnerId(actor, dto.ownerId),
|
||||
@@ -220,6 +233,12 @@ export class DealsService {
|
||||
data.customFields = toJsonCustomFields(dto.customFields);
|
||||
}
|
||||
if ('lostReason' in dto) data.lostReason = emptyToNull(dto.lostReason);
|
||||
if ('lostNote' in dto) data.lostNote = emptyToNull(dto.lostNote);
|
||||
if ('code' in dto) data.code = emptyToNull(dto.code);
|
||||
if ('probability' in dto) data.probability = normalizeProbability(dto.probability);
|
||||
if ('sourceDetail' in dto) data.sourceDetail = emptyToNull(dto.sourceDetail);
|
||||
if ('referrer' in dto) data.referrer = emptyToNull(dto.referrer);
|
||||
if ('closedAt' in dto) data.closedAt = dto.closedAt ? new Date(dto.closedAt) : null;
|
||||
if ('expectedCloseAt' in dto) {
|
||||
data.expectedCloseAt = dto.expectedCloseAt
|
||||
? new Date(dto.expectedCloseAt)
|
||||
@@ -338,6 +357,9 @@ export class DealsService {
|
||||
position,
|
||||
status,
|
||||
lostReason: stage.isLost ? undefined : null,
|
||||
...(status !== deal.status
|
||||
? { closedAt: status === 'open' ? null : new Date() }
|
||||
: {}),
|
||||
},
|
||||
include: dealInclude,
|
||||
});
|
||||
@@ -494,6 +516,11 @@ function emptyToNull(value?: string | null): string | null {
|
||||
return trimmed.length ? trimmed : null;
|
||||
}
|
||||
|
||||
function normalizeProbability(value?: number | null): number | null {
|
||||
if (value == null || Number.isNaN(Number(value))) return null;
|
||||
return Math.max(0, Math.min(100, Math.round(Number(value))));
|
||||
}
|
||||
|
||||
function normalizeTags(tags?: string[]): string[] {
|
||||
if (!tags?.length) return [];
|
||||
const seen = new Set<string>();
|
||||
|
||||
Reference in New Issue
Block a user