Allow user to change projects

This commit is contained in:
David Corbitt
2023-08-07 15:18:23 -07:00
parent c0f10cd522
commit d220cd30e8
3 changed files with 172 additions and 30 deletions

View File

@@ -22,7 +22,7 @@ export const organizationsRouter = createTRPCRouter({
},
},
orderBy: {
createdAt: "desc",
createdAt: "asc",
},
});
@@ -63,7 +63,7 @@ export const organizationsRouter = createTRPCRouter({
},
include: {
apiKeys: true,
}
},
});
}),
update: protectedProcedure
@@ -79,4 +79,33 @@ export const organizationsRouter = createTRPCRouter({
},
});
}),
create: protectedProcedure
.input(z.object({ name: z.string() }))
.mutation(async ({ input, ctx }) => {
requireNothing(ctx);
const newOrgId = uuidv4();
const [newOrg] = await prisma.$transaction([
prisma.organization.create({
data: {
id: newOrgId,
name: input.name,
},
}),
prisma.organizationUser.create({
data: {
userId: ctx.session.user.id,
organizationId: newOrgId,
role: "ADMIN",
},
}),
prisma.apiKey.create({
data: {
name: "Default API Key",
organizationId: newOrgId,
apiKey: generateApiKey(),
},
}),
]);
return newOrg;
}),
});