Skip to content

Commit

Permalink
changed activity to activity type
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry-cheng5 committed Oct 9, 2024
1 parent 8a5fd21 commit 9156318
Show file tree
Hide file tree
Showing 12 changed files with 407 additions and 343 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,54 @@
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";

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",
},
});
};

export const down: Migration = async ({ context: sequelize }) => {
// 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",
},
});
};
57 changes: 53 additions & 4 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" })
@Table({ timestamps: false, tableName: "user_pet_activities" })
export default class Activity extends Model {
@Column
activity_name!: string;
@Column({})
user_pet_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 9156318

Please sign in to comment.