feat(workspaces): create workspace seat function

This commit is contained in:
Alessandro Magionami
2025-02-27 11:06:31 +01:00
parent 781357c488
commit 99d4aba767
2 changed files with 16 additions and 0 deletions
@@ -1,3 +1,4 @@
import { WorkspaceSeat } from '@/modules/gatekeeper/domain/billing'
import { WorkspaceFeatureName } from '@/modules/gatekeeper/domain/workspacePricing'
import {
PlanStatuses,
@@ -30,3 +31,7 @@ export type GetWorkspacePlanByProjectId = ({
}: {
projectId: string
}) => Promise<WorkspacePlan | null>
export type CreateWorkspaceSeat = (
args: Pick<WorkspaceSeat, 'workspaceId' | 'userId' | 'type'>
) => Promise<WorkspaceSeat>
@@ -1,4 +1,5 @@
import { WorkspaceSeat } from '@/modules/gatekeeper/domain/billing'
import { CreateWorkspaceSeat } from '@/modules/gatekeeper/domain/operations'
import { Knex } from 'knex'
const tables = {
@@ -17,3 +18,13 @@ export const countSeatsByTypeInWorkspaceFactory =
.count('id')
return parseInt(count.toString())
}
export const createWorkspaceSeatFactory =
({ db }: { db: Knex }): CreateWorkspaceSeat =>
async ({ userId, workspaceId, type }) => {
return await tables.workspaceSeats(db).insert({
workspaceId,
userId,
type
})
}