diff --git a/infra/db/docker-compose.yml b/infra/db/docker-compose.yml index 66a2678..6c23443 100644 --- a/infra/db/docker-compose.yml +++ b/infra/db/docker-compose.yml @@ -10,6 +10,8 @@ services: - '5454:5432' volumes: - multiTenant:/var/lib/postgresql + restart: unless-stopped + volumes: multiTenant: diff --git a/src/organization-membership/organization-membership.controller.ts b/src/organization-membership/organization-membership.controller.ts index 9b265aa..a4eab37 100644 --- a/src/organization-membership/organization-membership.controller.ts +++ b/src/organization-membership/organization-membership.controller.ts @@ -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') diff --git a/src/organization-membership/organization-membership.service.ts b/src/organization-membership/organization-membership.service.ts index a315fde..3044536 100644 --- a/src/organization-membership/organization-membership.service.ts +++ b/src/organization-membership/organization-membership.service.ts @@ -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.');