fix: Org slight

This commit is contained in:
SauravDhakal
2026-04-02 21:51:46 +05:45
parent 349196b801
commit 68135ae022
3 changed files with 13 additions and 4 deletions

View File

@@ -9,7 +9,7 @@ import { Authorization } from 'src/auth/decorators';
/* NOTE: Regarding endpoint path naming
* - Since we follow REST style, endpoint are resource based.
* - So insted of /organization/:orgId/invitation-action, we user ..../invitation/:invitationId
* (invitationid points to a resource)
* (invitationId points to a resource)
* */
@Controller('membership')

View File

@@ -45,8 +45,10 @@ export class OrganizationMembershipService {
where: {
orgId,
userId,
status: ORGANIZATION_JOIN_REQUEST.PENDING
},
orderBy: {
requestedOn: "desc"
}
}),
this.prisma.organizationUserJoinTable.findFirst({
where: {
@@ -59,7 +61,7 @@ export class OrganizationMembershipService {
if (!orgExists)
throw new NotFoundException("Organization")
if (invitationAlreadySent)
if (invitationAlreadySent?.status === "PENDING")
throw new BadRequestException("Invitation to join this organization already sent")
if (userAlreadyPartOf)
throw new BadRequestException("User already part of the organization")
@@ -85,7 +87,8 @@ export class OrganizationMembershipService {
where: {
id,
userId,
orgId
orgId,
status: ORGANIZATION_JOIN_REQUEST.PENDING,
},
data: {
status: ORGANIZATION_JOIN_REQUEST.CANCELLED,
@@ -116,6 +119,7 @@ export class OrganizationMembershipService {
where: {
userId,
requestType: joinReqType,
status: ORGANIZATION_JOIN_REQUEST.PENDING
},
include: { user: { select: { firstName: true, email: true } } }
})
@@ -152,6 +156,8 @@ export class OrganizationMembershipService {
id,
userId,
orgId,
status: ORGANIZATION_JOIN_REQUEST.PENDING,
requestType: ORGANIZATION_JOIN_REQUEST_TYPE.REQUESTED
},
data: {
status: userAction,
@@ -173,6 +179,7 @@ export class OrganizationMembershipService {
});
}
catch (err) {
console.log(err)
if (err instanceof Prisma.PrismaClientKnownRequestError) {
if (err.code === 'P2002')
throw new BadRequestException('User already part of this organization.');