Skip to content

Commit

Permalink
[TM-1675] Don't send test projects to AT.
Browse files Browse the repository at this point in the history
  • Loading branch information
roguenet committed Jan 30, 2025
1 parent 950645f commit 92144b4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -16,7 +16,7 @@ export abstract class AirtableEntity<ModelType extends Model<ModelType>, Associa
abstract readonly MODEL: ModelCtor<ModelType>;
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);

Expand Down Expand Up @@ -69,8 +69,10 @@ export abstract class AirtableEntity<ModelType extends Model<ModelType>, 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 {
Expand All @@ -87,17 +89,17 @@ export abstract class AirtableEntity<ModelType extends Model<ModelType>, Associa
const where = {} as WhereOptions<ModelType>;

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class ProjectEntity extends AirtableEntity<Project, ProjectAssociations>
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class RestorationPartnerEntity extends AirtableEntity<RestorationPartner,
readonly TABLE_NAME = "Restoration Partners";
readonly COLUMNS = COLUMNS;
readonly MODEL = RestorationPartner;
readonly HAS_HIDDEN_FLAG = true;
readonly FILTER_FLAGS = ["hidden"];

protected async loadAssociations(partners: RestorationPartner[]) {
return this.loadPolymorphicUuidAssociations(LARAVEL_TYPE_MAPPINGS, "partnerableType", "partnerableId", partners);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class TreeSpeciesEntity extends AirtableEntity<TreeSpecies, TreeSpeciesAs
readonly TABLE_NAME = "Tree Species";
readonly COLUMNS = COLUMNS;
readonly MODEL = TreeSpecies;
readonly HAS_HIDDEN_FLAG = true;
readonly FILTER_FLAGS = ["hidden"];

protected async loadAssociations(treeSpecies: TreeSpecies[]) {
return this.loadPolymorphicUuidAssociations(LARAVEL_TYPE_MAPPING, "speciesableType", "speciesableId", treeSpecies);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class WorkdayEntity extends AirtableEntity<Workday, WorkdayAssociations>
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);
Expand Down

0 comments on commit 92144b4

Please sign in to comment.