Skip to content

Commit f4bc424

Browse files
committed
update schema
1 parent f5b677b commit f4bc424

File tree

19 files changed

+105
-51
lines changed

19 files changed

+105
-51
lines changed

apps/web/client/src/components/store/editor/chat/conversation.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,7 @@ export class ConversationManager {
196196
}
197197

198198
async updateConversationInStorage(conversation: Partial<ChatConversation> & { id: string }) {
199-
await api.chat.conversation.update.mutate({
200-
conversationId: conversation.id,
201-
conversation,
202-
});
199+
await api.chat.conversation.update.mutate(conversation);
203200
}
204201

205202
async deleteConversationInStorage(id: string) {

apps/web/client/src/components/ui/settings-modal/project/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const ProjectTab = observer(() => {
6060
if (formData.name !== name) {
6161
await updateProject({
6262
id: editorEngine.projectId,
63-
project: { name: formData.name }
63+
name: formData.name,
6464
});
6565
// Invalidate queries to refresh UI
6666
await Promise.all([

apps/web/client/src/server/api/root.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
userCanvasRouter,
1818
userRouter,
1919
} from './routers';
20+
import { branchRouter } from './routers/project/branch';
2021

2122
/**
2223
* This is the primary router for your server.

apps/web/client/src/server/api/routers/chat/conversation.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,13 @@ export const conversationRouter = createTRPCRouter({
4343
return fromDbConversation(conversation);
4444
}),
4545
update: protectedProcedure
46-
.input(z.object({
47-
conversationId: z.string(),
48-
conversation: conversationUpdateSchema,
49-
}))
46+
.input(conversationUpdateSchema)
5047
.mutation(async ({ ctx, input }) => {
5148
const [conversation] = await ctx.db.update({
5249
...conversations,
5350
updatedAt: new Date(),
54-
}).set(input.conversation)
55-
.where(eq(conversations.id, input.conversationId)).returning();
51+
}).set(input)
52+
.where(eq(conversations.id, input.id)).returning();
5653
if (!conversation) {
5754
throw new Error('Conversation not updated');
5855
}

apps/web/client/src/server/api/routers/project/branch.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { branches, branchInsertSchema, branchUpdateSchema, frames, fromDbBranch } from '@onlook/db';
1+
import { branches, branchInsertSchema, branchUpdateSchema, fromDbBranch } from '@onlook/db';
2+
import { TRPCError } from '@trpc/server';
23
import { eq } from 'drizzle-orm';
34
import { z } from 'zod';
45
import { createTRPCRouter, protectedProcedure } from '../../trpc';
56

67
export const branchRouter = createTRPCRouter({
7-
88
getByProjectId: protectedProcedure
99
.input(
1010
z.object({
@@ -15,6 +15,12 @@ export const branchRouter = createTRPCRouter({
1515
const dbBranch = await ctx.db.query.branches.findFirst({
1616
where: eq(branches.projectId, input.projectId),
1717
});
18+
if (!dbBranch) {
19+
throw new TRPCError({
20+
code: 'NOT_FOUND',
21+
message: 'Branch not found',
22+
});
23+
}
1824
return fromDbBranch(dbBranch);
1925
}),
2026
create: protectedProcedure
@@ -45,12 +51,12 @@ export const branchRouter = createTRPCRouter({
4551
delete: protectedProcedure
4652
.input(
4753
z.object({
48-
frameId: z.string(),
54+
branchId: z.string().uuid(),
4955
}),
5056
)
5157
.mutation(async ({ ctx, input }) => {
5258
try {
53-
await ctx.db.delete(frames).where(eq(frames.id, input.frameId));
59+
await ctx.db.delete(branches).where(eq(branches.id, input.branchId));
5460
return true;
5561
} catch (error) {
5662
console.error('Error deleting frame', error);

apps/web/client/src/server/api/routers/project/frame.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,13 @@ export const frameRouter = createTRPCRouter({
4141
return false;
4242
}
4343
}),
44-
update: protectedProcedure.input(z.object({
45-
frameId: z.string(),
46-
frame: frameUpdateSchema,
47-
})).mutation(async ({ ctx, input }) => {
44+
update: protectedProcedure.input(frameUpdateSchema).mutation(async ({ ctx, input }) => {
4845
try {
4946
await ctx.db
5047
.update(frames)
51-
.set(input.frame)
48+
.set(input)
5249
.where(
53-
eq(frames.id, input.frameId)
50+
eq(frames.id, input.id)
5451
);
5552
return true;
5653
} catch (error) {

apps/web/client/src/server/api/routers/project/project.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import {
1010
createDefaultFrame,
1111
createDefaultUserCanvas,
1212
frames,
13-
toDbPreviewImg,
13+
fromDbCanvas,
14+
fromDbFrame,
15+
fromDbProject,
1416
projectCreateRequestInsertSchema,
1517
projectCreateRequests,
1618
projectInsertSchema,
1719
projects,
1820
projectUpdateSchema,
19-
fromDbCanvas,
20-
fromDbFrame,
21-
fromDbProject,
21+
toDbPreviewImg,
2222
userCanvases,
2323
userProjects,
2424
type Canvas,
@@ -349,14 +349,17 @@ export const projectRouter = createTRPCRouter({
349349
});
350350
return projects.map((project) => fromDbProject(project.project));
351351
}),
352-
update: protectedProcedure.input(z.object({
353-
id: z.string(),
354-
project: projectUpdateSchema,
355-
})).mutation(async ({ ctx, input }) => {
356-
await ctx.db.update(projects).set({
357-
...input.project,
352+
update: protectedProcedure.input(projectUpdateSchema).mutation(async ({ ctx, input }) => {
353+
const [updatedProject] = await ctx.db.update(projects).set({
354+
...input,
358355
updatedAt: new Date(),
359-
}).where(eq(projects.id, input.id));
356+
}).where(
357+
eq(projects.id, input.id)
358+
).returning();
359+
if (!updatedProject) {
360+
throw new Error('Project not found');
361+
}
362+
return fromDbProject(updatedProject);
360363
}),
361364
addTag: protectedProcedure.input(z.object({
362365
projectId: z.string(),

apps/web/client/src/server/api/routers/publish/deployment.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,8 @@ export const deploymentRouter = createTRPCRouter({
2525
});
2626
return deployment ?? null;
2727
}),
28-
update: protectedProcedure.input(z.object({
29-
deploymentId: z.string(),
30-
deployment: deploymentUpdateSchema
31-
})).mutation(async ({ ctx, input }) => {
32-
const { deploymentId, deployment } = input;
33-
return await updateDeployment(ctx.db, deploymentId, deployment);
28+
update: protectedProcedure.input(deploymentUpdateSchema).mutation(async ({ ctx, input }) => {
29+
return await updateDeployment(ctx.db, input);
3430
}),
3531
create: protectedProcedure.input(z.object({
3632
projectId: z.string(),
@@ -108,13 +104,15 @@ export const deploymentRouter = createTRPCRouter({
108104
db: ctx.db,
109105
deployment: existingDeployment,
110106
});
111-
await updateDeployment(ctx.db, deploymentId, {
107+
await updateDeployment(ctx.db, {
108+
id: deploymentId,
112109
status: DeploymentStatus.COMPLETED,
113110
message: 'Deployment Success!',
114111
});
115112
} catch (error) {
116113
console.error(error);
117-
await updateDeployment(ctx.db, deploymentId, {
114+
await updateDeployment(ctx.db, {
115+
id: deploymentId,
118116
status: DeploymentStatus.FAILED,
119117
message: 'Failed to publish deployment',
120118
});
@@ -125,7 +123,8 @@ export const deploymentRouter = createTRPCRouter({
125123
deploymentId: z.string(),
126124
})).mutation(async ({ ctx, input }) => {
127125
const { deploymentId } = input;
128-
await updateDeployment(ctx.db, deploymentId, {
126+
await updateDeployment(ctx.db, {
127+
id: deploymentId,
129128
status: DeploymentStatus.CANCELLED,
130129
message: 'Cancelled by user',
131130
});

apps/web/client/src/server/api/routers/publish/helpers/helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ export async function getSandboxId(db: DrizzleDb, projectId: string): Promise<st
5252
return project.sandboxId;
5353
}
5454

55-
export async function updateDeployment(db: DrizzleDb, deploymentId: string, deployment: z.infer<typeof deploymentUpdateSchema>): Promise<Deployment | null> {
55+
export async function updateDeployment(db: DrizzleDb, deployment: z.infer<typeof deploymentUpdateSchema>): Promise<Deployment | null> {
5656
try {
5757
const [result] = await db.update(deployments).set({
5858
...deployment,
5959
type: deployment.type as DeploymentType,
6060
status: deployment.status as DeploymentStatus
6161
}).where(
6262
and(
63-
eq(deployments.id, deploymentId),
63+
eq(deployments.id, deployment.id),
6464
ne(deployments.status, DeploymentStatus.CANCELLED)
6565
)
6666
).returning();
6767
return result ?? null;
6868
} catch (error) {
69-
console.error(`Failed to update deployment ${deploymentId}:`, error);
69+
console.error(`Failed to update deployment ${deployment.id}:`, error);
7070
return null;
7171
}
7272
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import type { Branch } from '@onlook/models';
2+
import type { Branch as DbBranch } from '../../schema';
3+
4+
export const fromDbBranch = (dbBranch: DbBranch): Branch => {
5+
return {
6+
id: dbBranch.id,
7+
projectId: dbBranch.projectId,
8+
name: dbBranch.name,
9+
description: dbBranch.description,
10+
createdAt: dbBranch.createdAt,
11+
updatedAt: dbBranch.updatedAt,
12+
isDefault: dbBranch.isDefault,
13+
git: {
14+
branch: dbBranch.gitBranch,
15+
commitSha: dbBranch.gitCommitSha,
16+
repoUrl: dbBranch.gitRepoUrl,
17+
},
18+
sandbox: {
19+
id: dbBranch.sandboxId,
20+
},
21+
};
22+
};
23+
24+
export const toDbBranch = (branch: Branch): DbBranch => {
25+
return {
26+
id: branch.id,
27+
name: branch.name,
28+
projectId: branch.projectId,
29+
description: branch.description,
30+
createdAt: branch.createdAt,
31+
updatedAt: branch.updatedAt,
32+
isDefault: branch.isDefault,
33+
gitBranch: branch.git?.branch ?? null,
34+
gitCommitSha: branch.git?.commitSha ?? null,
35+
gitRepoUrl: branch.git?.repoUrl ?? null,
36+
sandboxId: branch.sandbox.id,
37+
};
38+
};

0 commit comments

Comments
 (0)