-
Notifications
You must be signed in to change notification settings - Fork 1
[INTS25] user admin role models #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
595e0a2
dummy commit
mxc-maggiechen 9555636
Create/update schemas for admin, position, user
carolynzhang18 01d2884
Add types for department/position
carolynzhang18 d60b997
Create migration file
carolynzhang18 f8c8f7c
Make linter happy
carolynzhang18 bf5d9e0
dummy commit
mxc-maggiechen 7b1cba2
Create/update schemas for admin, position, user
carolynzhang18 b406049
Add types for department/position
carolynzhang18 f34d2c9
Create migration file
carolynzhang18 5d499b1
Make linter happy
carolynzhang18 836cea8
Linter?
carolynzhang18 abd83ae
Merge branch 'main' into INTS25-user-admin-role-models
mxc-maggiechen 025c349
merge main
mxc-maggiechen 1bb7770
fix lint
mxc-maggiechen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
...rations/2025.06.18T05.35.22.create-admin-table-create-position-table-update-user-table.ts
This file contains hidden or 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,96 @@ | ||
| import { DataType } from "sequelize-typescript"; | ||
|
|
||
| import { Migration } from "../umzug"; | ||
| import { | ||
| CommunityPositionTitles, | ||
| Department, | ||
| DesignPositionTitles, | ||
| EngineeringPositionTitles, | ||
| PositionTitles, | ||
| ProductPositionTitles, | ||
| } from "../types"; | ||
|
|
||
| const ADMIN_TABLE_NAME = "admins"; | ||
| const POSITION_TABLE_NAME = "positions"; | ||
| const USER_TABLE_NAME = "users"; | ||
|
|
||
| const ADMIN_SEEDED_DATA = [ | ||
| { | ||
| userId: "1", | ||
| authorizedDepartments: [Department.Engineering, Department.Product], | ||
| }, | ||
| { | ||
| userId: "2", | ||
| authorizedDepartments: [Department.Design, Department.Community], | ||
| }, | ||
| ]; | ||
| const POSITION_SEEDED_DATA = [ | ||
| ...EngineeringPositionTitles.map((title) => ({ | ||
| title, | ||
| department: Department.Engineering, | ||
| })), | ||
| ...DesignPositionTitles.map((title) => ({ | ||
| title, | ||
| department: Department.Design, | ||
| })), | ||
| ...ProductPositionTitles.map((title) => ({ | ||
| title, | ||
| department: Department.Product, | ||
| })), | ||
| ...CommunityPositionTitles.map((title) => ({ | ||
| title, | ||
| department: Department.Community, | ||
| })), | ||
| ]; | ||
|
|
||
| export const up: Migration = async ({ context: sequelize }) => { | ||
| await sequelize.getQueryInterface().createTable(POSITION_TABLE_NAME, { | ||
| title: { | ||
| type: DataType.ENUM(...PositionTitles), | ||
| allowNull: false, | ||
| primaryKey: true, | ||
| }, | ||
| department: { | ||
| type: DataType.ENUM(...Object.values(Department)), | ||
| allowNull: false, | ||
| }, | ||
| }); | ||
| await sequelize | ||
| .getQueryInterface() | ||
| .bulkInsert(POSITION_TABLE_NAME, POSITION_SEEDED_DATA); | ||
|
|
||
| await sequelize.getQueryInterface().addColumn(USER_TABLE_NAME, "position", { | ||
| type: "enum_positions_title", | ||
| references: { | ||
| model: POSITION_TABLE_NAME, | ||
| key: "title", | ||
| }, | ||
| }); | ||
|
|
||
| await sequelize.getQueryInterface().createTable(ADMIN_TABLE_NAME, { | ||
| userId: { | ||
| type: DataType.INTEGER, | ||
| allowNull: false, | ||
| primaryKey: true, | ||
| references: { | ||
| model: USER_TABLE_NAME, | ||
| key: "id", | ||
| }, | ||
| }, | ||
| authorizedDepartments: { | ||
| type: DataType.ARRAY(DataType.STRING), | ||
| allowNull: false, | ||
| }, | ||
| }); | ||
| await sequelize | ||
| .getQueryInterface() | ||
| .bulkInsert(ADMIN_TABLE_NAME, ADMIN_SEEDED_DATA); | ||
| }; | ||
|
|
||
| export const down: Migration = async ({ context: sequelize }) => { | ||
| await sequelize.getQueryInterface().removeColumn(USER_TABLE_NAME, "position"); | ||
| await sequelize.getQueryInterface().dropTable(ADMIN_TABLE_NAME); | ||
| await sequelize.getQueryInterface().dropTable(POSITION_TABLE_NAME); | ||
| await sequelize.query('DROP TYPE IF EXISTS "enum_positions_title";'); | ||
| await sequelize.query('DROP TYPE IF EXISTS "enum_positions_department";'); | ||
| }; |
This file contains hidden or 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 { | ||
| Column, | ||
| DataType, | ||
| ForeignKey, | ||
| Model, | ||
| Table, | ||
| } from "sequelize-typescript"; | ||
| import User from "./user.model"; | ||
| import { Department } from "../types"; | ||
|
|
||
| @Table({ tableName: "admins" }) | ||
| export default class Admin extends Model { | ||
| @ForeignKey(() => User) | ||
| @Column({ type: DataType.INTEGER, primaryKey: true }) | ||
| userId!: number; | ||
|
|
||
| @Column({ type: DataType.ARRAY(DataType.ENUM(...Object.values(Department))) }) | ||
| authorizedDepartments!: Department[]; | ||
| } |
This file contains hidden or 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,11 @@ | ||
| import { Column, DataType, Model, Table } from "sequelize-typescript"; | ||
| import { Department, PositionTitle, PositionTitles } from "../types"; | ||
|
|
||
| @Table({ tableName: "positions" }) | ||
| export default class Position extends Model { | ||
| @Column({ type: DataType.ENUM(...PositionTitles), primaryKey: true }) | ||
| title!: PositionTitle; | ||
|
|
||
| @Column({ type: DataType.ENUM(...Object.values(Department)) }) | ||
| department!: Department; | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you have time, maybe create a enum for all position titles to prevent misspelling