-
Notifications
You must be signed in to change notification settings - Fork 0
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
fe8233c
commit 9d7f075
Showing
8 changed files
with
1,050 additions
and
287 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,5 @@ | ||
POSTGRES_DATABASE=local | ||
POSTGRES_HOST=localhost | ||
POSTGRES_PORT=55432 | ||
POSTGRES_USER=local | ||
POSTGRES_PASSWORD=local |
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,52 @@ | ||
import { | ||
Collection, | ||
Entity, | ||
Enum, | ||
ManyToMany, | ||
Property, | ||
} from '@mikro-orm/core'; | ||
|
||
export enum RoleName { | ||
Owner = 'Owner', | ||
Admin = 'Admin', | ||
BillingManager = 'BillingManager', | ||
InfrastructureManager = 'InfrastructureManager', | ||
Member = 'Member', | ||
} | ||
export enum PermissionAction { | ||
CREATE = 'create', | ||
READ = 'read', | ||
UPDATE = 'update', | ||
DELETE = 'delete', | ||
} | ||
|
||
export enum PermissableSubject { | ||
USER = 'Users', | ||
} | ||
|
||
export interface PermissionCondition { | ||
[key: string]: string | number | PermissionCondition; | ||
} | ||
|
||
@Entity({ tableName: 'permissions' }) | ||
export class PermissionModel { | ||
@Enum(() => PermissionAction) | ||
action!: PermissionAction; | ||
|
||
@Enum(() => PermissableSubject) | ||
subject!: PermissableSubject; | ||
|
||
@Property({ type: 'json', nullable: false, default: '{}' }) | ||
condition!: PermissionCondition; | ||
} | ||
|
||
@Entity({ tableName: 'roles' }) | ||
export class RoleModel { | ||
@Enum(() => RoleName) | ||
name!: RoleName; | ||
|
||
@ManyToMany(() => PermissionModel) | ||
permissions: Collection<PermissionModel> = new Collection<PermissionModel>( | ||
this | ||
); | ||
} |
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,16 @@ | ||
import { defineConfig } from '@mikro-orm/postgresql'; | ||
|
||
export default defineConfig({ | ||
dbName: process.env.POSTGRES_DATABASE, | ||
host: process.env['POSTGRES_HOST'], | ||
port: Number(process.env['POSTGRES_PORT'] || '23455'), | ||
user: process.env['POSTGRES_USER'], | ||
password: process.env['POSTGRES_PASSWORD'], | ||
entities: ['dist/src/**/*.entity.js'], | ||
entitiesTs: ['src/**/*.entity.ts'], | ||
migrations: { | ||
path: 'dist/migrations', | ||
pathTs: 'src/migrations', | ||
}, | ||
debug: true, | ||
}); |
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,10 @@ | ||
version: '2' | ||
services: | ||
postgres: | ||
image: postgres:15.5 | ||
environment: | ||
POSTGRES_USER: local | ||
POSTGRES_PASSWORD: local | ||
POSTGRES_DB: local | ||
ports: | ||
- 23455:5432 |
Oops, something went wrong.