-
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
6a7b516
commit 15b9522
Showing
15 changed files
with
185 additions
and
31 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
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,44 @@ | ||
import { | ||
Table, | ||
Model, | ||
Column, | ||
PrimaryKey, | ||
DataType, | ||
AutoIncrement, | ||
ForeignKey, | ||
Unique, | ||
Default, | ||
BelongsToMany, | ||
AllowNull | ||
} from 'sequelize-typescript' | ||
|
||
export interface UserPermissionAttributes { | ||
id: bigint | ||
userId: string | ||
teamId: string | ||
permission: string | ||
} | ||
|
||
export type UserPermissionCreationAttributes = Omit< | ||
UserPermissionAttributes, | ||
'id' | ||
> | ||
|
||
@Table({ | ||
tableName: 'vw_user_teams_permissions' | ||
}) | ||
export class UserPermission extends Model< | ||
UserPermissionAttributes, | ||
UserPermissionCreationAttributes | ||
> { | ||
@AllowNull(false) | ||
@Column(DataType.UUIDV4) | ||
userId?: string | ||
|
||
@AllowNull(false) | ||
@Column(DataType.UUIDV4) | ||
teamId?: bigint | ||
|
||
@Column | ||
permission?: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
Table, | ||
Model, | ||
Column, | ||
PrimaryKey, | ||
DataType, | ||
AutoIncrement, | ||
ForeignKey | ||
} from 'sequelize-typescript' | ||
import { User } from './users' | ||
import { Team } from './teams' | ||
|
||
export interface UserTeamAttributes { | ||
id: string | ||
} | ||
|
||
export type UserRoleCreationAttributes = Omit<UserTeamAttributes, 'id'> | ||
|
||
@Table({ | ||
tableName: 'users-teams' | ||
}) | ||
export class UserTeam extends Model< | ||
UserTeamAttributes, | ||
UserRoleCreationAttributes | ||
> { | ||
@PrimaryKey | ||
@AutoIncrement | ||
@Column(DataType.BIGINT) | ||
id!: bigint | ||
|
||
@ForeignKey(() => User) | ||
@Column(DataType.UUIDV4) | ||
userId?: string | ||
|
||
@ForeignKey(() => Team) | ||
@Column(DataType.UUIDV4) | ||
teamId?: bigint | ||
} |
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,8 @@ | ||
import { z } from 'zod' | ||
|
||
export const FindOnePermissionSchema = z.object({ | ||
userId: z.string().uuid(), | ||
teamId: z.string().uuid(), | ||
permission: z.string() | ||
}) | ||
export type FindOnePermissionSchema = z.infer<typeof FindOnePermissionSchema> |
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 @@ | ||
import type { FindOnePermissionSchema } from '../schemas/permissions' | ||
import { UserPermission } from '../models/users-permissions' | ||
|
||
export const findOnePermission = async (opts: FindOnePermissionSchema) => | ||
await UserPermission.count({ where: { ...opts } }) |
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,7 @@ | ||
import { PermissionGetSchema } from '../schemas/permissions' | ||
import { protectedProcedure } from '../../trpc' | ||
import { findOnePermission } from '@/db/services/permissions' | ||
|
||
export const checkPermission = protectedProcedure | ||
.input(PermissionGetSchema) | ||
.query(async opts => findOnePermission(opts.input)) |
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,8 @@ | ||
import { z } from 'zod' | ||
|
||
export const PermissionGetSchema = z.object({ | ||
userId: z.string().uuid(), | ||
teamId: z.string().uuid(), | ||
permission: z.string() | ||
}) | ||
export type PermissionGetSchema = z.infer<typeof PermissionGetSchema> |