Allow user to change projects
This commit is contained in:
@@ -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;
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user