From 2983f67ce860bf03e86c092e6cc94f31f2f5b6fc Mon Sep 17 00:00:00 2001 From: jackiettran <41605212+jackiettran@users.noreply.github.com> Date: Tue, 25 Nov 2025 16:48:54 -0500 Subject: [PATCH] removed metadata from condition check model --- .../20241124000006-create-condition-checks.js | 70 +++++++++++++++++++ backend/models/ConditionCheck.js | 4 -- backend/routes/conditionChecks.js | 10 +-- backend/services/conditionCheckService.js | 14 +--- .../services/conditionCheckService.test.js | 1 - frontend/src/types/index.ts | 1 - 6 files changed, 72 insertions(+), 28 deletions(-) create mode 100644 backend/migrations/20241124000006-create-condition-checks.js diff --git a/backend/migrations/20241124000006-create-condition-checks.js b/backend/migrations/20241124000006-create-condition-checks.js new file mode 100644 index 0000000..77c1e83 --- /dev/null +++ b/backend/migrations/20241124000006-create-condition-checks.js @@ -0,0 +1,70 @@ +"use strict"; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.createTable("ConditionChecks", { + id: { + type: Sequelize.UUID, + defaultValue: Sequelize.UUIDV4, + primaryKey: true, + }, + rentalId: { + type: Sequelize.UUID, + allowNull: false, + references: { + model: "Rentals", + key: "id", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }, + submittedBy: { + type: Sequelize.UUID, + allowNull: false, + references: { + model: "Users", + key: "id", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }, + checkType: { + type: Sequelize.ENUM( + "pre_rental_owner", + "rental_start_renter", + "rental_end_renter", + "post_rental_owner" + ), + allowNull: false, + }, + photos: { + type: Sequelize.ARRAY(Sequelize.STRING), + defaultValue: [], + }, + notes: { + type: Sequelize.TEXT, + }, + submittedAt: { + type: Sequelize.DATE, + allowNull: false, + defaultValue: Sequelize.NOW, + }, + createdAt: { + type: Sequelize.DATE, + allowNull: false, + }, + updatedAt: { + type: Sequelize.DATE, + allowNull: false, + }, + }); + + // Add indexes + await queryInterface.addIndex("ConditionChecks", ["rentalId"]); + await queryInterface.addIndex("ConditionChecks", ["submittedBy"]); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.dropTable("ConditionChecks"); + }, +}; diff --git a/backend/models/ConditionCheck.js b/backend/models/ConditionCheck.js index 803ece7..6bc5e0d 100644 --- a/backend/models/ConditionCheck.js +++ b/backend/models/ConditionCheck.js @@ -44,10 +44,6 @@ const ConditionCheck = sequelize.define("ConditionCheck", { allowNull: false, defaultValue: DataTypes.NOW, }, - metadata: { - type: DataTypes.JSONB, - defaultValue: {}, - }, }); module.exports = ConditionCheck; \ No newline at end of file diff --git a/backend/routes/conditionChecks.js b/backend/routes/conditionChecks.js index 5179be3..71396c8 100644 --- a/backend/routes/conditionChecks.js +++ b/backend/routes/conditionChecks.js @@ -37,20 +37,12 @@ router.post( // Get uploaded file paths const photos = req.files ? req.files.map((file) => file.path) : []; - // Extract metadata from request - const metadata = { - userAgent: req.get("User-Agent"), - ipAddress: req.ip, - deviceType: req.get("X-Device-Type") || "web", - }; - const conditionCheck = await ConditionCheckService.submitConditionCheck( rentalId, checkType, userId, photos, - notes, - metadata + notes ); const reqLogger = logger.withRequestId(req.id); diff --git a/backend/services/conditionCheckService.js b/backend/services/conditionCheckService.js index 8d31a31..abed26d 100644 --- a/backend/services/conditionCheckService.js +++ b/backend/services/conditionCheckService.js @@ -118,7 +118,6 @@ class ConditionCheckService { * @param {string} userId - User submitting the check * @param {Array} photos - Array of photo URLs * @param {string} notes - Optional notes - * @param {Object} metadata - Additional metadata (device info, location, etc.) * @returns {Object} - Created condition check */ static async submitConditionCheck( @@ -126,8 +125,7 @@ class ConditionCheckService { checkType, userId, photos = [], - notes = null, - metadata = {} + notes = null ) { // Validate the check const validation = await this.validateConditionCheck( @@ -145,22 +143,12 @@ class ConditionCheckService { throw new Error("Maximum 20 photos allowed per condition check"); } - // Add timestamp and user agent to metadata - const enrichedMetadata = { - ...metadata, - submittedAt: new Date().toISOString(), - userAgent: metadata.userAgent || "Unknown", - ipAddress: metadata.ipAddress || "Unknown", - deviceType: metadata.deviceType || "Unknown", - }; - const conditionCheck = await ConditionCheck.create({ rentalId, checkType, submittedBy: userId, photos, notes, - metadata: enrichedMetadata, }); return conditionCheck; diff --git a/backend/tests/unit/services/conditionCheckService.test.js b/backend/tests/unit/services/conditionCheckService.test.js index 5b84e4f..7107643 100644 --- a/backend/tests/unit/services/conditionCheckService.test.js +++ b/backend/tests/unit/services/conditionCheckService.test.js @@ -51,7 +51,6 @@ describe('ConditionCheckService', () => { submittedBy: 'renter-789', photos: mockPhotos, notes: 'Item received in good condition', - metadata: expect.any(Object) }) ); diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts index 15623e2..f672b59 100644 --- a/frontend/src/types/index.ts +++ b/frontend/src/types/index.ts @@ -194,7 +194,6 @@ export interface ConditionCheck { notes?: string; submittedBy: string; submittedAt: string; - metadata: any; submittedByUser?: User; createdAt: string; updatedAt: string;