From 92144b4cc08acf0f55e7e880f48c637fa62ccbae Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Thu, 30 Jan 2025 10:58:08 -0800 Subject: [PATCH] [TM-1675] Don't send test projects to AT. --- .../airtable/entities/airtable-entity.spec.ts | 3 +++ .../src/airtable/entities/airtable-entity.ts | 18 ++++++++++-------- .../entities/project.airtable-entity.ts | 1 + .../restoration-partner.airtable-entity.ts | 2 +- .../entities/tree-species.airtable-entity.ts | 2 +- .../entities/workday.airtable-entity.ts | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/apps/unified-database-service/src/airtable/entities/airtable-entity.spec.ts b/apps/unified-database-service/src/airtable/entities/airtable-entity.spec.ts index a458030..f339d19 100644 --- a/apps/unified-database-service/src/airtable/entities/airtable-entity.spec.ts +++ b/apps/unified-database-service/src/airtable/entities/airtable-entity.spec.ts @@ -457,6 +457,9 @@ describe("AirtableEntity", () => { }) ); + // make sure test projects are not included + await ProjectFactory.create({ organisationId: orgId(), isTest: true }); + projects = allProjects.filter(project => !project.isSoftDeleted()); applicationUuids = ( await Application.findAll({ diff --git a/apps/unified-database-service/src/airtable/entities/airtable-entity.ts b/apps/unified-database-service/src/airtable/entities/airtable-entity.ts index 548198b..c73a11f 100644 --- a/apps/unified-database-service/src/airtable/entities/airtable-entity.ts +++ b/apps/unified-database-service/src/airtable/entities/airtable-entity.ts @@ -1,5 +1,5 @@ import { Model, ModelCtor, ModelType } from "sequelize-typescript"; -import { cloneDeep, flatten, groupBy, isObject, uniq } from "lodash"; +import { cloneDeep, flatten, groupBy, isEmpty, isObject, uniq } from "lodash"; import { Attributes, FindOptions, Op, WhereOptions } from "sequelize"; import { TMLogService } from "@terramatch-microservices/common/util/tm-log.service"; import { LoggerService } from "@nestjs/common"; @@ -16,7 +16,7 @@ export abstract class AirtableEntity, Associa abstract readonly MODEL: ModelCtor; readonly IDENTITY_COLUMN: string = "uuid"; readonly SUPPORTS_UPDATED_SINCE: boolean = true; - readonly HAS_HIDDEN_FLAG: boolean = false; + readonly FILTER_FLAGS: string[] = []; protected readonly logger: LoggerService = new TMLogService(AirtableEntity.name); @@ -69,8 +69,10 @@ export abstract class AirtableEntity, Associa if (this.SUPPORTS_UPDATED_SINCE && updatedSince != null) { where["updatedAt"] = { [Op.gte]: updatedSince }; } - if (this.HAS_HIDDEN_FLAG) { - where["hidden"] = false; + if (!isEmpty(this.FILTER_FLAGS)) { + for (const flag of this.FILTER_FLAGS) { + where[flag] = false; + } } return { @@ -87,17 +89,17 @@ export abstract class AirtableEntity, Associa const where = {} as WhereOptions; const deletedAtCondition = { [Op.gte]: deletedSince }; - if (this.HAS_HIDDEN_FLAG) { + if (isEmpty(this.FILTER_FLAGS)) { + where["deletedAt"] = deletedAtCondition; + } else { where[Op.or] = { deletedAt: deletedAtCondition, // include records that have been hidden since the timestamp as well [Op.and]: { updatedAt: { ...deletedAtCondition }, - hidden: true + [Op.or]: this.FILTER_FLAGS.reduce((flags, flag) => ({ ...flags, [flag]: true }), {}) } }; - } else { - where["deletedAt"] = deletedAtCondition; } return { diff --git a/apps/unified-database-service/src/airtable/entities/project.airtable-entity.ts b/apps/unified-database-service/src/airtable/entities/project.airtable-entity.ts index 445cb9f..2256755 100644 --- a/apps/unified-database-service/src/airtable/entities/project.airtable-entity.ts +++ b/apps/unified-database-service/src/airtable/entities/project.airtable-entity.ts @@ -108,6 +108,7 @@ export class ProjectEntity extends AirtableEntity readonly COLUMNS = COLUMNS; readonly MODEL = Project; readonly SUPPORTS_UPDATED_SINCE = false; + readonly FILTER_FLAGS = ["isTest"]; async loadAssociations(projects: Project[]) { const projectIds = projects.map(({ id }) => id); diff --git a/apps/unified-database-service/src/airtable/entities/restoration-partner.airtable-entity.ts b/apps/unified-database-service/src/airtable/entities/restoration-partner.airtable-entity.ts index 892d3ce..b2464c5 100644 --- a/apps/unified-database-service/src/airtable/entities/restoration-partner.airtable-entity.ts +++ b/apps/unified-database-service/src/airtable/entities/restoration-partner.airtable-entity.ts @@ -23,7 +23,7 @@ export class RestorationPartnerEntity extends AirtableEntity readonly TABLE_NAME = "Workdays"; readonly COLUMNS = COLUMNS; readonly MODEL = Workday; - readonly HAS_HIDDEN_FLAG = true; + readonly FILTER_FLAGS = ["hidden"]; protected async loadAssociations(workdays: Workday[]) { return this.loadPolymorphicUuidAssociations(LARAVEL_TYPE_MAPPINGS, "workdayableType", "workdayableId", workdays);