-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c169bb
commit 9cf3870
Showing
17 changed files
with
319 additions
and
16 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
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 |
---|---|---|
|
@@ -165,8 +165,9 @@ describe('AuthService', () => { | |
const user = createMock<UserEntity>({ email: '[email protected]' }) | ||
|
||
mockedJwtService.sign.mockReturnValueOnce('j.w.t') | ||
const token = service.signToken(user) | ||
const {refresh_token, access_token} = service.signToken(user) | ||
|
||
expect(token).toEqual(expect.any(String)) | ||
expect(access_token).toEqual(expect.any(String)) | ||
expect(refresh_token).toEqual(expect.any(String)) | ||
}) | ||
}) |
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
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,25 @@ | ||
import { | ||
Column, | ||
CreateDateColumn, | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
UpdateDateColumn, | ||
} from 'typeorm' | ||
import { OrganizationInterface } from '@isomera/interfaces' | ||
|
||
@Entity({ name: 'organizations' }) | ||
export class OrganizationEntity implements OrganizationInterface { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Column({ nullable: false }) | ||
name: string | ||
|
||
@CreateDateColumn() | ||
createdAt: Date | ||
|
||
@UpdateDateColumn() | ||
updatedAt: Date | ||
|
||
static DEFAULT_ORGANIZATION_NAME = 'Isomera personal user' | ||
} |
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,25 @@ | ||
import { | ||
Column, | ||
CreateDateColumn, | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
} from 'typeorm' | ||
import { UserOrganizationInterace } from '@isomera/interfaces' | ||
|
||
@Entity({ name: 'user-organization' }) | ||
export class UserOrganizationEntity implements UserOrganizationInterace { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Column({ nullable: false }) | ||
userId: number | ||
|
||
@Column({ nullable: false }) | ||
organizationId: number | ||
|
||
@Column({ nullable: false }) | ||
role: number | ||
|
||
@CreateDateColumn() | ||
createdAt: Date | ||
} |
45 changes: 45 additions & 0 deletions
45
apps/api/src/migrations/1702703853544-create-organizations-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,45 @@ | ||
import { MigrationInterface, QueryRunner, Table, TableColumn } from "typeorm" | ||
|
||
export class CreateOrganizationsTable1702703853544 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: 'name', | ||
type: 'varchar(255)', | ||
isNullable: false | ||
}), | ||
new TableColumn({ | ||
name: 'createdAt', | ||
type: 'timestamp', | ||
default: 'CURRENT_TIMESTAMP', | ||
isNullable: false | ||
}), | ||
new TableColumn({ | ||
name: 'updatedAt', | ||
type: 'timestamp', | ||
default: 'CURRENT_TIMESTAMP', | ||
onUpdate: 'CURRENT_TIMESTAMP()', | ||
isNullable: false | ||
}) | ||
] | ||
}), | ||
true | ||
) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.dropTable('organizations') | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
apps/api/src/migrations/1702703944825-create-user-organization-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,55 @@ | ||
import { MigrationInterface, QueryRunner, Table, TableColumn } from "typeorm" | ||
|
||
export class CreateUserOrganizationTable1702703944825 implements MigrationInterface { | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.createTable( | ||
new Table({ | ||
name: 'user-organization', | ||
columns: [ | ||
new TableColumn({ | ||
name: 'id', | ||
type: 'int', | ||
isPrimary: true, | ||
isGenerated: true, | ||
generationStrategy: 'increment' | ||
}), | ||
new TableColumn({ | ||
name: 'userId', | ||
type: 'int', | ||
isNullable: false | ||
}), | ||
new TableColumn({ | ||
name: 'organizationId', | ||
type: 'int', | ||
isNullable: false | ||
}), | ||
new TableColumn({ | ||
name: 'role', | ||
type: 'int', | ||
isNullable: false | ||
}), | ||
new TableColumn({ | ||
name: 'createdAt', | ||
type: 'timestamp', | ||
default: 'CURRENT_TIMESTAMP', | ||
isNullable: false | ||
}), | ||
new TableColumn({ | ||
name: 'updatedAt', | ||
type: 'timestamp', | ||
default: 'CURRENT_TIMESTAMP', | ||
onUpdate: 'CURRENT_TIMESTAMP()', | ||
isNullable: false | ||
}) | ||
] | ||
}), | ||
true | ||
) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.dropTable('user-organization') | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
apps/api/src/migrations/1702704151500-add-foreign-key-user-organization-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,41 @@ | ||
import { MigrationInterface, QueryRunner, TableForeignKey } from "typeorm" | ||
|
||
export class AddForeignKeyUserOrganizationTable1702704151500 implements MigrationInterface { | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.createForeignKey( | ||
'user-organization', | ||
new TableForeignKey({ | ||
name: 'FK_users_of_user-organization', | ||
columnNames: ['userId'], | ||
referencedColumnNames: ['id'], | ||
referencedTableName: 'users', | ||
onDelete: 'CASCADE' | ||
}) | ||
) | ||
|
||
await queryRunner.createForeignKey( | ||
'user-organization', | ||
new TableForeignKey({ | ||
name: 'FK_organizations_of_user-organization', | ||
columnNames: ['organizationId'], | ||
referencedColumnNames: ['id'], | ||
referencedTableName: 'organizations', | ||
onDelete: 'CASCADE' | ||
}) | ||
) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
const table = await queryRunner.getTable('user-organization') | ||
const foreignKeyUser = table.foreignKeys.find( | ||
fk => fk.columnNames.indexOf('userId') !== -1 | ||
) | ||
await queryRunner.dropForeignKey('user_organization', foreignKeyUser) | ||
|
||
const foreignKeyOrganization = table.foreignKeys.find( | ||
fk => fk.columnNames.indexOf('organizationId') !== -1 | ||
) | ||
await queryRunner.dropForeignKey('user_organization', foreignKeyOrganization) | ||
} | ||
} |
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,12 @@ | ||
import { Module } from '@nestjs/common' | ||
import { TypeOrmModule } from '@nestjs/typeorm' | ||
import { OrganizationService } from './organization.service' | ||
import { OrganizationEntity } from '../entities/organization.entity' | ||
import { UserOrganizationEntity } from '../entities/user-organization.entity' | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([OrganizationEntity, UserOrganizationEntity]), OrganizationEntity, UserOrganizationEntity], | ||
providers: [OrganizationService], | ||
exports: [OrganizationService] | ||
}) | ||
export class OrganizationModule {} |
Oops, something went wrong.