Skip to content

Commit

Permalink
first steps
Browse files Browse the repository at this point in the history
  • Loading branch information
vygandas committed Dec 8, 2023
1 parent a03e57d commit 85c0eb1
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
13 changes: 13 additions & 0 deletions apps/api/src/entities/organization.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { OrganizationInterface } from '@isomera/interfaces'
import { PrimaryGeneratedColumn, JoinColumn, ManyToOne } from 'typeorm'

import { UserEntity } from './user.entity'

export class OrganizationEntity implements OrganizationInterface {
@PrimaryGeneratedColumn('increment')
id: number

@ManyToOne(() => UserEntity, user => user.id)
@JoinColumn()
user: UserEntity
}
4 changes: 4 additions & 0 deletions apps/api/src/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { UserInterface } from '@isomera/interfaces'
import bcrypt from 'bcryptjs'
import { ConfirmCodeEntity } from './confirm-code.entity'
import { OrganizationEntity } from './organization.entity'

@Entity({ name: 'users' })
export class UserEntity implements UserInterface {
Expand Down Expand Up @@ -50,6 +51,9 @@ export class UserEntity implements UserInterface {
@OneToMany(() => ConfirmCodeEntity, confirmCode => confirmCode.user)
confirmationCodes: ConfirmCodeEntity[]

@OneToMany(() => OrganizationEntity, organization => organization.user)
organizations: OrganizationEntity[]

@BeforeInsert()
@BeforeUpdate()
async hashPassword(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
MigrationInterface,
QueryRunner,
Table,
TableColumn,
TableForeignKey
} from 'typeorm'

export class CreateOrganizationsTable1701953109158
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'organizations',
columns: [
new TableColumn({
name: 'id',
type: 'int',
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment'
}),
new TableColumn({
name: 'userId',
type: 'int'
})
]
})
)

await queryRunner.createForeignKey(
'organizations',
new TableForeignKey({
name: 'FK_user_of_organization',
columnNames: ['userId'],
referencedColumnNames: ['id'],
referencedTableName: 'users',
onDelete: 'CASCADE'
})
)
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('organizations')
}
}
1 change: 1 addition & 0 deletions libs/interfaces/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './auth/passwordResetRequest.interface'
export * from './auth/passwordResetPerform.interface'
export * from './auth/signUpResponse.interface'
export * from './auth/confirmationCode.interface'
export * from './organization/organization.interface'
6 changes: 6 additions & 0 deletions libs/interfaces/src/organization/organization.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { UserInterface } from '../user/User.interface'

export interface OrganizationInterface {
id?: number
user: UserInterface
}
2 changes: 2 additions & 0 deletions libs/interfaces/src/user/User.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConfirmationCodeInterface } from '../auth/confirmationCode.interface'
import { OrganizationInterface } from '../organization/organization.interface'

export interface UserInterface {
id?: number
Expand All @@ -11,4 +12,5 @@ export interface UserInterface {
passwordResetCode?: string | null
active: boolean
confirmationCodes?: ConfirmationCodeInterface[]
organizations: OrganizationInterface[]
}

0 comments on commit 85c0eb1

Please sign in to comment.