fix(dashboard): duplicate members
This commit is contained in:
@@ -77,14 +77,16 @@ export const onboardingRouter = createTRPCRouter({
|
||||
throw new Error('Organization slug is missing');
|
||||
}
|
||||
|
||||
await db.member.create({
|
||||
data: {
|
||||
email: user.email,
|
||||
organizationId: organization.id,
|
||||
role: 'org:admin',
|
||||
userId: user.id,
|
||||
},
|
||||
});
|
||||
if (input.organization) {
|
||||
await db.member.create({
|
||||
data: {
|
||||
email: user.email,
|
||||
organizationId: organization.id,
|
||||
role: 'org:admin',
|
||||
userId: user.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const project = await db.project.create({
|
||||
data: {
|
||||
|
||||
@@ -130,10 +130,18 @@ export const organizationRouter = createTRPCRouter({
|
||||
z.object({
|
||||
organizationId: z.string(),
|
||||
userId: z.string(),
|
||||
id: z.string(),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
if (ctx.session.userId === input.userId) {
|
||||
const exists = await db.member.count({
|
||||
where: {
|
||||
userId: input.userId,
|
||||
organizationId: input.organizationId,
|
||||
},
|
||||
});
|
||||
|
||||
if (ctx.session.userId === input.userId && exists === 1) {
|
||||
throw new Error('You cannot remove yourself from the organization');
|
||||
}
|
||||
|
||||
@@ -147,8 +155,9 @@ export const organizationRouter = createTRPCRouter({
|
||||
}
|
||||
|
||||
await db.$transaction([
|
||||
db.member.deleteMany({
|
||||
db.member.delete({
|
||||
where: {
|
||||
id: input.id,
|
||||
userId: input.userId,
|
||||
organizationId: input.organizationId,
|
||||
},
|
||||
@@ -171,6 +180,10 @@ export const organizationRouter = createTRPCRouter({
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
if (input.userId === ctx.session.userId) {
|
||||
throw TRPCAccessError('You cannot update your own access');
|
||||
}
|
||||
|
||||
const access = await getOrganizationAccess({
|
||||
userId: ctx.session.userId,
|
||||
organizationId: input.organizationSlug,
|
||||
|
||||
Reference in New Issue
Block a user