-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into F24/julia/activity-managem…
…ent-endpoints-I
- Loading branch information
Showing
21 changed files
with
647 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const MIN_BEHAVIOUR_LEVEL = 1; | ||
export const MAX_BEHAVIOUR_LEVEL = 4; |
36 changes: 36 additions & 0 deletions
36
backend/typescript/migrations/2024.10.04T00.23.02.create-user-animal-types-table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { DataType } from "sequelize-typescript"; | ||
|
||
import { Migration } from "../umzug"; | ||
|
||
const TABLE_NAME = "user_animal_types"; | ||
|
||
export const up: Migration = async ({ context: sequelize }) => { | ||
await sequelize.getQueryInterface().createTable(TABLE_NAME, { | ||
user_id: { | ||
type: DataType.INTEGER, | ||
allowNull: false, | ||
primaryKey: true, | ||
references: { | ||
model: "users", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
animal_type_id: { | ||
type: DataType.INTEGER, | ||
allowNull: false, | ||
primaryKey: true, | ||
references: { | ||
model: "animal_types", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
}); | ||
}; | ||
|
||
export const down: Migration = async ({ context: sequelize }) => { | ||
await sequelize.getQueryInterface().dropTable(TABLE_NAME); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
backend/typescript/migrations/2024.10.29T20.20.02.create-user-behaviour-table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { DataType } from "sequelize-typescript"; | ||
|
||
import { Migration } from "../umzug"; | ||
import { MAX_BEHAVIOUR_LEVEL, MIN_BEHAVIOUR_LEVEL } from "../constants"; | ||
|
||
const TABLE_NAME = "user_behaviours"; | ||
const CONSTRAINT_NAME = "unique_user_behaviour_skill"; | ||
const CONSTRAINT_NAME_2 = "max_level_interval"; | ||
|
||
export const up: Migration = async ({ context: sequelize }) => { | ||
await sequelize.getQueryInterface().createTable(TABLE_NAME, { | ||
id: { | ||
type: DataType.INTEGER, | ||
allowNull: false, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
}, | ||
user_id: { | ||
type: DataType.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: "users", | ||
key: "id", | ||
}, | ||
}, | ||
behaviour_id: { | ||
type: DataType.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: "behaviours", | ||
key: "id", | ||
}, | ||
}, | ||
max_level: { | ||
type: DataType.INTEGER, | ||
allowNull: false, | ||
}, | ||
}); | ||
|
||
await sequelize.getQueryInterface().addConstraint(TABLE_NAME, { | ||
fields: ["behaviour_id", "user_id"], | ||
type: "unique", | ||
name: CONSTRAINT_NAME, | ||
}); | ||
|
||
await sequelize.query( | ||
`ALTER TABLE ${TABLE_NAME} ADD CONSTRAINT ${CONSTRAINT_NAME_2} | ||
CHECK (max_level BETWEEN ${MIN_BEHAVIOUR_LEVEL} AND ${MAX_BEHAVIOUR_LEVEL});`, | ||
); | ||
}; | ||
|
||
export const down: Migration = async ({ context: sequelize }) => { | ||
await sequelize | ||
.getQueryInterface() | ||
.removeConstraint(TABLE_NAME, CONSTRAINT_NAME); | ||
|
||
await sequelize.query( | ||
`ALTER TABLE ${TABLE_NAME} DROP CONSTRAINT ${CONSTRAINT_NAME_2};`, | ||
); | ||
|
||
await sequelize.getQueryInterface().dropTable(TABLE_NAME); | ||
}; |
40 changes: 40 additions & 0 deletions
40
backend/typescript/migrations/2024.10.29T20.29.50.add-pet-behaviour-columns.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { DataType } from "sequelize-typescript"; | ||
import { Migration } from "../umzug"; | ||
import { MAX_BEHAVIOUR_LEVEL, MIN_BEHAVIOUR_LEVEL } from "../constants"; | ||
|
||
const TABLE_NAME = "pet_behaviours"; | ||
const CONSTRAINT_NAME = "unique_pet_behaviour"; | ||
const CONSTRAINT_NAME_2 = "skill_level_interval"; | ||
|
||
export const up: Migration = async ({ context: sequelize }) => { | ||
await sequelize.getQueryInterface().addColumn(TABLE_NAME, "is_highlighted", { | ||
type: DataType.BOOLEAN, | ||
allowNull: true, | ||
defaultValue: false, | ||
}); | ||
|
||
await sequelize.getQueryInterface().addConstraint(TABLE_NAME, { | ||
fields: ["behaviour_id", "pet_id"], | ||
type: "unique", | ||
name: CONSTRAINT_NAME, | ||
}); | ||
|
||
await sequelize.query( | ||
`ALTER TABLE ${TABLE_NAME} ADD CONSTRAINT ${CONSTRAINT_NAME_2} | ||
CHECK (skill_level BETWEEN ${MIN_BEHAVIOUR_LEVEL} AND ${MAX_BEHAVIOUR_LEVEL});`, | ||
); | ||
}; | ||
|
||
export const down: Migration = async ({ context: sequelize }) => { | ||
await sequelize | ||
.getQueryInterface() | ||
.removeConstraint(TABLE_NAME, CONSTRAINT_NAME); | ||
|
||
await sequelize | ||
.getQueryInterface() | ||
.removeColumn(TABLE_NAME, "is_highlighted"); | ||
|
||
await sequelize.query( | ||
`ALTER TABLE ${TABLE_NAME} DROP CONSTRAINT ${CONSTRAINT_NAME_2};`, | ||
); | ||
}; |
19 changes: 19 additions & 0 deletions
19
...typescript/migrations/2024.11.21T16.49.50.add-constraint-behaviour-level-details-table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { DataType } from "sequelize-typescript"; | ||
import { Migration } from "../umzug"; | ||
import { MAX_BEHAVIOUR_LEVEL, MIN_BEHAVIOUR_LEVEL } from "../constants"; | ||
|
||
const TABLE_NAME = "behaviour_level_details"; | ||
const CONSTRAINT_NAME = "level_interval"; | ||
|
||
export const up: Migration = async ({ context: sequelize }) => { | ||
await sequelize.query( | ||
`ALTER TABLE ${TABLE_NAME} ADD CONSTRAINT ${CONSTRAINT_NAME} | ||
CHECK (level BETWEEN ${MIN_BEHAVIOUR_LEVEL} AND ${MAX_BEHAVIOUR_LEVEL});`, | ||
); | ||
}; | ||
|
||
export const down: Migration = async ({ context: sequelize }) => { | ||
await sequelize.query( | ||
`ALTER TABLE ${TABLE_NAME} DROP CONSTRAINT ${CONSTRAINT_NAME};`, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import User from "./user.model"; | ||
import AnimalType from "./animalType.model"; | ||
import UserAnimalType from "./userAnimalType.model"; | ||
|
||
export default function defineRelationships(): void { | ||
User.belongsToMany(AnimalType, { through: UserAnimalType }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { | ||
Column, | ||
DataType, | ||
Model, | ||
Table, | ||
ForeignKey, | ||
PrimaryKey, | ||
} from "sequelize-typescript"; | ||
import User from "./user.model"; | ||
import AnimalType from "./animalType.model"; | ||
|
||
@Table({ | ||
tableName: "User_AnimalTypes", | ||
timestamps: true, | ||
}) | ||
export default class UserAnimalType extends Model { | ||
@ForeignKey(() => User) | ||
@PrimaryKey | ||
@Column({ type: DataType.INTEGER, allowNull: false }) | ||
user_id!: number; | ||
|
||
@ForeignKey(() => AnimalType) | ||
@PrimaryKey | ||
@Column({ type: DataType.INTEGER, allowNull: false }) | ||
animal_type_id!: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { | ||
Column, | ||
Model, | ||
Table, | ||
ForeignKey, | ||
BelongsTo, | ||
DataType, | ||
} from "sequelize-typescript"; | ||
import Behaviour from "./behaviour.model"; | ||
import User from "./user.model"; | ||
|
||
@Table({ timestamps: false, tableName: "user_behaviours" }) | ||
export default class UserBehaviour extends Model { | ||
@ForeignKey(() => User) | ||
@Column({ type: DataType.INTEGER, allowNull: false }) | ||
user_id!: number; | ||
|
||
@BelongsTo(() => User) | ||
user!: User; | ||
|
||
@ForeignKey(() => Behaviour) | ||
@Column({ type: DataType.INTEGER, allowNull: false }) | ||
behaviour_id!: number; | ||
|
||
@BelongsTo(() => Behaviour) | ||
behaviour!: Behaviour; | ||
|
||
@Column({ type: DataType.INTEGER, allowNull: false }) | ||
max_level!: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from "react"; | ||
import { Text } from "@chakra-ui/react"; | ||
|
||
interface StatusMessageProps { | ||
message: string; | ||
color?: string; | ||
} | ||
|
||
const StatusMessage = ({ | ||
message, | ||
color = "blue.700", | ||
}: StatusMessageProps): React.ReactElement => { | ||
return ( | ||
<Text color={color} textAlign="center" lineHeight="120%" marginTop="16px"> | ||
{message} | ||
</Text> | ||
); | ||
}; | ||
|
||
export default StatusMessage; |
Oops, something went wrong.