From dff49ddaf7cc856a40be375d10490386fc1f1011 Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Wed, 16 Oct 2024 15:25:32 -0700 Subject: [PATCH 01/14] LF-4470 Create migration for animal movement task * Create 'animal_movement_task' table * Create 'animal_movement_task_purpose_relationship' table * Create 'animal_movement_purpose' table * Create 'animal_movement_task_animal_relationship' table * Create 'animal_movement_task_animal_batch_relationship' table * Add 'ANIMAL_MOVEMENT' type to 'task_type' table * Add 'location_id' column to animal tables --- ...4145_create_animal_movement_task_tables.js | 113 ++++++++++++++++++ ...ovementTaskAnimalBatchRelationshipModel.js | 66 ++++++++++ 2 files changed, 179 insertions(+) create mode 100644 packages/api/db/migration/20241016204145_create_animal_movement_task_tables.js create mode 100644 packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js diff --git a/packages/api/db/migration/20241016204145_create_animal_movement_task_tables.js b/packages/api/db/migration/20241016204145_create_animal_movement_task_tables.js new file mode 100644 index 0000000000..bcd840658b --- /dev/null +++ b/packages/api/db/migration/20241016204145_create_animal_movement_task_tables.js @@ -0,0 +1,113 @@ +/* + * Copyright 2024 LiteFarm.org + * This file is part of LiteFarm. + * + * LiteFarm is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LiteFarm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details, see . + */ + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +export const up = async (knex) => { + // Add new animal_movement entry to task_type table + await knex('task_type').insert({ + task_name: 'Animal Movement', + task_translation_key: 'ANIMAL_MOVEMENT', + }); + + // Add location_id column to animal and animal_batch tables (foreign key to location table) + await knex.schema.alterTable('animal', (table) => { + table.uuid('location_id').references('location_id').inTable('location'); + }); + await knex.schema.alterTable('animal_batch', (table) => { + table.uuid('location_id').references('location_id').inTable('location'); + }); + + // Create animal_movement_purpose enum table + await knex.schema.createTable('animal_movement_purpose', (table) => { + table.increments('id').primary(); + table.string('key').notNullable(); + }); + await knex('animal_movement_purpose').insert( + [ + 'GRAZING', + 'MILKING', + 'MANURE_MANAGEMENT', + 'PEST_OR_DISEASE_CONTROL', + 'BREEDING', + 'FEEDING', + 'VETERINARY_CARE', + 'BIRTHING', + 'WEANING', + 'TRANSPORTATION', + 'BEHAVIORAL_AND_SOCIAL_MANAGEMENT', + 'EXERCISE', + 'QUARANTINE', + 'OTHER', + ].map((key) => ({ key })), + ); + + // Create animal_movement_task table + await knex.schema.createTable('animal_movement_task', (table) => { + table.integer('task_id').references('task_id').inTable('task').primary(); + table.uuid('to_location_id').references('location_id').inTable('location'); + }); + + const [{ id: otherPurposeId }] = await knex('animal_movement_purpose').where({ key: 'OTHER' }); + + // Create animal_movement_task_purpose_relationship table + await knex.schema.createTable('animal_movement_task_purpose_relationship', (table) => { + table.integer('task_id').references('task_id').inTable('task').notNullable(); + table.integer('purpose_id').references('id').inTable('animal_movement_purpose').notNullable(); + table.primary(['task_id', 'purpose_id']); + table.string('other_purpose'); + table.check( + `(other_purpose IS NOT NULL AND purpose_id = ${otherPurposeId}) OR (other_purpose IS NULL)`, + [], + 'other_purpose_id_check', + ); + }); + + // Create animal_movement_task_animal_relationship table (links the task to the animals that are to be moved) + await knex.schema.createTable('animal_movement_task_animal_relationship', (table) => { + table.integer('task_id').references('task_id').inTable('task').notNullable(); + table.integer('animal_id').references('id').inTable('animal').notNullable(); + }); + + // Create animal_movement_task_animal_batch_relationship table (similar to above but for batches) + await knex.schema.createTable('animal_movement_task_animal_batch_relationship', (table) => { + table.integer('task_id').references('task_id').inTable('task').notNullable(); + table.integer('animal_batch_id').references('id').inTable('animal_batch').notNullable(); + }); +}; + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +export const down = async (knex) => { + await knex('task_type').where({ task_translation_key: 'ANIMAL_MOVEMENT' }).del(); + await knex.schema.alterTable('animal', (table) => table.dropColumn('location_id')); + await knex.schema.alterTable('animal_batch', (table) => table.dropColumn('location_id')); + + const tablesToDelete = [ + 'animal_movement_task', + 'animal_movement_task_purpose_relationship', + 'animal_movement_purpose', + 'animal_movement_task_animal_relationship', + 'animal_movement_task_animal_batch_relationship', + ]; + + for (const table of tablesToDelete) { + await knex.schema.dropTable(table); + } +}; diff --git a/packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js b/packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js new file mode 100644 index 0000000000..e9762e85b7 --- /dev/null +++ b/packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js @@ -0,0 +1,66 @@ +/* + * Copyright 2024 LiteFarm.org + * This file is part of LiteFarm. + * + * LiteFarm is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LiteFarm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details, see . + */ + +import Model from './baseFormatModel.js'; +import TaskModel from '../models/taskModel.js'; +import AnimalBatchModel from '../models/animalBatchModel.js'; + +class AnimalMovementTaskAnimalBatchRelationshipModel extends Model { + static get tableName() { + return 'animal_movement_task_animal_batch_relationship'; + } + + static get idColumn() { + return ['task_id', 'animal_batch_id']; + } + + // Optional JSON schema. This is not the database schema! Nothing is generated + // based on this. This is only used for validation. Whenever a model instance + // is created it is checked against this schema. http://json-schema.org/. + static get jsonSchema() { + return { + type: 'object', + required: ['task_id', 'animal_batch_id'], + properties: { + task_id: { type: 'integer' }, + animal_batch_id: { type: 'integer' }, + }, + additionalProperties: false, + }; + } + + static get relationMappings() { + return { + task: { + relation: Model.BelongsToOneRelation, + modelClass: TaskModel, + join: { + from: 'animal_movement_task_animal_batch_relationship.task_id', + to: 'task.task_id', + }, + }, + animal_batch: { + relation: Model.BelongsToOneRelation, + modelClass: AnimalBatchModel, + join: { + from: 'animal_movement_task_animal_batch_relationship.animal_batch_id', + to: 'animal_batch.id', + }, + }, + }; + } +} + +export default AnimalMovementTaskAnimalBatchRelationshipModel; From c81484622072cf111880e8f01cdbc46ce9576a24 Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Tue, 22 Oct 2024 12:23:52 -0700 Subject: [PATCH 02/14] LF-4471 Create new models for animal movement task --- .../src/models/animalMovementPurposeModel.js | 56 ++++++++++ ...imalMovementTaskAnimalRelationshipModel.js | 66 +++++++++++ .../api/src/models/animalMovementTaskModel.js | 103 ++++++++++++++++++ ...malMovementTaskPurposeRelationshipModel.js | 67 ++++++++++++ 4 files changed, 292 insertions(+) create mode 100644 packages/api/src/models/animalMovementPurposeModel.js create mode 100644 packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js create mode 100644 packages/api/src/models/animalMovementTaskModel.js create mode 100644 packages/api/src/models/animalMovementTaskPurposeRelationshipModel.js diff --git a/packages/api/src/models/animalMovementPurposeModel.js b/packages/api/src/models/animalMovementPurposeModel.js new file mode 100644 index 0000000000..373a10f8dd --- /dev/null +++ b/packages/api/src/models/animalMovementPurposeModel.js @@ -0,0 +1,56 @@ +/* + * Copyright 2024 LiteFarm.org + * This file is part of LiteFarm. + * + * LiteFarm is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LiteFarm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details, see . + */ +import Model from './baseFormatModel.js'; +import AnimalMovementTaskPurposeRelationship from './animalMovementTaskPurposeRelationshipModel.js'; + +class AnimalMovementPurpose extends Model { + static get tableName() { + return 'animal_movement_purpose'; + } + + static get idColumn() { + return 'id'; + } + + // Optional JSON schema. This is not the database schema! Nothing is generated + // based on this. This is only used for validation. Whenever a model instance + // is created it is checked against this schema. http://json-schema.org/. + static get jsonSchema() { + return { + type: 'object', + required: ['key'], + properties: { + id: { type: 'integer' }, + key: { type: 'string' }, + }, + additionalProperties: false, + }; + } + + static get relationMappings() { + return { + animal_movement_task_purpose_relationships: { + relation: Model.HasManyRelation, + modelClass: AnimalMovementTaskPurposeRelationship, + join: { + from: 'animal_movement_purpose.id', + to: 'animal_movement_task_purpose_relationship.purpose_id', + }, + }, + }; + } +} + +export default AnimalMovementPurpose; diff --git a/packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js b/packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js new file mode 100644 index 0000000000..4e3ba0f8d0 --- /dev/null +++ b/packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js @@ -0,0 +1,66 @@ +/* + * Copyright 2024 LiteFarm.org + * This file is part of LiteFarm. + * + * LiteFarm is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LiteFarm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details, see . + */ + +import Model from './baseFormatModel.js'; +import TaskModel from '../models/taskModel.js'; +import AnimalModel from '../models/animalModel.js'; + +class AnimalMovementTaskAnimalRelationshipModel extends Model { + static get tableName() { + return 'animal_movement_task_animal_relationship'; + } + + static get idColumn() { + return ['task_id', 'animal_id']; + } + + // Optional JSON schema. This is not the database schema! Nothing is generated + // based on this. This is only used for validation. Whenever a model instance + // is created it is checked against this schema. http://json-schema.org/. + static get jsonSchema() { + return { + type: 'object', + required: ['task_id', 'animal_id'], + properties: { + task_id: { type: 'integer' }, + animal_id: { type: 'integer' }, + }, + additionalProperties: false, + }; + } + + static get relationMappings() { + return { + task: { + relation: Model.BelongsToOneRelation, + modelClass: TaskModel, + join: { + from: 'animal_movement_task_animal_relationship.task_id', + to: 'task.task_id', + }, + }, + animal: { + relation: Model.BelongsToOneRelation, + modelClass: AnimalModel, + join: { + from: 'animal_movement_task_animal_relationship.animal_id', + to: 'animal.id', + }, + }, + }; + } +} + +export default AnimalMovementTaskAnimalRelationshipModel; diff --git a/packages/api/src/models/animalMovementTaskModel.js b/packages/api/src/models/animalMovementTaskModel.js new file mode 100644 index 0000000000..b090159cd2 --- /dev/null +++ b/packages/api/src/models/animalMovementTaskModel.js @@ -0,0 +1,103 @@ +/* + * Copyright 2024 LiteFarm.org + * This file is part of LiteFarm. + * + * LiteFarm is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LiteFarm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details, see . + */ + +import Model from './baseFormatModel.js'; +import baseModel from './baseModel.js'; +import TaskModel from './taskModel.js'; +import AnimalModel from './animalModel.js'; +import AnimalBatchModel from './animalBatchModel.js'; +import AnimalMovementPurposeModel from './animalMovementPurposeModel.js'; +import AnimalMovementTaskPurposeRelationshipModel from './animalMovementTaskPurposeRelationshipModel.js'; +import AnimalMovementTaskAnimalRelationshipModel from './animalMovementTaskAnimalRelationshipModel.js'; +import AnimalMovementTaskAnimalBatchRelationshipModel from './animalMovementTaskAnimalBatchRelationshipModel.js'; + +class AnimalMovementTask extends baseModel { + static get tableName() { + return 'animal_movement_task'; + } + + static get idColumn() { + return 'task_id'; + } + + // Optional JSON schema. This is not the database schema! Nothing is generated + // based on this. This is only used for validation. Whenever a model instance + // is created it is checked against this schema. http://json-schema.org/. + static get jsonSchema() { + return { + type: 'object', + required: [], + properties: { + task_id: { type: 'integer' }, + }, + additionalProperties: false, + }; + } + + static get relationMappings() { + return { + task: { + relation: Model.BelongsToOneRelation, + modelClass: TaskModel, + join: { + from: 'animal_movement_task.task_id', + to: 'task.task_id', + }, + }, + animals: { + relation: Model.ManyToManyRelation, + modelClass: AnimalModel, + join: { + from: 'animal_movement_task.task_id', + through: { + modelClass: AnimalMovementTaskAnimalRelationshipModel, + from: 'animal_movement_task_animal_relationship.task_id', + to: 'animal_movement_task_animal_relationship.animal_id', + }, + to: 'animal.id', + }, + }, + animal_batches: { + relation: Model.ManyToManyRelation, + modelClass: AnimalBatchModel, + join: { + from: 'animal_movement_task.task_id', + through: { + modelClass: AnimalMovementTaskAnimalBatchRelationshipModel, + from: 'animal_movement_task_animal_batch_relationship.task_id', + to: 'animal_movement_task_animal_batch_relationship.animal_batch_id', + }, + to: 'animal_batch.id', + }, + }, + purposes: { + relation: Model.ManyToManyRelation, + modelClass: AnimalMovementPurposeModel, + join: { + from: 'animal_movement_task.task_id', + through: { + modelClass: AnimalMovementTaskPurposeRelationshipModel, + from: 'animal_movement_task_purpose_relationship.task_id', + to: 'animal_movement_task_purpose_relationship.purpose_id', + extra: ['other_purpose'], + }, + to: 'animal_movement_purpose.id', + }, + }, + }; + } +} + +export default AnimalMovementTask; diff --git a/packages/api/src/models/animalMovementTaskPurposeRelationshipModel.js b/packages/api/src/models/animalMovementTaskPurposeRelationshipModel.js new file mode 100644 index 0000000000..808df2d2c5 --- /dev/null +++ b/packages/api/src/models/animalMovementTaskPurposeRelationshipModel.js @@ -0,0 +1,67 @@ +/* + * Copyright 2024 LiteFarm.org + * This file is part of LiteFarm. + * + * LiteFarm is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LiteFarm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details, see . + */ + +import Model from './baseFormatModel.js'; +import TaskModel from './taskModel.js'; +import AnimalMovementPurposeModel from './animalMovementPurposeModel.js'; + +class AnimalMovementTaskPurposeRelationship extends Model { + static get tableName() { + return 'animal_movement_task_purpose_relationship'; + } + + static get idColumn() { + return ['task_id', 'purpose_id']; + } + + // Optional JSON schema. This is not the database schema! Nothing is generated + // based on this. This is only used for validation. Whenever a model instance + // is created it is checked against this schema. http://json-schema.org/. + static get jsonSchema() { + return { + type: 'object', + required: ['task_id', 'purpose_id'], + properties: { + task_id: { type: 'integer' }, + purpose_id: { type: 'integer' }, + other_purpose: { type: ['string', 'null'], minLength: 1, maxLength: 255 }, + }, + additionalProperties: false, + }; + } + + static get relationMappings() { + return { + task: { + relation: Model.BelongsToOneRelation, + modelClass: TaskModel, + join: { + from: 'animal_movement_task_purpose_relationship.task_id', + to: 'task.task_id', + }, + }, + purpose: { + relation: Model.BelongsToOneRelation, + modelClass: AnimalMovementPurposeModel, + join: { + from: 'animal_movement_task_purpose_relationship.purpose_id', + to: 'animal_movement_purpose.id', + }, + }, + }; + } +} + +export default AnimalMovementTaskPurposeRelationship; From 7d3f0106978a105570c3ac274db17eb723a5dad8 Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Tue, 22 Oct 2024 12:33:28 -0700 Subject: [PATCH 03/14] LF-4471 Update Animal and Batch models * add location_id * add relation to animal_movement_tasks --- packages/api/src/models/animalBatchModel.js | 16 ++++++++++++++++ packages/api/src/models/animalModel.js | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/packages/api/src/models/animalBatchModel.js b/packages/api/src/models/animalBatchModel.js index d0df0aa19d..03af2d3916 100644 --- a/packages/api/src/models/animalBatchModel.js +++ b/packages/api/src/models/animalBatchModel.js @@ -20,6 +20,8 @@ import AnimalBatchGroupRelationshipModel from './animalBatchGroupRelationshipMod import AnimalUnionBatchIdViewModel from './animalUnionBatchIdViewModel.js'; import { checkAndTrimString } from '../util/util.js'; import AnimalBatchUseRelationshipModel from './animalBatchUseRelationshipModel.js'; +import AnimalMovementTaskModel from './animalMovementTaskModel.js'; +import AnimalMovementTaskAnimalBatchRelationshipModel from './animalMovementTaskAnimalBatchRelationshipModel.js'; class AnimalBatchModel extends baseModel { static get tableName() { @@ -95,6 +97,7 @@ class AnimalBatchModel extends baseModel { sire: { type: ['string', 'null'] }, supplier: { type: ['string', 'null'], maxLength: 255 }, price: { type: ['number', 'null'] }, + location_id: { type: ['string', 'null'] }, ...this.baseProperties, }, additionalProperties: false, @@ -141,6 +144,19 @@ class AnimalBatchModel extends baseModel { to: 'animal_batch_use_relationship.animal_batch_id', }, }, + animal_movement_tasks: { + modelClass: AnimalMovementTaskModel, + relation: Model.ManyToManyRelation, + join: { + from: 'animal_batch.id', + through: { + modelClass: AnimalMovementTaskAnimalBatchRelationshipModel, + from: 'animal_movement_task_animal_batch_relationship.animal_batch_id', + to: 'animal_movement_task_animal_batch_relationship.task_id', + }, + to: 'animal_movement_task.task_id', + }, + }, }; } } diff --git a/packages/api/src/models/animalModel.js b/packages/api/src/models/animalModel.js index f0958282ea..f04a6891f5 100644 --- a/packages/api/src/models/animalModel.js +++ b/packages/api/src/models/animalModel.js @@ -19,6 +19,8 @@ import AnimalGroupRelationshipModel from './animalGroupRelationshipModel.js'; import Model from './baseFormatModel.js'; import { checkAndTrimString } from '../util/util.js'; import AnimalUseRelationshipModel from './animalUseRelationshipModel.js'; +import AnimalMovementTaskModel from './animalMovementTaskModel.js'; +import AnimalMovementTaskAnimalRelationshipModel from './animalMovementTaskAnimalRelationshipModel.js'; class Animal extends baseModel { static get tableName() { @@ -99,6 +101,7 @@ class Animal extends baseModel { organic_status: { type: 'string', enum: ['Non-Organic', 'Transitional', 'Organic'] }, supplier: { type: ['string', 'null'], maxLength: 255 }, price: { type: ['number', 'null'] }, + location_id: { type: ['string', 'null'] }, ...this.baseProperties, }, additionalProperties: false, @@ -136,6 +139,19 @@ class Animal extends baseModel { to: 'animal_use_relationship.animal_id', }, }, + animal_movement_tasks: { + modelClass: AnimalMovementTaskModel, + relation: Model.ManyToManyRelation, + join: { + from: 'animal.id', + through: { + modelClass: AnimalMovementTaskAnimalRelationshipModel, + from: 'animal_movement_task_animal_relationship.animal_id', + to: 'animal_movement_task_animal_relationship.task_id', + }, + to: 'animal_movement_task.task_id', + }, + }, }; } } From eef949847d1d9bac4147551dfc27cde9e3dad08b Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Tue, 22 Oct 2024 12:35:38 -0700 Subject: [PATCH 04/14] LF-4471 Updaate taskModel to add relation to animal_movement_task --- packages/api/src/models/taskModel.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/api/src/models/taskModel.js b/packages/api/src/models/taskModel.js index 338ab61325..9b281bcb38 100644 --- a/packages/api/src/models/taskModel.js +++ b/packages/api/src/models/taskModel.js @@ -28,6 +28,7 @@ import cleaningTaskModel from './cleaningTaskModel.js'; import taskTypeModel from './taskTypeModel.js'; import plantTaskModel from './plantTaskModel.js'; import transplantTaskModel from './transplantTaskModel.js'; +import animalMovementTaskModel from './animalMovementTaskModel.js'; import plantingManagementPlanModel from './plantingManagementPlanModel.js'; import managementTasksModel from './managementTasksModel.js'; import locationModel from './locationModel.js'; @@ -189,6 +190,14 @@ class TaskModel extends BaseModel { to: 'transplant_task.task_id', }, }, + animal_movement_task: { + relation: Model.HasOneRelation, + modelClass: animalMovementTaskModel, + join: { + from: 'task.task_id', + to: 'animal_movement_task.task_id', + }, + }, //TODO: rename to plantingManagementPlans managementPlans: { modelClass: plantingManagementPlanModel, @@ -266,6 +275,7 @@ class TaskModel extends BaseModel { taskType: 'omit', plant_task: 'edit', transplant_task: 'edit', + animal_movement_task: 'omit', managementPlans: 'omit', locations: 'edit', }; From a6580d2934700a633a55cc2ef2fd97ec7246b48a Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Tue, 22 Oct 2024 12:41:37 -0700 Subject: [PATCH 05/14] LF-4471 Update taskController's getTasksByFarmId to include animal movement tasks --- packages/api/src/controllers/taskController.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/api/src/controllers/taskController.js b/packages/api/src/controllers/taskController.js index 0dc257a85e..704f664249 100644 --- a/packages/api/src/controllers/taskController.js +++ b/packages/api/src/controllers/taskController.js @@ -713,7 +713,20 @@ const taskController = { const graphTasks = await TaskModel.query() .whereNotDeleted() .withGraphFetched( - `[locations.[location_defaults], managementPlans, soil_amendment_task, soil_amendment_task_products(filterDeleted).[purpose_relationships], field_work_task.[field_work_task_type], cleaning_task, pest_control_task, harvest_task.[harvest_use], plant_task, transplant_task, irrigation_task.[irrigation_type]] + `[${[ + 'locations.[location_defaults]', + 'managementPlans', + 'soil_amendment_task', + 'soil_amendment_task_products(filterDeleted).[purpose_relationships]', + 'field_work_task.[field_work_task_type]', + 'cleaning_task', + 'pest_control_task', + 'harvest_task.[harvest_use]', + 'plant_task', + 'transplant_task', + 'irrigation_task.[irrigation_type]', + 'animal_movement_task.[purposes, animals, animal_batches]', + ].join(', ')}] `, ) .whereIn('task_id', taskIds); From f2886c92e7bf3d11a26dfdb088be16b18a5c3c14 Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Thu, 31 Oct 2024 10:04:55 -0700 Subject: [PATCH 06/14] LF-4471 Update movement task and animal&batch models to - extend baseModel - add base properties --- .../models/animalMovementTaskAnimalBatchRelationshipModel.js | 4 +++- .../src/models/animalMovementTaskAnimalRelationshipModel.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js b/packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js index e9762e85b7..2481f11ff4 100644 --- a/packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js +++ b/packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js @@ -14,10 +14,11 @@ */ import Model from './baseFormatModel.js'; +import baseModel from './baseModel.js'; import TaskModel from '../models/taskModel.js'; import AnimalBatchModel from '../models/animalBatchModel.js'; -class AnimalMovementTaskAnimalBatchRelationshipModel extends Model { +class AnimalMovementTaskAnimalBatchRelationshipModel extends baseModel { static get tableName() { return 'animal_movement_task_animal_batch_relationship'; } @@ -36,6 +37,7 @@ class AnimalMovementTaskAnimalBatchRelationshipModel extends Model { properties: { task_id: { type: 'integer' }, animal_batch_id: { type: 'integer' }, + ...this.baseProperties, }, additionalProperties: false, }; diff --git a/packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js b/packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js index 4e3ba0f8d0..66ec362298 100644 --- a/packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js +++ b/packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js @@ -14,10 +14,11 @@ */ import Model from './baseFormatModel.js'; +import baseModel from './baseModel.js'; import TaskModel from '../models/taskModel.js'; import AnimalModel from '../models/animalModel.js'; -class AnimalMovementTaskAnimalRelationshipModel extends Model { +class AnimalMovementTaskAnimalRelationshipModel extends baseModel { static get tableName() { return 'animal_movement_task_animal_relationship'; } @@ -36,6 +37,7 @@ class AnimalMovementTaskAnimalRelationshipModel extends Model { properties: { task_id: { type: 'integer' }, animal_id: { type: 'integer' }, + ...this.baseProperties, }, additionalProperties: false, }; From a8594a3373a47b8d24848bc963003fcae42faabc Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Fri, 1 Nov 2024 14:57:13 -0700 Subject: [PATCH 07/14] LF-4471 Fix AnimalMovementTask model to extend Model --- packages/api/src/models/animalMovementTaskModel.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/api/src/models/animalMovementTaskModel.js b/packages/api/src/models/animalMovementTaskModel.js index b090159cd2..fe1fd44ee5 100644 --- a/packages/api/src/models/animalMovementTaskModel.js +++ b/packages/api/src/models/animalMovementTaskModel.js @@ -14,7 +14,6 @@ */ import Model from './baseFormatModel.js'; -import baseModel from './baseModel.js'; import TaskModel from './taskModel.js'; import AnimalModel from './animalModel.js'; import AnimalBatchModel from './animalBatchModel.js'; @@ -23,7 +22,7 @@ import AnimalMovementTaskPurposeRelationshipModel from './animalMovementTaskPurp import AnimalMovementTaskAnimalRelationshipModel from './animalMovementTaskAnimalRelationshipModel.js'; import AnimalMovementTaskAnimalBatchRelationshipModel from './animalMovementTaskAnimalBatchRelationshipModel.js'; -class AnimalMovementTask extends baseModel { +class AnimalMovementTask extends Model { static get tableName() { return 'animal_movement_task'; } From 155f28a902c1480a7d079ec2549e621dc0409d74 Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Mon, 4 Nov 2024 11:03:11 -0800 Subject: [PATCH 08/14] Revert "LF-4471 Update movement task and animal&batch models to" This reverts commit f2886c92e7bf3d11a26dfdb088be16b18a5c3c14. --- .../models/animalMovementTaskAnimalBatchRelationshipModel.js | 4 +--- .../src/models/animalMovementTaskAnimalRelationshipModel.js | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js b/packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js index 2481f11ff4..e9762e85b7 100644 --- a/packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js +++ b/packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js @@ -14,11 +14,10 @@ */ import Model from './baseFormatModel.js'; -import baseModel from './baseModel.js'; import TaskModel from '../models/taskModel.js'; import AnimalBatchModel from '../models/animalBatchModel.js'; -class AnimalMovementTaskAnimalBatchRelationshipModel extends baseModel { +class AnimalMovementTaskAnimalBatchRelationshipModel extends Model { static get tableName() { return 'animal_movement_task_animal_batch_relationship'; } @@ -37,7 +36,6 @@ class AnimalMovementTaskAnimalBatchRelationshipModel extends baseModel { properties: { task_id: { type: 'integer' }, animal_batch_id: { type: 'integer' }, - ...this.baseProperties, }, additionalProperties: false, }; diff --git a/packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js b/packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js index 66ec362298..4e3ba0f8d0 100644 --- a/packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js +++ b/packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js @@ -14,11 +14,10 @@ */ import Model from './baseFormatModel.js'; -import baseModel from './baseModel.js'; import TaskModel from '../models/taskModel.js'; import AnimalModel from '../models/animalModel.js'; -class AnimalMovementTaskAnimalRelationshipModel extends baseModel { +class AnimalMovementTaskAnimalRelationshipModel extends Model { static get tableName() { return 'animal_movement_task_animal_relationship'; } @@ -37,7 +36,6 @@ class AnimalMovementTaskAnimalRelationshipModel extends baseModel { properties: { task_id: { type: 'integer' }, animal_id: { type: 'integer' }, - ...this.baseProperties, }, additionalProperties: false, }; From a96a6258e4c9d2b9f8521f40c8db7addbfb1d9ae Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Mon, 4 Nov 2024 12:17:55 -0800 Subject: [PATCH 09/14] LF-4471 Reflect table name changes on task animal relationship --- .../api/src/controllers/taskController.js | 31 ++++++++++--------- packages/api/src/models/animalBatchModel.js | 16 +++++----- packages/api/src/models/animalModel.js | 16 +++++----- .../api/src/models/animalMovementTaskModel.js | 30 ------------------ ...js => taskAnimalBatchRelationshipModel.js} | 14 ++++----- ...odel.js => taskAnimalRelationshipModel.js} | 14 ++++----- packages/api/src/models/taskModel.js | 30 ++++++++++++++++++ 7 files changed, 76 insertions(+), 75 deletions(-) rename packages/api/src/models/{animalMovementTaskAnimalBatchRelationshipModel.js => taskAnimalBatchRelationshipModel.js} (78%) rename packages/api/src/models/{animalMovementTaskAnimalRelationshipModel.js => taskAnimalRelationshipModel.js} (79%) diff --git a/packages/api/src/controllers/taskController.js b/packages/api/src/controllers/taskController.js index 704f664249..68dd2a4e1f 100644 --- a/packages/api/src/controllers/taskController.js +++ b/packages/api/src/controllers/taskController.js @@ -713,21 +713,22 @@ const taskController = { const graphTasks = await TaskModel.query() .whereNotDeleted() .withGraphFetched( - `[${[ - 'locations.[location_defaults]', - 'managementPlans', - 'soil_amendment_task', - 'soil_amendment_task_products(filterDeleted).[purpose_relationships]', - 'field_work_task.[field_work_task_type]', - 'cleaning_task', - 'pest_control_task', - 'harvest_task.[harvest_use]', - 'plant_task', - 'transplant_task', - 'irrigation_task.[irrigation_type]', - 'animal_movement_task.[purposes, animals, animal_batches]', - ].join(', ')}] - `, + `[ + locations.[location_defaults], + managementPlans, + animals, + animal_batches, + soil_amendment_task, + soil_amendment_task_products(filterDeleted).[purpose_relationships], + field_work_task.[field_work_task_type], + cleaning_task, + pest_control_task, + harvest_task.[harvest_use], + plant_task, + transplant_task, + irrigation_task.[irrigation_type], + animal_movement_task.[purposes], + ]`, ) .whereIn('task_id', taskIds); const filteredTasks = graphTasks.map(removeNullTypes); diff --git a/packages/api/src/models/animalBatchModel.js b/packages/api/src/models/animalBatchModel.js index 03af2d3916..83f216aa3c 100644 --- a/packages/api/src/models/animalBatchModel.js +++ b/packages/api/src/models/animalBatchModel.js @@ -20,8 +20,8 @@ import AnimalBatchGroupRelationshipModel from './animalBatchGroupRelationshipMod import AnimalUnionBatchIdViewModel from './animalUnionBatchIdViewModel.js'; import { checkAndTrimString } from '../util/util.js'; import AnimalBatchUseRelationshipModel from './animalBatchUseRelationshipModel.js'; -import AnimalMovementTaskModel from './animalMovementTaskModel.js'; -import AnimalMovementTaskAnimalBatchRelationshipModel from './animalMovementTaskAnimalBatchRelationshipModel.js'; +import TaskAnimalBatchRelationshipModel from './taskAnimalBatchRelationshipModel.js'; +import TaskModel from './taskModel.js'; class AnimalBatchModel extends baseModel { static get tableName() { @@ -144,17 +144,17 @@ class AnimalBatchModel extends baseModel { to: 'animal_batch_use_relationship.animal_batch_id', }, }, - animal_movement_tasks: { - modelClass: AnimalMovementTaskModel, + tasks: { + modelClass: TaskModel, relation: Model.ManyToManyRelation, join: { from: 'animal_batch.id', through: { - modelClass: AnimalMovementTaskAnimalBatchRelationshipModel, - from: 'animal_movement_task_animal_batch_relationship.animal_batch_id', - to: 'animal_movement_task_animal_batch_relationship.task_id', + modelClass: TaskAnimalBatchRelationshipModel, + from: 'task_animal_batch_relationship.animal_batch_id', + to: 'task_animal_batch_relationship.task_id', }, - to: 'animal_movement_task.task_id', + to: 'task.task_id', }, }, }; diff --git a/packages/api/src/models/animalModel.js b/packages/api/src/models/animalModel.js index f04a6891f5..99a4877f7c 100644 --- a/packages/api/src/models/animalModel.js +++ b/packages/api/src/models/animalModel.js @@ -19,8 +19,8 @@ import AnimalGroupRelationshipModel from './animalGroupRelationshipModel.js'; import Model from './baseFormatModel.js'; import { checkAndTrimString } from '../util/util.js'; import AnimalUseRelationshipModel from './animalUseRelationshipModel.js'; -import AnimalMovementTaskModel from './animalMovementTaskModel.js'; -import AnimalMovementTaskAnimalRelationshipModel from './animalMovementTaskAnimalRelationshipModel.js'; +import TaskModel from './taskModel.js'; +import TaskAnimalRelationshipModel from './taskAnimalRelationshipModel.js'; class Animal extends baseModel { static get tableName() { @@ -139,17 +139,17 @@ class Animal extends baseModel { to: 'animal_use_relationship.animal_id', }, }, - animal_movement_tasks: { - modelClass: AnimalMovementTaskModel, + tasks: { + modelClass: TaskModel, relation: Model.ManyToManyRelation, join: { from: 'animal.id', through: { - modelClass: AnimalMovementTaskAnimalRelationshipModel, - from: 'animal_movement_task_animal_relationship.animal_id', - to: 'animal_movement_task_animal_relationship.task_id', + modelClass: TaskAnimalRelationshipModel, + from: 'task_animal_relationship.animal_id', + to: 'task_animal_relationship.task_id', }, - to: 'animal_movement_task.task_id', + to: 'task.task_id', }, }, }; diff --git a/packages/api/src/models/animalMovementTaskModel.js b/packages/api/src/models/animalMovementTaskModel.js index fe1fd44ee5..4281588840 100644 --- a/packages/api/src/models/animalMovementTaskModel.js +++ b/packages/api/src/models/animalMovementTaskModel.js @@ -15,12 +15,8 @@ import Model from './baseFormatModel.js'; import TaskModel from './taskModel.js'; -import AnimalModel from './animalModel.js'; -import AnimalBatchModel from './animalBatchModel.js'; import AnimalMovementPurposeModel from './animalMovementPurposeModel.js'; import AnimalMovementTaskPurposeRelationshipModel from './animalMovementTaskPurposeRelationshipModel.js'; -import AnimalMovementTaskAnimalRelationshipModel from './animalMovementTaskAnimalRelationshipModel.js'; -import AnimalMovementTaskAnimalBatchRelationshipModel from './animalMovementTaskAnimalBatchRelationshipModel.js'; class AnimalMovementTask extends Model { static get tableName() { @@ -55,32 +51,6 @@ class AnimalMovementTask extends Model { to: 'task.task_id', }, }, - animals: { - relation: Model.ManyToManyRelation, - modelClass: AnimalModel, - join: { - from: 'animal_movement_task.task_id', - through: { - modelClass: AnimalMovementTaskAnimalRelationshipModel, - from: 'animal_movement_task_animal_relationship.task_id', - to: 'animal_movement_task_animal_relationship.animal_id', - }, - to: 'animal.id', - }, - }, - animal_batches: { - relation: Model.ManyToManyRelation, - modelClass: AnimalBatchModel, - join: { - from: 'animal_movement_task.task_id', - through: { - modelClass: AnimalMovementTaskAnimalBatchRelationshipModel, - from: 'animal_movement_task_animal_batch_relationship.task_id', - to: 'animal_movement_task_animal_batch_relationship.animal_batch_id', - }, - to: 'animal_batch.id', - }, - }, purposes: { relation: Model.ManyToManyRelation, modelClass: AnimalMovementPurposeModel, diff --git a/packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js b/packages/api/src/models/taskAnimalBatchRelationshipModel.js similarity index 78% rename from packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js rename to packages/api/src/models/taskAnimalBatchRelationshipModel.js index e9762e85b7..b1b12ce992 100644 --- a/packages/api/src/models/animalMovementTaskAnimalBatchRelationshipModel.js +++ b/packages/api/src/models/taskAnimalBatchRelationshipModel.js @@ -14,12 +14,12 @@ */ import Model from './baseFormatModel.js'; -import TaskModel from '../models/taskModel.js'; -import AnimalBatchModel from '../models/animalBatchModel.js'; +import TaskModel from './taskModel.js'; +import AnimalBatchModel from './animalBatchModel.js'; -class AnimalMovementTaskAnimalBatchRelationshipModel extends Model { +class TaskAnimalBatchRelationshipModel extends Model { static get tableName() { - return 'animal_movement_task_animal_batch_relationship'; + return 'task_animal_batch_relationship'; } static get idColumn() { @@ -47,7 +47,7 @@ class AnimalMovementTaskAnimalBatchRelationshipModel extends Model { relation: Model.BelongsToOneRelation, modelClass: TaskModel, join: { - from: 'animal_movement_task_animal_batch_relationship.task_id', + from: 'task_animal_batch_relationship.task_id', to: 'task.task_id', }, }, @@ -55,7 +55,7 @@ class AnimalMovementTaskAnimalBatchRelationshipModel extends Model { relation: Model.BelongsToOneRelation, modelClass: AnimalBatchModel, join: { - from: 'animal_movement_task_animal_batch_relationship.animal_batch_id', + from: 'task_animal_batch_relationship.animal_batch_id', to: 'animal_batch.id', }, }, @@ -63,4 +63,4 @@ class AnimalMovementTaskAnimalBatchRelationshipModel extends Model { } } -export default AnimalMovementTaskAnimalBatchRelationshipModel; +export default TaskAnimalBatchRelationshipModel; diff --git a/packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js b/packages/api/src/models/taskAnimalRelationshipModel.js similarity index 79% rename from packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js rename to packages/api/src/models/taskAnimalRelationshipModel.js index 4e3ba0f8d0..b3098f3d7a 100644 --- a/packages/api/src/models/animalMovementTaskAnimalRelationshipModel.js +++ b/packages/api/src/models/taskAnimalRelationshipModel.js @@ -14,12 +14,12 @@ */ import Model from './baseFormatModel.js'; -import TaskModel from '../models/taskModel.js'; -import AnimalModel from '../models/animalModel.js'; +import TaskModel from './taskModel.js'; +import AnimalModel from './animalModel.js'; -class AnimalMovementTaskAnimalRelationshipModel extends Model { +class TaskAnimalRelationshipModel extends Model { static get tableName() { - return 'animal_movement_task_animal_relationship'; + return 'task_animal_relationship'; } static get idColumn() { @@ -47,7 +47,7 @@ class AnimalMovementTaskAnimalRelationshipModel extends Model { relation: Model.BelongsToOneRelation, modelClass: TaskModel, join: { - from: 'animal_movement_task_animal_relationship.task_id', + from: 'task_animal_relationship.task_id', to: 'task.task_id', }, }, @@ -55,7 +55,7 @@ class AnimalMovementTaskAnimalRelationshipModel extends Model { relation: Model.BelongsToOneRelation, modelClass: AnimalModel, join: { - from: 'animal_movement_task_animal_relationship.animal_id', + from: 'task_animal_relationship.animal_id', to: 'animal.id', }, }, @@ -63,4 +63,4 @@ class AnimalMovementTaskAnimalRelationshipModel extends Model { } } -export default AnimalMovementTaskAnimalRelationshipModel; +export default TaskAnimalRelationshipModel; diff --git a/packages/api/src/models/taskModel.js b/packages/api/src/models/taskModel.js index 9b281bcb38..00c8bcabf6 100644 --- a/packages/api/src/models/taskModel.js +++ b/packages/api/src/models/taskModel.js @@ -33,6 +33,10 @@ import plantingManagementPlanModel from './plantingManagementPlanModel.js'; import managementTasksModel from './managementTasksModel.js'; import locationModel from './locationModel.js'; import locationTasksModel from './locationTasksModel.js'; +import AnimalModel from './animalModel.js'; +import AnimalBatchModel from './animalBatchModel.js'; +import TaskAnimalRelationshipModel from './taskAnimalRelationshipModel.js'; +import TaskAnimalBatchRelationshipModel from './taskAnimalBatchRelationshipModel.js'; class TaskModel extends BaseModel { static get tableName() { @@ -233,6 +237,32 @@ class TaskModel extends BaseModel { to: 'location_tasks.task_id', }, }, + animals: { + relation: Model.ManyToManyRelation, + modelClass: AnimalModel, + join: { + from: 'task.task_id', + through: { + modelClass: TaskAnimalRelationshipModel, + from: 'task_animal_relationship.task_id', + to: 'task_animal_relationship.animal_id', + }, + to: 'animal.id', + }, + }, + animal_batches: { + relation: Model.ManyToManyRelation, + modelClass: AnimalBatchModel, + join: { + from: 'task.task_id', + through: { + modelClass: TaskAnimalBatchRelationshipModel, + from: 'task_animal_batch_relationship.task_id', + to: 'task_animal_batch_relationship.animal_batch_id', + }, + to: 'animal_batch.id', + }, + }, }; } From bdae2ea56a23af48a56142ee36a17700d6447b51 Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Tue, 5 Nov 2024 08:57:25 -0800 Subject: [PATCH 10/14] LF-4471 Remove unused relationMappings --- .../api/src/models/animalMovementPurposeModel.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/packages/api/src/models/animalMovementPurposeModel.js b/packages/api/src/models/animalMovementPurposeModel.js index 373a10f8dd..cb190a99d8 100644 --- a/packages/api/src/models/animalMovementPurposeModel.js +++ b/packages/api/src/models/animalMovementPurposeModel.js @@ -13,7 +13,6 @@ * GNU General Public License for more details, see . */ import Model from './baseFormatModel.js'; -import AnimalMovementTaskPurposeRelationship from './animalMovementTaskPurposeRelationshipModel.js'; class AnimalMovementPurpose extends Model { static get tableName() { @@ -38,19 +37,6 @@ class AnimalMovementPurpose extends Model { additionalProperties: false, }; } - - static get relationMappings() { - return { - animal_movement_task_purpose_relationships: { - relation: Model.HasManyRelation, - modelClass: AnimalMovementTaskPurposeRelationship, - join: { - from: 'animal_movement_purpose.id', - to: 'animal_movement_task_purpose_relationship.purpose_id', - }, - }, - }; - } } export default AnimalMovementPurpose; From 36578860a49d203fa4c31d1a3eb1c170c1f30cf4 Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Tue, 5 Nov 2024 09:39:50 -0800 Subject: [PATCH 11/14] LF-4471 Change movement task's relationship with purposes --- packages/api/src/controllers/taskController.js | 2 +- .../api/src/models/animalMovementTaskModel.js | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/packages/api/src/controllers/taskController.js b/packages/api/src/controllers/taskController.js index 68dd2a4e1f..8298c63b75 100644 --- a/packages/api/src/controllers/taskController.js +++ b/packages/api/src/controllers/taskController.js @@ -727,7 +727,7 @@ const taskController = { plant_task, transplant_task, irrigation_task.[irrigation_type], - animal_movement_task.[purposes], + animal_movement_task.[purpose_relationships], ]`, ) .whereIn('task_id', taskIds); diff --git a/packages/api/src/models/animalMovementTaskModel.js b/packages/api/src/models/animalMovementTaskModel.js index 4281588840..31dead8970 100644 --- a/packages/api/src/models/animalMovementTaskModel.js +++ b/packages/api/src/models/animalMovementTaskModel.js @@ -15,7 +15,6 @@ import Model from './baseFormatModel.js'; import TaskModel from './taskModel.js'; -import AnimalMovementPurposeModel from './animalMovementPurposeModel.js'; import AnimalMovementTaskPurposeRelationshipModel from './animalMovementTaskPurposeRelationshipModel.js'; class AnimalMovementTask extends Model { @@ -51,18 +50,12 @@ class AnimalMovementTask extends Model { to: 'task.task_id', }, }, - purposes: { - relation: Model.ManyToManyRelation, - modelClass: AnimalMovementPurposeModel, + purpose_relationships: { + relation: Model.HasManyRelation, + modelClass: AnimalMovementTaskPurposeRelationshipModel, join: { from: 'animal_movement_task.task_id', - through: { - modelClass: AnimalMovementTaskPurposeRelationshipModel, - from: 'animal_movement_task_purpose_relationship.task_id', - to: 'animal_movement_task_purpose_relationship.purpose_id', - extra: ['other_purpose'], - }, - to: 'animal_movement_purpose.id', + to: 'animal_movement_task_purpose_relationship.task_id', }, }, }; From 68148d6c8a651bbd699765920a6960e6ad22c1f2 Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Tue, 5 Nov 2024 14:13:38 -0800 Subject: [PATCH 12/14] LF-4471 Update templateMappingSchema in Task model to handle animal and batch --- packages/api/src/models/taskModel.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/api/src/models/taskModel.js b/packages/api/src/models/taskModel.js index 00c8bcabf6..8c66a1543a 100644 --- a/packages/api/src/models/taskModel.js +++ b/packages/api/src/models/taskModel.js @@ -308,6 +308,8 @@ class TaskModel extends BaseModel { animal_movement_task: 'omit', managementPlans: 'omit', locations: 'edit', + animals: 'omit', + animal_batches: 'omit', }; } From 7929bab072c09fe71b04bfe99f518f5ff705cf26 Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Tue, 5 Nov 2024 14:15:08 -0800 Subject: [PATCH 13/14] LF-4471 Remove task animal relationship models' relationMappings --- .../taskAnimalBatchRelationshipModel.js | 23 ------------------- .../src/models/taskAnimalRelationshipModel.js | 23 ------------------- 2 files changed, 46 deletions(-) diff --git a/packages/api/src/models/taskAnimalBatchRelationshipModel.js b/packages/api/src/models/taskAnimalBatchRelationshipModel.js index b1b12ce992..d09dff33b3 100644 --- a/packages/api/src/models/taskAnimalBatchRelationshipModel.js +++ b/packages/api/src/models/taskAnimalBatchRelationshipModel.js @@ -14,8 +14,6 @@ */ import Model from './baseFormatModel.js'; -import TaskModel from './taskModel.js'; -import AnimalBatchModel from './animalBatchModel.js'; class TaskAnimalBatchRelationshipModel extends Model { static get tableName() { @@ -40,27 +38,6 @@ class TaskAnimalBatchRelationshipModel extends Model { additionalProperties: false, }; } - - static get relationMappings() { - return { - task: { - relation: Model.BelongsToOneRelation, - modelClass: TaskModel, - join: { - from: 'task_animal_batch_relationship.task_id', - to: 'task.task_id', - }, - }, - animal_batch: { - relation: Model.BelongsToOneRelation, - modelClass: AnimalBatchModel, - join: { - from: 'task_animal_batch_relationship.animal_batch_id', - to: 'animal_batch.id', - }, - }, - }; - } } export default TaskAnimalBatchRelationshipModel; diff --git a/packages/api/src/models/taskAnimalRelationshipModel.js b/packages/api/src/models/taskAnimalRelationshipModel.js index b3098f3d7a..9e7819885c 100644 --- a/packages/api/src/models/taskAnimalRelationshipModel.js +++ b/packages/api/src/models/taskAnimalRelationshipModel.js @@ -14,8 +14,6 @@ */ import Model from './baseFormatModel.js'; -import TaskModel from './taskModel.js'; -import AnimalModel from './animalModel.js'; class TaskAnimalRelationshipModel extends Model { static get tableName() { @@ -40,27 +38,6 @@ class TaskAnimalRelationshipModel extends Model { additionalProperties: false, }; } - - static get relationMappings() { - return { - task: { - relation: Model.BelongsToOneRelation, - modelClass: TaskModel, - join: { - from: 'task_animal_relationship.task_id', - to: 'task.task_id', - }, - }, - animal: { - relation: Model.BelongsToOneRelation, - modelClass: AnimalModel, - join: { - from: 'task_animal_relationship.animal_id', - to: 'animal.id', - }, - }, - }; - } } export default TaskAnimalRelationshipModel; From e3f9106075f288593c3558d7d762eb20e14f8468 Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Tue, 5 Nov 2024 14:22:22 -0800 Subject: [PATCH 14/14] LF-4471 Remove AnimalMovementTaskPurposeRelationship model's relationMappings --- ...malMovementTaskPurposeRelationshipModel.js | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/packages/api/src/models/animalMovementTaskPurposeRelationshipModel.js b/packages/api/src/models/animalMovementTaskPurposeRelationshipModel.js index 808df2d2c5..e19e0d7a5e 100644 --- a/packages/api/src/models/animalMovementTaskPurposeRelationshipModel.js +++ b/packages/api/src/models/animalMovementTaskPurposeRelationshipModel.js @@ -14,8 +14,6 @@ */ import Model from './baseFormatModel.js'; -import TaskModel from './taskModel.js'; -import AnimalMovementPurposeModel from './animalMovementPurposeModel.js'; class AnimalMovementTaskPurposeRelationship extends Model { static get tableName() { @@ -41,27 +39,6 @@ class AnimalMovementTaskPurposeRelationship extends Model { additionalProperties: false, }; } - - static get relationMappings() { - return { - task: { - relation: Model.BelongsToOneRelation, - modelClass: TaskModel, - join: { - from: 'animal_movement_task_purpose_relationship.task_id', - to: 'task.task_id', - }, - }, - purpose: { - relation: Model.BelongsToOneRelation, - modelClass: AnimalMovementPurposeModel, - join: { - from: 'animal_movement_task_purpose_relationship.purpose_id', - to: 'animal_movement_purpose.id', - }, - }, - }; - } } export default AnimalMovementTaskPurposeRelationship;