Skip to content

Commit

Permalink
Automatically donate key to new projects
Browse files Browse the repository at this point in the history
  • Loading branch information
cephalization committed Oct 19, 2023
1 parent ce2aafe commit d661c52
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
15 changes: 14 additions & 1 deletion apps/web/src/routes/(app)/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ export const actions = {
});
}

await queries.Project.createProject(userId, name);
const project = await queries.Project.createProject(userId, name);

if (!project) {
return fail(400, {
createProject: {
success: false,
errors: {
general: 'Could not create project'
}
}
});
}

await queries.Project.donateKey(project.id, userId);

return { createProject: { success: true } };
},
Expand Down
20 changes: 14 additions & 6 deletions packages/database/queries/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,20 @@ export class ProjectQueries {
return null;
}

await tx.insert(usersInProjects).values({
userId,
projectId: newProject[0].id,
admin: true,
updatedAt: getCurrentDateInUTC(),
});
const uip = await tx
.insert(usersInProjects)
.values({
userId,
projectId: newProject[0].id,
admin: true,
updatedAt: getCurrentDateInUTC(),
})
.returning();

if (uip.length === 0) {
tx.rollback();
return null;
}

return newProject[0];
});
Expand Down

0 comments on commit d661c52

Please sign in to comment.