mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-21 16:12:18 +03:00
Fix secondary links default value and types (#8532)
Fixes broken companies view
This commit is contained in:
parent
8c33e4cdae
commit
ac1197afe1
@ -93,7 +93,7 @@ const fieldLinksMock = {
|
||||
type: FieldMetadataType.LINKS,
|
||||
isNullable: false,
|
||||
defaultValue: [
|
||||
{ primaryLinkLabel: '', primaryLinkUrl: '', secondaryLinks: {} },
|
||||
{ primaryLinkLabel: '', primaryLinkUrl: '', secondaryLinks: [] },
|
||||
],
|
||||
};
|
||||
|
||||
|
@ -22,7 +22,7 @@ export class LinksMetadata {
|
||||
primaryLinkUrl: string;
|
||||
|
||||
@Field(() => [LinkMetadata], { nullable: true })
|
||||
secondaryLinks: object | null;
|
||||
secondaryLinks: LinkMetadata[] | null;
|
||||
}
|
||||
|
||||
@ObjectType('TimelineCalendarEvent')
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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 {
|
||||
|
@ -38,7 +38,7 @@ export function generateDefaultValue(
|
||||
return {
|
||||
primaryLinkLabel: "''",
|
||||
primaryLinkUrl: "''",
|
||||
secondaryLinks: [],
|
||||
secondaryLinks: "'[]'",
|
||||
};
|
||||
case FieldMetadataType.PHONES:
|
||||
return {
|
||||
|
@ -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);
|
||||
|
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user