Skip to content

Commit

Permalink
Merge pull request #38 from uwblueprint/f24/jerry/rename-activity-to-…
Browse files Browse the repository at this point in the history
…activity-type

changed activity to activity type
  • Loading branch information
jerry-cheng5 authored Oct 10, 2024
2 parents 8a5fd21 + 93e8c99 commit ff1a9b7
Show file tree
Hide file tree
Showing 12 changed files with 417 additions and 342 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getApiValidationError, validatePrimitive } from "./util";

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable-next-line import/prefer-default-export */
export const activityRequestDtoValidator = async (
export const activityTypeRequestDtoValidator = async (
req: Request,
res: Response,
next: NextFunction,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { DataType } from "sequelize-typescript";
import { Migration } from "../umzug";

const OLD_TABLE_NAME = "activities";
const NEW_TABLE_NAME = "activity_types";
const USER_PET_ACTIVITIES_TABLE = "user_pet_activities";
const ACTIVITIES_TABLE = "activities";

export const up: Migration = async ({ context: sequelize }) => {
// Rename the activities table to activity_types
await sequelize
.getQueryInterface()
.renameTable(OLD_TABLE_NAME, NEW_TABLE_NAME);

// Change the activity_id column in user_pet_activities to activity_type_id
await sequelize
.getQueryInterface()
.renameColumn(USER_PET_ACTIVITIES_TABLE, "activity_id", "activity_type_id");

// Update the references for activity_type_id to point to the new activity_types table
await sequelize
.getQueryInterface()
.changeColumn(USER_PET_ACTIVITIES_TABLE, "activity_type_id", {
type: DataType.INTEGER,
allowNull: false,
references: {
model: NEW_TABLE_NAME, // Reference the new table name
key: "id",
},
});

// Change the name of user_pet_activities to activities
await sequelize
.getQueryInterface()
.renameTable(USER_PET_ACTIVITIES_TABLE, ACTIVITIES_TABLE);
};

export const down: Migration = async ({ context: sequelize }) => {
// Rename the activities table back to user_pet_activities
await sequelize
.getQueryInterface()
.renameTable(ACTIVITIES_TABLE, USER_PET_ACTIVITIES_TABLE);

// Rename the activity_types table back to activities
await sequelize
.getQueryInterface()
.renameTable(NEW_TABLE_NAME, OLD_TABLE_NAME);

// Revert the activity_type_id column back to activity_id
await sequelize
.getQueryInterface()
.renameColumn(USER_PET_ACTIVITIES_TABLE, "activity_type_id", "activity_id");

// Revert the activity_id column to reference the old activities table
await sequelize
.getQueryInterface()
.changeColumn(USER_PET_ACTIVITIES_TABLE, "activity_id", {
type: DataType.INTEGER,
allowNull: false,
references: {
model: OLD_TABLE_NAME, // Revert back to the old table name
key: "id",
},
});
};
55 changes: 52 additions & 3 deletions backend/typescript/models/activity.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,56 @@
import { Column, Model, Table } from "sequelize-typescript";
import {
Column,
Model,
Table,
DataType,
ForeignKey,
BelongsTo,
} from "sequelize-typescript";
import User from "./user.model";
import Pet from "./pet.model";
import ActivityType from "./activityType.model";

@Table({ timestamps: false, tableName: "activities" })
export default class Activity extends Model {
@Column
activity_name!: string;
@Column({})
activity_id!: number;

@ForeignKey(() => User) // in case of null, task has not been assigned
@Column({})
user_id?: number;

@BelongsTo(() => User)
user?: User;

@ForeignKey(() => Pet)
@Column({})
pet_id!: number;

@BelongsTo(() => Pet)
pet!: Pet;

@ForeignKey(() => ActivityType)
@Column({})
activity_type_id!: number;

@BelongsTo(() => ActivityType)
activity_type!: ActivityType;

@Column({})
scheduled_start_time?: Date;

@Column({})
start_time?: Date;

@Column({})
end_time?: Date;

@Column({ type: DataType.TEXT })
notes?: string;

@Column({})
created_at!: Date;

@Column({})
updated_at?: Date;
}
7 changes: 7 additions & 0 deletions backend/typescript/models/activityType.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Column, Model, Table } from "sequelize-typescript";

@Table({ timestamps: false, tableName: "activity_types" })
export default class ActivityType extends Model {
@Column
activity_name!: string;
}
57 changes: 0 additions & 57 deletions backend/typescript/models/userPetActivity.ts

This file was deleted.

106 changes: 0 additions & 106 deletions backend/typescript/rest/activityRoutes.ts

This file was deleted.

Loading

0 comments on commit ff1a9b7

Please sign in to comment.