Skip to content

Commit

Permalink
Merge pull request #233 from RBND-studio/dev
Browse files Browse the repository at this point in the history
Merge dev
  • Loading branch information
VojtechVidra committed Apr 10, 2024
2 parents 54a7cf2 + 10014c4 commit 29f5950
Show file tree
Hide file tree
Showing 16 changed files with 534 additions and 1,062 deletions.
2 changes: 1 addition & 1 deletion apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
"@types/react-dom": "^18.2.22",
"eslint-config-custom": "workspace:*",
"tsconfig": "workspace:*",
"typescript": "5.4.2"
"typescript": "5.4.4"
}
}
2 changes: 1 addition & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@
"ts-node": "^10.9.2",
"tsconfig": "workspace:*",
"tsconfig-paths": "^4.2.0",
"typescript": "5.4.2"
"typescript": "5.4.4"
}
}
4 changes: 2 additions & 2 deletions apps/backend/src/db-permission/db-permission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Injectable,
NotFoundException,
} from "@nestjs/common";
import { flows, organizations, organizationsToUsers, projects, subscriptions } from "db";
import { flows, organizationsToUsers, projects, subscriptions } from "db";
import { and, arrayContains, eq } from "drizzle-orm";

import type { Auth } from "../auth";
Expand Down Expand Up @@ -87,7 +87,7 @@ export class DbPermissionService {
.leftJoin(
organizationsToUsers,
and(
eq(organizations.id, organizationsToUsers.organization_id),
eq(projects.organization_id, organizationsToUsers.organization_id),
eq(organizationsToUsers.user_id, auth.userId),
),
)
Expand Down
19 changes: 10 additions & 9 deletions apps/backend/src/flows/flows.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from "@nestjs/common";
import { Body, Controller, Delete, Get, Patch, Post, Query } from "@nestjs/common";
import { ApiBearerAuth, ApiQuery, ApiTags } from "@nestjs/swagger";

import { type Auth, Authorization } from "../auth";
import { UUIDParam } from "../lib/uuid";
import type {
GetFlowAnalyticsDto,
GetFlowDetailDto,
Expand All @@ -20,51 +21,51 @@ export class FlowsController {
@Get("projects/:projectId/flows")
getFlows(
@Authorization() auth: Auth,
@Param("projectId") projectId: string,
@UUIDParam("projectId") projectId: string,
): Promise<GetFlowsDto[]> {
return this.flowsService.getFlows({ auth, projectId });
}

@Get("flows/:flowId")
getFlowDetail(
@Authorization() auth: Auth,
@Param("flowId") flowId: string,
@UUIDParam("flowId") flowId: string,
): Promise<GetFlowDetailDto> {
return this.flowsService.getFlowDetail({ auth, flowId });
}

@Patch("flows/:flowId")
async updateFlow(
@Authorization() auth: Auth,
@Param("flowId") flowId: string,
@UUIDParam("flowId") flowId: string,
@Body() body: UpdateFlowDto,
): Promise<void> {
await this.flowsService.updateFlow({ auth, flowId, data: body });
}

@Post("flows/:flowId/publish")
publishFlow(@Authorization() auth: Auth, @Param("flowId") flowId: string): Promise<void> {
publishFlow(@Authorization() auth: Auth, @UUIDParam("flowId") flowId: string): Promise<void> {
return this.flowsService.publishFlow({ auth, flowId });
}

@Post("projects/:projectId/flows")
createFlow(
@Authorization() auth: Auth,
@Param("projectId") projectId: string,
@UUIDParam("projectId") projectId: string,
@Body() body: CreateFlowDto,
): Promise<GetFlowsDto> {
return this.flowsService.createFlow({ auth, projectId, data: body });
}

@Delete("flows/:flowId")
deleteFlow(@Authorization() auth: Auth, @Param("flowId") flowId: string): Promise<void> {
deleteFlow(@Authorization() auth: Auth, @UUIDParam("flowId") flowId: string): Promise<void> {
return this.flowsService.deleteFlow({ auth, flowId });
}

@Get("flows/:flowId/versions")
getFlowVersions(
@Authorization() auth: Auth,
@Param("flowId") flowId: string,
@UUIDParam("flowId") flowId: string,
): Promise<GetFlowVersionsDto[]> {
return this.flowsService.getFlowVersions({ auth, flowId });
}
Expand All @@ -74,7 +75,7 @@ export class FlowsController {
@ApiQuery({ name: "endDate", required: false })
getFlowAnalytics(
@Authorization() auth: Auth,
@Param("flowId") flowId: string,
@UUIDParam("flowId") flowId: string,
@Query("startDate") startDate?: Date,
@Query("endDate") endDate?: Date,
): Promise<GetFlowAnalyticsDto> {
Expand Down
7 changes: 7 additions & 0 deletions apps/backend/src/lib/uuid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Param, ParseUUIDPipe, Query } from "@nestjs/common";

export const UUIDParam = (name: string): ParameterDecorator =>
Param(name, new ParseUUIDPipe({ version: "4" }));

export const UUIDQuery = (name: string): ParameterDecorator =>
Query(name, new ParseUUIDPipe({ version: "4" }));
30 changes: 17 additions & 13 deletions apps/backend/src/organizations/organizations.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from "@nestjs/common";
import { Body, Controller, Delete, Get, Patch, Post } from "@nestjs/common";
import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";

import { type Auth, Authorization } from "../auth";
import { UUIDParam } from "../lib/uuid";
import type {
GetOrganizationDetailDto,
GetOrganizationInvoiceDto,
Expand All @@ -26,7 +27,7 @@ export class OrganizationsController {
@Get("organizations/:organizationId")
getOrganizationDetail(
@Authorization() auth: Auth,
@Param("organizationId") organizationId: string,
@UUIDParam("organizationId") organizationId: string,
): Promise<GetOrganizationDetailDto> {
return this.organizationsService.getOrganizationDetail({ auth, organizationId });
}
Expand All @@ -42,7 +43,7 @@ export class OrganizationsController {
@Patch("organizations/:organizationId")
updateOrganization(
@Authorization() auth: Auth,
@Param("organizationId") organizationId: string,
@UUIDParam("organizationId") organizationId: string,
@Body() body: UpdateOrganizationDto,
): Promise<GetOrganizationsDto> {
return this.organizationsService.updateOrganization({ auth, organizationId, data: body });
Expand All @@ -51,15 +52,15 @@ export class OrganizationsController {
@Delete("organizations/:organizationId")
deleteOrganization(
@Authorization() auth: Auth,
@Param("organizationId") organizationId: string,
@UUIDParam("organizationId") organizationId: string,
): Promise<void> {
return this.organizationsService.deleteOrganization({ auth, organizationId });
}

@Post("organizations/:organizationId/users")
inviteUser(
@Authorization() auth: Auth,
@Param("organizationId") organizationId: string,
@UUIDParam("organizationId") organizationId: string,
@Body() body: InviteUserDto,
): Promise<void> {
return this.organizationsService.inviteUser({ auth, organizationId, email: body.email });
Expand All @@ -68,53 +69,56 @@ export class OrganizationsController {
@Post("organizations/:organizationId/users/leave")
leaveOrganization(
@Authorization() auth: Auth,
@Param("organizationId") organizationId: string,
@UUIDParam("organizationId") organizationId: string,
): Promise<void> {
return this.organizationsService.leaveOrganization({ auth, organizationId });
}

@Delete("organizations/:organizationId/users/:userId")
removeUser(
@Authorization() auth: Auth,
@Param("organizationId") organizationId: string,
@Param("userId") userId: string,
@UUIDParam("organizationId") organizationId: string,
@UUIDParam("userId") userId: string,
): Promise<void> {
return this.organizationsService.removeUser({ auth, organizationId, userId });
}

@Delete("/invites/:inviteId")
removeInvite(@Authorization() auth: Auth, @Param("inviteId") inviteId: string): Promise<void> {
removeInvite(
@Authorization() auth: Auth,
@UUIDParam("inviteId") inviteId: string,
): Promise<void> {
return this.organizationsService.deleteInvite({ auth, inviteId });
}

@Get("organizations/:organizationId/users")
getUsers(
@Authorization() auth: Auth,
@Param("organizationId") organizationId: string,
@UUIDParam("organizationId") organizationId: string,
): Promise<GetOrganizationMembersDto> {
return this.organizationsService.getOrganizationMembers({ auth, organizationId });
}

@Get("subscriptions/:subscriptionId")
getSubscription(
@Authorization() auth: Auth,
@Param("subscriptionId") subscriptionId: string,
@UUIDParam("subscriptionId") subscriptionId: string,
): Promise<GetSubscriptionDetailDto> {
return this.organizationsService.getSubscription({ auth, subscriptionId });
}

@Post("subscriptions/:subscriptionId/cancel")
cancelSubscription(
@Authorization() auth: Auth,
@Param("subscriptionId") subscriptionId: string,
@UUIDParam("subscriptionId") subscriptionId: string,
): Promise<void> {
return this.organizationsService.cancelSubscription({ auth, subscriptionId });
}

@Get("organizations/:organizationId/invoices")
getInvoices(
@Authorization() auth: Auth,
@Param("organizationId") organizationId: string,
@UUIDParam("organizationId") organizationId: string,
): Promise<GetOrganizationInvoiceDto[]> {
return this.organizationsService.getInvoices({ auth, organizationId });
}
Expand Down
16 changes: 10 additions & 6 deletions apps/backend/src/projects/projects.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from "@nestjs/common";
import { Body, Controller, Delete, Get, Patch, Post } from "@nestjs/common";
import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";

import { type Auth, Authorization } from "../auth";
import { UUIDParam } from "../lib/uuid";
import type { GetProjectDetailDto, GetProjectsDto } from "./projects.dto";
import { CreateProjectDto, UpdateProjectDto } from "./projects.dto";
import { ProjectsService } from "./projects.service";
Expand All @@ -15,23 +16,23 @@ export class ProjectsController {
@Get("organizations/:organizationId/projects")
getProjects(
@Authorization() auth: Auth,
@Param("organizationId") organizationId: string,
@UUIDParam("organizationId") organizationId: string,
): Promise<GetProjectsDto[]> {
return this.projectsService.getProjects({ auth, organizationId });
}

@Get("projects/:projectId")
getProjectDetail(
@Authorization() auth: Auth,
@Param("projectId") projectId: string,
@UUIDParam("projectId") projectId: string,
): Promise<GetProjectDetailDto> {
return this.projectsService.getProjectDetail({ auth, projectId });
}

@Post("organizations/:organizationId/projects")
createProject(
@Authorization() auth: Auth,
@Param("organizationId") organizationId: string,
@UUIDParam("organizationId") organizationId: string,
@Body() body: CreateProjectDto,
): Promise<GetProjectsDto> {
return this.projectsService.createProject({ auth, organizationId, data: body });
Expand All @@ -40,14 +41,17 @@ export class ProjectsController {
@Patch("projects/:projectId")
updateProject(
@Authorization() auth: Auth,
@Param("projectId") projectId: string,
@UUIDParam("projectId") projectId: string,
@Body() body: UpdateProjectDto,
): Promise<GetProjectDetailDto> {
return this.projectsService.updateProject({ auth, projectId, data: body });
}

@Delete("projects/:projectId")
deleteProject(@Authorization() auth: Auth, @Param("projectId") projectId: string): Promise<void> {
deleteProject(
@Authorization() auth: Auth,
@UUIDParam("projectId") projectId: string,
): Promise<void> {
return this.projectsService.deleteProject({ auth, projectId });
}
}
14 changes: 9 additions & 5 deletions apps/backend/src/sdk/sdk.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Body, Controller, Delete, Get, Header, Headers, Param, Post, Query } fr
import { ApiQuery, ApiTags } from "@nestjs/swagger";
import { minutes, Throttle } from "@nestjs/throttler";

import { UUIDQuery } from "../lib/uuid";
import type { CreateEventResponseDto, GetSdkFlowsDto } from "./sdk.dto";
import { CreateEventDto } from "./sdk.dto";
import { SdkService } from "./sdk.service";
Expand All @@ -15,7 +16,7 @@ export class SdkController {
@Throttle({ default: { limit: 100, ttl: minutes(1) } })
@Header("content-type", "text/css")
@Header("cache-control", "max-age=3600")
getCss(@Query("projectId") projectId: string, @Query("v") version: string): Promise<string> {
getCss(@UUIDQuery("projectId") projectId: string, @Query("v") version: string): Promise<string> {
return this.sdkService.getCss({ projectId, version });
}

Expand All @@ -24,7 +25,7 @@ export class SdkController {
@ApiQuery({ name: "userHash", required: false })
getFlows(
@Headers("origin") origin: string,
@Query("projectId") projectId: string,
@UUIDQuery("projectId") projectId: string,
@Query("userHash") userHash?: string,
): Promise<GetSdkFlowsDto[]> {
return this.sdkService.getFlows({ projectId, requestOrigin: origin, userHash });
Expand All @@ -34,7 +35,7 @@ export class SdkController {
@Throttle({ default: { limit: 50, ttl: minutes(1) } })
getPreviewFlow(
@Headers("origin") origin: string,
@Query("projectId") projectId: string,
@UUIDQuery("projectId") projectId: string,
@Param("flowId") flowId: string,
): Promise<GetSdkFlowsDto> {
return this.sdkService.getPreviewFlow({ projectId, requestOrigin: origin, flowId });
Expand All @@ -44,7 +45,7 @@ export class SdkController {
@Throttle({ default: { limit: 50, ttl: minutes(1) } })
getFlowDetail(
@Headers("origin") origin: string,
@Query("projectId") projectId: string,
@UUIDQuery("projectId") projectId: string,
@Param("flowId") flowId: string,
): Promise<GetSdkFlowsDto> {
return this.sdkService.getFlowDetail({ projectId, requestOrigin: origin, flowId });
Expand All @@ -59,7 +60,10 @@ export class SdkController {
}

@Delete("events/:eventId")
deleteEvent(@Headers("origin") origin: string, @Param("eventId") eventId: string): Promise<void> {
deleteEvent(
@Headers("origin") origin: string,
@UUIDQuery("eventId") eventId: string,
): Promise<void> {
return this.sdkService.deleteEvent({ eventId, requestOrigin: origin });
}
}
12 changes: 8 additions & 4 deletions apps/backend/src/users/users.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Body, Controller, Delete, Get, Param, Post } from "@nestjs/common";
import { Body, Controller, Delete, Get, Post } from "@nestjs/common";
import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";

import { type Auth, Authorization } from "../auth";
import { UUIDParam } from "../lib/uuid";
import type { AcceptInviteResponseDto, GetMeDto } from "./users.dto";
import { JoinWaitlistDto } from "./users.dto";
import { UsersService } from "./users.service";
Expand All @@ -20,13 +21,16 @@ export class UsersController {
@Post("invites/:inviteId/accept")
acceptInvite(
@Authorization() auth: Auth,
@Param("inviteId") inviteId: string,
@UUIDParam("inviteId") inviteId: string,
): Promise<AcceptInviteResponseDto> {
return this.usersService.acceptInvite({ auth, inviteId });
}

@Post("invites/:inviteId/decline")
declineInvite(@Authorization() auth: Auth, @Param("inviteId") inviteId: string): Promise<void> {
declineInvite(
@Authorization() auth: Auth,
@UUIDParam("inviteId") inviteId: string,
): Promise<void> {
return this.usersService.declineInvite({ auth, inviteId });
}

Expand All @@ -43,7 +47,7 @@ export class UsersController {
@Delete("me/identities/:providerId")
deleteIdentity(
@Authorization() auth: Auth,
@Param("providerId") providerId: string,
@UUIDParam("providerId") providerId: string,
): Promise<void> {
return this.usersService.deleteIdentity({ auth, providerId });
}
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"@types/react-dom": "^18.2.22",
"eslint-config-custom": "workspace:*",
"tsconfig": "workspace:*",
"typescript": "5.4.2"
"typescript": "5.4.4"
}
}
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
"@types/react-dom": "^18.2.22",
"eslint-config-custom": "workspace:*",
"tsconfig": "workspace:*",
"typescript": "5.4.2"
"typescript": "5.4.4"
}
}
Loading

0 comments on commit 29f5950

Please sign in to comment.