Adding registration date and multiple addresses for contacts and leads.
This commit is contained in:
@@ -15,7 +15,9 @@ import { PrismaService } from '../prisma/prisma.service';
|
||||
import { CompaniesService } from './companies.service';
|
||||
import { emptyToNull, normalizeEmail, normalizePhone } from './normalize';
|
||||
import {
|
||||
asAddresses,
|
||||
asCustomFields,
|
||||
toJsonAddresses,
|
||||
toJsonCustomFields,
|
||||
} from '../common/custom-fields';
|
||||
import {
|
||||
@@ -47,7 +49,9 @@ type PersonRow = {
|
||||
mobile: string | null;
|
||||
position: string | null;
|
||||
website: string | null;
|
||||
instagram: string | null;
|
||||
referrer: string | null;
|
||||
addresses: unknown;
|
||||
notes: string | null;
|
||||
mood: PersonMood;
|
||||
tags: string[];
|
||||
@@ -138,6 +142,7 @@ export class PeopleService {
|
||||
await this.companies.ensureInOrg(actor.organizationId, companyId, actor);
|
||||
}
|
||||
|
||||
const registeredAt = dto.registeredAt ? new Date(dto.registeredAt) : null;
|
||||
const data: Prisma.PersonUncheckedCreateInput = {
|
||||
organizationId: actor.organizationId,
|
||||
firstName: (dto.firstName ?? '').trim(),
|
||||
@@ -147,13 +152,18 @@ export class PeopleService {
|
||||
mobile: normalizePhone(dto.mobile),
|
||||
position: emptyToNull(dto.position),
|
||||
website: emptyToNull(dto.website),
|
||||
instagram: emptyToNull(dto.instagram),
|
||||
referrer: emptyToNull(dto.referrer),
|
||||
addresses: toJsonAddresses(dto.addresses),
|
||||
notes: emptyToNull(dto.notes),
|
||||
mood: dto.mood ?? 'newcomer',
|
||||
tags: normalizeTags(dto.tags),
|
||||
companyId,
|
||||
ownerId: resolveOwnerId(actor, dto.ownerId),
|
||||
customFields: toJsonCustomFields(dto.customFields),
|
||||
...(registeredAt && !Number.isNaN(registeredAt.getTime())
|
||||
? { createdAt: registeredAt }
|
||||
: {}),
|
||||
};
|
||||
await this.assertNoDuplicate(actor.organizationId, data);
|
||||
|
||||
@@ -202,7 +212,9 @@ export class PeopleService {
|
||||
if ('mobile' in dto) data.mobile = normalizePhone(dto.mobile);
|
||||
if ('position' in dto) data.position = emptyToNull(dto.position);
|
||||
if ('website' in dto) data.website = emptyToNull(dto.website);
|
||||
if ('instagram' in dto) data.instagram = emptyToNull(dto.instagram);
|
||||
if ('referrer' in dto) data.referrer = emptyToNull(dto.referrer);
|
||||
if ('addresses' in dto) data.addresses = toJsonAddresses(dto.addresses);
|
||||
if ('notes' in dto) data.notes = emptyToNull(dto.notes);
|
||||
if (dto.mood !== undefined) data.mood = dto.mood;
|
||||
if ('tags' in dto) data.tags = normalizeTags(dto.tags);
|
||||
@@ -295,7 +307,18 @@ export class PeopleService {
|
||||
mobile: row.mobile,
|
||||
position: row.position,
|
||||
website: row.website,
|
||||
instagram: row.instagram,
|
||||
referrer: row.referrer,
|
||||
addresses: (() => {
|
||||
const fromCol = asAddresses(row.addresses);
|
||||
if (fromCol.length) return fromCol;
|
||||
const extra = asCustomFields(row.customFields);
|
||||
return asAddresses(
|
||||
[extra.address, extra.homeAddress, extra.address2]
|
||||
.map((v) => (typeof v === 'string' ? v : ''))
|
||||
.filter(Boolean),
|
||||
);
|
||||
})(),
|
||||
notes: row.notes,
|
||||
mood: row.mood,
|
||||
tags: row.tags ?? [],
|
||||
|
||||
Reference in New Issue
Block a user