Standardize isDefined usage for metadata version assertions (#11829)
# Introduction `!value` is risky as `!falsy` would return `true`
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
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 { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface';
|
||||||
|
|
||||||
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||||
@ -40,7 +42,7 @@ export class FieldMetadataRelationService {
|
|||||||
const metadataVersion =
|
const metadataVersion =
|
||||||
await this.workspaceCacheStorageService.getMetadataVersion(workspaceId);
|
await this.workspaceCacheStorageService.getMetadataVersion(workspaceId);
|
||||||
|
|
||||||
if (!metadataVersion) {
|
if (!isDefined(metadataVersion)) {
|
||||||
throw new FieldMetadataException(
|
throw new FieldMetadataException(
|
||||||
`Metadata version not found for workspace ${workspaceId}`,
|
`Metadata version not found for workspace ${workspaceId}`,
|
||||||
FieldMetadataExceptionCode.INTERNAL_SERVER_ERROR,
|
FieldMetadataExceptionCode.INTERNAL_SERVER_ERROR,
|
||||||
|
|||||||
@ -537,7 +537,7 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
|||||||
const metadataVersion =
|
const metadataVersion =
|
||||||
await this.workspaceCacheStorageService.getMetadataVersion(workspaceId);
|
await this.workspaceCacheStorageService.getMetadataVersion(workspaceId);
|
||||||
|
|
||||||
if (!metadataVersion) {
|
if (!isDefined(metadataVersion)) {
|
||||||
throw new NotFoundException(
|
throw new NotFoundException(
|
||||||
`Metadata version not found for workspace ${workspaceId}`,
|
`Metadata version not found for workspace ${workspaceId}`,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
import { isDefined } from 'twenty-shared/utils';
|
||||||
|
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||||
@ -44,7 +45,7 @@ export class WorkspaceMetadataCacheService {
|
|||||||
const currentDatabaseVersion =
|
const currentDatabaseVersion =
|
||||||
await this.getMetadataVersionFromDatabase(workspaceId);
|
await this.getMetadataVersionFromDatabase(workspaceId);
|
||||||
|
|
||||||
if (currentDatabaseVersion === undefined) {
|
if (!isDefined(currentDatabaseVersion)) {
|
||||||
throw new WorkspaceMetadataCacheException(
|
throw new WorkspaceMetadataCacheException(
|
||||||
'Metadata version not found in the database',
|
'Metadata version not found in the database',
|
||||||
WorkspaceMetadataCacheExceptionCode.METADATA_VERSION_NOT_FOUND,
|
WorkspaceMetadataCacheExceptionCode.METADATA_VERSION_NOT_FOUND,
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
import { isDefined } from 'twenty-shared/utils';
|
||||||
|
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
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';
|
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;
|
const metadataVersion = workspace?.metadataVersion;
|
||||||
|
|
||||||
if (metadataVersion === undefined) {
|
if (!isDefined(metadataVersion)) {
|
||||||
throw new WorkspaceMetadataVersionException(
|
throw new WorkspaceMetadataVersionException(
|
||||||
'Metadata version not found',
|
'Metadata version not found',
|
||||||
WorkspaceMetadataVersionExceptionCode.METADATA_VERSION_NOT_FOUND,
|
WorkspaceMetadataVersionExceptionCode.METADATA_VERSION_NOT_FOUND,
|
||||||
|
|||||||
@ -307,7 +307,7 @@ export class WorkspaceDatasourceFactory {
|
|||||||
let latestWorkspaceMetadataVersion =
|
let latestWorkspaceMetadataVersion =
|
||||||
await this.workspaceCacheStorageService.getMetadataVersion(workspaceId);
|
await this.workspaceCacheStorageService.getMetadataVersion(workspaceId);
|
||||||
|
|
||||||
if (latestWorkspaceMetadataVersion === undefined) {
|
if (!isDefined(latestWorkspaceMetadataVersion)) {
|
||||||
if (shouldFailIfMetadataNotFound) {
|
if (shouldFailIfMetadataNotFound) {
|
||||||
throw new TwentyORMException(
|
throw new TwentyORMException(
|
||||||
`Metadata version not found for workspace ${workspaceId}`,
|
`Metadata version not found for workspace ${workspaceId}`,
|
||||||
@ -325,7 +325,7 @@ export class WorkspaceDatasourceFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!latestWorkspaceMetadataVersion) {
|
if (!isDefined(latestWorkspaceMetadataVersion)) {
|
||||||
throw new TwentyORMException(
|
throw new TwentyORMException(
|
||||||
`Metadata version not found after recompute for workspace ${workspaceId}`,
|
`Metadata version not found after recompute for workspace ${workspaceId}`,
|
||||||
TwentyORMExceptionCode.METADATA_VERSION_NOT_FOUND,
|
TwentyORMExceptionCode.METADATA_VERSION_NOT_FOUND,
|
||||||
|
|||||||
Reference in New Issue
Block a user