Fix secondary links default value and types (#8532)

Fixes broken companies view
This commit is contained in:
ad-elias 2024-11-17 15:18:02 +01:00 committed by GitHub
parent 8c33e4cdae
commit ac1197afe1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 25 additions and 16 deletions

View File

@ -93,7 +93,7 @@ const fieldLinksMock = {
type: FieldMetadataType.LINKS,
isNullable: false,
defaultValue: [
{ primaryLinkLabel: '', primaryLinkUrl: '', secondaryLinks: {} },
{ primaryLinkLabel: '', primaryLinkUrl: '', secondaryLinks: [] },
],
};

View File

@ -22,7 +22,7 @@ export class LinksMetadata {
primaryLinkUrl: string;
@Field(() => [LinkMetadata], { nullable: true })
secondaryLinks: object | null;
secondaryLinks: LinkMetadata[] | null;
}
@ObjectType('TimelineCalendarEvent')

View File

@ -27,8 +27,13 @@ export const linksCompositeType: CompositeType = {
],
};
export type LinkMetadata = {
label: string;
url: string;
};
export type LinksMetadata = {
primaryLinkLabel: string;
primaryLinkUrl: string;
secondaryLinks: object | null;
secondaryLinks: LinkMetadata[] | null;
};

View File

@ -31,7 +31,7 @@ export class FieldMetadataDefaultValueString {
export class FieldMetadataDefaultValueRawJson {
@ValidateIf((_object, value) => value !== null)
@IsObject()
@IsObject() // TODO: Should this also allow arrays?
value: object | null;
}
@ -137,6 +137,14 @@ export class FieldMetadataDefaultValueAddress {
addressLng: number | null;
}
class LinkMetadata {
@IsString()
label: string;
@IsString()
url: string;
}
export class FieldMetadataDefaultValueLinks {
@ValidateIf((_object, value) => value !== null)
@IsQuotedString()
@ -147,8 +155,8 @@ export class FieldMetadataDefaultValueLinks {
primaryLinkUrl: string | null;
@ValidateIf((_object, value) => value !== null)
@IsObject()
secondaryLinks: object | null;
@IsArray()
secondaryLinks: LinkMetadata[] | null;
}
export class FieldMetadataDefaultActor {

View File

@ -38,7 +38,7 @@ export function generateDefaultValue(
return {
primaryLinkLabel: "''",
primaryLinkUrl: "''",
secondaryLinks: [],
secondaryLinks: "'[]'",
};
case FieldMetadataType.PHONES:
return {

View File

@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
import axios, { AxiosInstance } from 'axios';
import uniqBy from 'lodash.uniqby';
import { EntityManager, ILike } from 'typeorm';
import { DeepPartial, EntityManager, ILike } from 'typeorm';
import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
@ -90,11 +90,7 @@ export class CreateCompanyService {
);
// Create new companies
const createdCompanies = await companyRepository.save(
newCompaniesData,
undefined,
transactionManager,
);
const createdCompanies = await companyRepository.save(newCompaniesData);
const createdCompanyIdsMap = this.createCompanyMap(createdCompanies);
return {
@ -157,10 +153,10 @@ export class CreateCompanyService {
};
}
private createCompanyMap(companies: CompanyWorkspaceEntity[]) {
private createCompanyMap(companies: DeepPartial<CompanyWorkspaceEntity>[]) {
return companies.reduce(
(acc, company) => {
if (!company.domainName) {
if (!company.domainName?.primaryLinkUrl || !company.id) {
return acc;
}
const key = extractDomainFromLink(company.domainName.primaryLinkUrl);

View File

@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { EntityManager } from 'typeorm';
import { DeepPartial, EntityManager } from 'typeorm';
import { v4 } from 'uuid';
import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';