Standardize isDefined usage for metadata version assertions (#11829)

# Introduction
`!value` is risky as `!falsy` would return `true`
This commit is contained in:
Paul Rastoin
2025-05-02 11:07:12 +02:00
committed by GitHub
parent 9df4778954
commit 3e1b4ace37
5 changed files with 10 additions and 6 deletions

View File

@ -1,5 +1,7 @@
import { Injectable } from '@nestjs/common';
import { isDefined } from 'twenty-shared/utils';
import { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface';
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
@ -40,7 +42,7 @@ export class FieldMetadataRelationService {
const metadataVersion =
await this.workspaceCacheStorageService.getMetadataVersion(workspaceId);
if (!metadataVersion) {
if (!isDefined(metadataVersion)) {
throw new FieldMetadataException(
`Metadata version not found for workspace ${workspaceId}`,
FieldMetadataExceptionCode.INTERNAL_SERVER_ERROR,

View File

@ -537,7 +537,7 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
const metadataVersion =
await this.workspaceCacheStorageService.getMetadataVersion(workspaceId);
if (!metadataVersion) {
if (!isDefined(metadataVersion)) {
throw new NotFoundException(
`Metadata version not found for workspace ${workspaceId}`,
);

View File

@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { isDefined } from 'twenty-shared/utils';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
@ -44,7 +45,7 @@ export class WorkspaceMetadataCacheService {
const currentDatabaseVersion =
await this.getMetadataVersionFromDatabase(workspaceId);
if (currentDatabaseVersion === undefined) {
if (!isDefined(currentDatabaseVersion)) {
throw new WorkspaceMetadataCacheException(
'Metadata version not found in the database',
WorkspaceMetadataCacheExceptionCode.METADATA_VERSION_NOT_FOUND,

View File

@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { isDefined } from 'twenty-shared/utils';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { WorkspaceMetadataCacheService } from 'src/engine/metadata-modules/workspace-metadata-cache/services/workspace-metadata-cache.service';
@ -27,7 +28,7 @@ export class WorkspaceMetadataVersionService {
const metadataVersion = workspace?.metadataVersion;
if (metadataVersion === undefined) {
if (!isDefined(metadataVersion)) {
throw new WorkspaceMetadataVersionException(
'Metadata version not found',
WorkspaceMetadataVersionExceptionCode.METADATA_VERSION_NOT_FOUND,

View File

@ -307,7 +307,7 @@ export class WorkspaceDatasourceFactory {
let latestWorkspaceMetadataVersion =
await this.workspaceCacheStorageService.getMetadataVersion(workspaceId);
if (latestWorkspaceMetadataVersion === undefined) {
if (!isDefined(latestWorkspaceMetadataVersion)) {
if (shouldFailIfMetadataNotFound) {
throw new TwentyORMException(
`Metadata version not found for workspace ${workspaceId}`,
@ -325,7 +325,7 @@ export class WorkspaceDatasourceFactory {
}
}
if (!latestWorkspaceMetadataVersion) {
if (!isDefined(latestWorkspaceMetadataVersion)) {
throw new TwentyORMException(
`Metadata version not found after recompute for workspace ${workspaceId}`,
TwentyORMExceptionCode.METADATA_VERSION_NOT_FOUND,