File size: 846 Bytes
d9494a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { type FieldMetadataDefaultValueForAnyType } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';

import { isNullEquivalentTextDefaultValue } from './is-null-equivalent-text-default-value.util';

export const nullifyEmptyFullNameDefaultValue = (
  defaultValue: FieldMetadataDefaultValueForAnyType,
): FieldMetadataDefaultValueForAnyType => {
  if (!isDefined(defaultValue)) {
    return null;
  }

  const v = defaultValue as {
    firstName?: string | null;
    lastName?: string | null;
  };

  const firstName = isNullEquivalentTextDefaultValue(v.firstName)
    ? null
    : (v.firstName ?? null);
  const lastName = isNullEquivalentTextDefaultValue(v.lastName)
    ? null
    : (v.lastName ?? null);

  if (firstName === null && lastName === null) {
    return null;
  }

  return { firstName, lastName };
};