Skip to content

Commit

Permalink
Fix secondary links default value and types (#8532)
Browse files Browse the repository at this point in the history
Fixes broken companies view
  • Loading branch information
ad-elias authored Nov 17, 2024
1 parent 8c33e4c commit ac1197a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const fieldLinksMock = {
type: FieldMetadataType.LINKS,
isNullable: false,
defaultValue: [
{ primaryLinkLabel: '', primaryLinkUrl: '', secondaryLinks: {} },
{ primaryLinkLabel: '', primaryLinkUrl: '', secondaryLinks: [] },
],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class LinksMetadata {
primaryLinkUrl: string;

@Field(() => [LinkMetadata], { nullable: true })
secondaryLinks: object | null;
secondaryLinks: LinkMetadata[] | null;
}

@ObjectType('TimelineCalendarEvent')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function generateDefaultValue(
return {
primaryLinkLabel: "''",
primaryLinkUrl: "''",
secondaryLinks: [],
secondaryLinks: "'[]'",
};
case FieldMetadataType.PHONES:
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit ac1197a

Please sign in to comment.