mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-08 06:42:39 +02:00
ddd: create users repository
This commit is contained in:
parent
eac001527c
commit
219d4c7901
23 changed files with 220 additions and 134 deletions
|
|
@ -1,13 +1,15 @@
|
|||
"use server";
|
||||
import { auth0 } from "../lib/auth0";
|
||||
import { USE_AUTH } from "../lib/feature_flags";
|
||||
import { WithStringId, User } from "../lib/types/types";
|
||||
import { User } from "@/src/entities/models/user";
|
||||
import { getUserFromSessionId, GUEST_DB_USER } from "../lib/auth";
|
||||
import { z } from "zod";
|
||||
import { ObjectId } from "mongodb";
|
||||
import { usersCollection } from "../lib/mongodb";
|
||||
import { container } from "@/di/container";
|
||||
import { IUsersRepository } from "@/src/application/repositories/users.repository.interface";
|
||||
|
||||
export async function authCheck(): Promise<WithStringId<z.infer<typeof User>>> {
|
||||
const usersRepository = container.resolve<IUsersRepository>("usersRepository");
|
||||
|
||||
export async function authCheck(): Promise<z.infer<typeof User>> {
|
||||
if (!USE_AUTH) {
|
||||
return GUEST_DB_USER;
|
||||
}
|
||||
|
|
@ -42,12 +44,5 @@ export async function updateUserEmail(email: string) {
|
|||
}
|
||||
|
||||
// update customer email in db
|
||||
await usersCollection.updateOne({
|
||||
_id: new ObjectId(user._id),
|
||||
}, {
|
||||
$set: {
|
||||
email,
|
||||
updatedAt: new Date().toISOString(),
|
||||
}
|
||||
});
|
||||
await usersRepository.updateEmail(user.id, email);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ export async function listToolkits(projectId: string, cursor: string | null = nu
|
|||
const user = await authCheck();
|
||||
return await listComposioToolkitsController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
cursor,
|
||||
});
|
||||
|
|
@ -59,7 +59,7 @@ export async function getToolkit(projectId: string, toolkitSlug: string): Promis
|
|||
const user = await authCheck();
|
||||
return await getComposioToolkitController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
toolkitSlug,
|
||||
});
|
||||
|
|
@ -69,7 +69,7 @@ export async function listTools(projectId: string, toolkitSlug: string, searchQu
|
|||
const user = await authCheck();
|
||||
return await listComposioToolsController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
toolkitSlug,
|
||||
searchQuery,
|
||||
|
|
@ -81,7 +81,7 @@ export async function createComposioManagedOauth2ConnectedAccount(projectId: str
|
|||
const user = await authCheck();
|
||||
return await createComposioManagedConnectedAccountController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
toolkitSlug,
|
||||
callbackUrl,
|
||||
|
|
@ -92,7 +92,7 @@ export async function createCustomConnectedAccount(projectId: string, request: z
|
|||
const user = await authCheck();
|
||||
return await createCustomConnectedAccountController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
toolkitSlug: request.toolkitSlug,
|
||||
authConfig: request.authConfig,
|
||||
|
|
@ -104,7 +104,7 @@ export async function syncConnectedAccount(projectId: string, toolkitSlug: strin
|
|||
const user = await authCheck();
|
||||
return await syncConnectedAccountController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
toolkitSlug,
|
||||
connectedAccountId,
|
||||
|
|
@ -116,7 +116,7 @@ export async function deleteConnectedAccount(projectId: string, toolkitSlug: str
|
|||
|
||||
await deleteComposioConnectedAccountController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
toolkitSlug,
|
||||
});
|
||||
|
|
@ -144,7 +144,7 @@ export async function createComposioTriggerDeployment(request: {
|
|||
// create trigger deployment
|
||||
return await createComposioTriggerDeploymentController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId: request.projectId,
|
||||
data: {
|
||||
triggerTypeSlug: request.triggerTypeSlug,
|
||||
|
|
@ -163,7 +163,7 @@ export async function listComposioTriggerDeployments(request: {
|
|||
// list trigger deployments
|
||||
return await listComposioTriggerDeploymentsController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId: request.projectId,
|
||||
cursor: request.cursor,
|
||||
});
|
||||
|
|
@ -178,7 +178,7 @@ export async function deleteComposioTriggerDeployment(request: {
|
|||
// delete trigger deployment
|
||||
return await deleteComposioTriggerDeploymentController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId: request.projectId,
|
||||
deploymentId: request.deploymentId,
|
||||
});
|
||||
|
|
@ -188,7 +188,7 @@ export async function fetchComposioTriggerDeployment(request: { deploymentId: st
|
|||
const user = await authCheck();
|
||||
return await fetchComposioTriggerDeploymentController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
deploymentId: request.deploymentId,
|
||||
});
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ export async function listConversations(request: {
|
|||
|
||||
return await listConversationsController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId: request.projectId,
|
||||
cursor: request.cursor,
|
||||
limit: request.limit,
|
||||
|
|
@ -31,7 +31,7 @@ export async function fetchConversation(request: {
|
|||
|
||||
return await fetchConversationController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
conversationId: request.conversationId,
|
||||
});
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ export async function addServer(projectId: string, name: string, server: McpServ
|
|||
validateUrl(server.serverUrl);
|
||||
await addCustomMcpServerController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
name,
|
||||
server,
|
||||
|
|
@ -43,7 +43,7 @@ export async function removeServer(projectId: string, name: string): Promise<voi
|
|||
const user = await authCheck();
|
||||
await removeCustomMcpServerController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
name,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ export async function getDataSource(sourceId: string): Promise<z.infer<typeof Da
|
|||
|
||||
return await fetchDataSourceController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
sourceId,
|
||||
});
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ export async function listDataSources(projectId: string): Promise<z.infer<typeof
|
|||
|
||||
return await listDataSourcesController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
});
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ export async function createDataSource({
|
|||
const user = await authCheck();
|
||||
return await createDataSourceController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
data: {
|
||||
projectId,
|
||||
name,
|
||||
|
|
@ -82,7 +82,7 @@ export async function recrawlWebDataSource(sourceId: string) {
|
|||
|
||||
return await recrawlWebDataSourceController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
sourceId,
|
||||
});
|
||||
}
|
||||
|
|
@ -92,7 +92,7 @@ export async function deleteDataSource(sourceId: string) {
|
|||
|
||||
return await deleteDataSourceController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
sourceId,
|
||||
});
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ export async function toggleDataSource(sourceId: string, active: boolean) {
|
|||
|
||||
return await toggleDataSourceController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
sourceId,
|
||||
active,
|
||||
});
|
||||
|
|
@ -122,7 +122,7 @@ export async function addDocsToDataSource({
|
|||
|
||||
return await addDocsToDataSourceController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
sourceId,
|
||||
docs: docData,
|
||||
});
|
||||
|
|
@ -144,7 +144,7 @@ export async function listDocsInDataSource({
|
|||
|
||||
const docs = await listDocsInDataSourceController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
sourceId,
|
||||
});
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ export async function deleteDocFromDataSource({
|
|||
const user = await authCheck();
|
||||
return await deleteDocFromDataSourceController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
docId,
|
||||
});
|
||||
}
|
||||
|
|
@ -174,7 +174,7 @@ export async function getDownloadUrlForFile(
|
|||
|
||||
return await getDownloadUrlForFileController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
fileId,
|
||||
});
|
||||
}
|
||||
|
|
@ -191,7 +191,7 @@ export async function getUploadUrlsForFilesDataSource(
|
|||
|
||||
return await getUploadUrlsForFilesController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
sourceId,
|
||||
files,
|
||||
});
|
||||
|
|
@ -208,7 +208,7 @@ export async function updateDataSource({
|
|||
|
||||
return await updateDataSourceController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
sourceId,
|
||||
data: {
|
||||
description,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export async function listJobs(request: {
|
|||
|
||||
return await listJobsController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId: request.projectId,
|
||||
filters: request.filters,
|
||||
cursor: request.cursor,
|
||||
|
|
@ -35,7 +35,7 @@ export async function fetchJob(request: {
|
|||
|
||||
return await fetchJobController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
jobId: request.jobId,
|
||||
});
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@ export async function createConversation({
|
|||
const controller = container.resolve<ICreatePlaygroundConversationController>("createPlaygroundConversationController");
|
||||
|
||||
return await controller.execute({
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
workflow,
|
||||
isLiveWorkflow,
|
||||
|
|
@ -41,7 +41,7 @@ export async function createCachedTurn({
|
|||
|
||||
const { key } = await createCachedTurnController.execute({
|
||||
caller: "user",
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
conversationId,
|
||||
input: {
|
||||
messages,
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ export async function projectAuthCheck(projectId: string) {
|
|||
const user = await authCheck();
|
||||
await projectActionAuthorizationPolicy.authorize({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
});
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ export async function createProject(formData: FormData): Promise<{ id: string }
|
|||
|
||||
try {
|
||||
const project = await createProjectController.execute({
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
data: {
|
||||
name: name || '',
|
||||
mode: {
|
||||
|
|
@ -94,7 +94,7 @@ export async function createProjectFromWorkflowJson(formData: FormData): Promise
|
|||
|
||||
try {
|
||||
const project = await createProjectController.execute({
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
data: {
|
||||
name: name || '',
|
||||
mode: {
|
||||
|
|
@ -116,7 +116,7 @@ export async function fetchProject(projectId: string): Promise<z.infer<typeof Pr
|
|||
const user = await authCheck();
|
||||
const project = await fetchProjectController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
});
|
||||
|
||||
|
|
@ -134,7 +134,7 @@ export async function listProjects(): Promise<z.infer<typeof Project>[]> {
|
|||
let cursor = undefined;
|
||||
do {
|
||||
const result = await listProjectsController.execute({
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
cursor,
|
||||
});
|
||||
projects.push(...result.items);
|
||||
|
|
@ -148,7 +148,7 @@ export async function rotateSecret(projectId: string): Promise<string> {
|
|||
const user = await authCheck();
|
||||
return await rotateSecretController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
});
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ export async function updateWebhookUrl(projectId: string, url: string) {
|
|||
const user = await authCheck();
|
||||
await updateWebhookUrlController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
url,
|
||||
});
|
||||
|
|
@ -167,7 +167,7 @@ export async function createApiKey(projectId: string): Promise<z.infer<typeof Ap
|
|||
const user = await authCheck();
|
||||
return await createApiKeyController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
});
|
||||
}
|
||||
|
|
@ -176,7 +176,7 @@ export async function deleteApiKey(projectId: string, id: string) {
|
|||
const user = await authCheck();
|
||||
return await deleteApiKeyController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
id,
|
||||
});
|
||||
|
|
@ -186,7 +186,7 @@ export async function listApiKeys(projectId: string): Promise<z.infer<typeof Api
|
|||
const user = await authCheck();
|
||||
return await listApiKeysController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
});
|
||||
}
|
||||
|
|
@ -195,7 +195,7 @@ export async function updateProjectName(projectId: string, name: string) {
|
|||
const user = await authCheck();
|
||||
await updateProjectNameController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
name,
|
||||
});
|
||||
|
|
@ -205,7 +205,7 @@ export async function deleteProject(projectId: string) {
|
|||
const user = await authCheck();
|
||||
await deleteProjectController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
});
|
||||
|
||||
|
|
@ -216,7 +216,7 @@ export async function saveWorkflow(projectId: string, workflow: z.infer<typeof W
|
|||
const user = await authCheck();
|
||||
await updateDraftWorkflowController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
workflow,
|
||||
});
|
||||
|
|
@ -226,7 +226,7 @@ export async function publishWorkflow(projectId: string, workflow: z.infer<typeo
|
|||
const user = await authCheck();
|
||||
await updateLiveWorkflowController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
workflow,
|
||||
});
|
||||
|
|
@ -236,7 +236,7 @@ export async function revertToLiveWorkflow(projectId: string) {
|
|||
const user = await authCheck();
|
||||
await revertToLiveWorkflowController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
});
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@ export async function createRecurringJobRule(request: {
|
|||
|
||||
return await createRecurringJobRuleController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId: request.projectId,
|
||||
input: request.input,
|
||||
cron: request.cron,
|
||||
|
|
@ -43,7 +43,7 @@ export async function listRecurringJobRules(request: {
|
|||
|
||||
return await listRecurringJobRulesController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId: request.projectId,
|
||||
cursor: request.cursor,
|
||||
limit: request.limit,
|
||||
|
|
@ -57,7 +57,7 @@ export async function fetchRecurringJobRule(request: {
|
|||
|
||||
return await fetchRecurringJobRuleController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
ruleId: request.ruleId,
|
||||
});
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ export async function toggleRecurringJobRule(request: {
|
|||
|
||||
return await toggleRecurringJobRuleController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
ruleId: request.ruleId,
|
||||
disabled: request.disabled,
|
||||
});
|
||||
|
|
@ -84,7 +84,7 @@ export async function deleteRecurringJobRule(request: {
|
|||
|
||||
return await deleteRecurringJobRuleController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId: request.projectId,
|
||||
ruleId: request.ruleId,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ export async function createScheduledJobRule(request: {
|
|||
|
||||
return await createScheduledJobRuleController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId: request.projectId,
|
||||
input: request.input,
|
||||
scheduledTime: request.scheduledTime,
|
||||
|
|
@ -41,7 +41,7 @@ export async function listScheduledJobRules(request: {
|
|||
|
||||
return await listScheduledJobRulesController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId: request.projectId,
|
||||
cursor: request.cursor,
|
||||
limit: request.limit,
|
||||
|
|
@ -55,7 +55,7 @@ export async function fetchScheduledJobRule(request: {
|
|||
|
||||
return await fetchScheduledJobRuleController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
ruleId: request.ruleId,
|
||||
});
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ export async function deleteScheduledJobRule(request: {
|
|||
|
||||
return await deleteScheduledJobRuleController.execute({
|
||||
caller: 'user',
|
||||
userId: user._id,
|
||||
userId: user.id,
|
||||
projectId: request.projectId,
|
||||
ruleId: request.ruleId,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue