This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a16df6
commit 26c0c0e
Showing
5 changed files
with
149 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
Param, | ||
ParseIntPipe, | ||
Patch, | ||
Query, | ||
} from '@nestjs/common'; | ||
import { memberships } from '@prisma/client'; | ||
import { Expose } from 'src/modules/prisma/prisma.interface'; | ||
import { CursorPipe } from 'src/pipes/cursor.pipe'; | ||
import { OptionalIntPipe } from 'src/pipes/optional-int.pipe'; | ||
import { OrderByPipe } from 'src/pipes/order-by.pipe'; | ||
import { WherePipe } from 'src/pipes/where.pipe'; | ||
import { Scopes } from '../auth/scope.decorator'; | ||
import { UpdateMembershipDto } from './memberships.dto'; | ||
import { MembershipsService } from './memberships.service'; | ||
|
||
@Controller('groups/:groupId/memberships') | ||
export class GroupMembershipController { | ||
constructor(private membershipsService: MembershipsService) {} | ||
|
||
@Get() | ||
@Scopes('group-{groupId}:read-membership') | ||
async getAll( | ||
@Param('groupId', ParseIntPipe) groupId: number, | ||
@Query('skip', OptionalIntPipe) skip?: number, | ||
@Query('take', OptionalIntPipe) take?: number, | ||
@Query('cursor', CursorPipe) cursor?: Record<string, number | string>, | ||
@Query('where', WherePipe) where?: Record<string, number | string>, | ||
@Query('orderBy', OrderByPipe) orderBy?: Record<string, 'asc' | 'desc'>, | ||
): Promise<Expose<memberships>[]> { | ||
return this.membershipsService.getMemberships({ | ||
skip, | ||
take, | ||
orderBy, | ||
cursor, | ||
where: { ...where, group: { id: groupId } }, | ||
}); | ||
} | ||
|
||
@Get(':id') | ||
@Scopes('group-{groupId}:read-membership-{id}') | ||
async get( | ||
@Param('groupId', ParseIntPipe) groupId: number, | ||
@Param('id', ParseIntPipe) id: number, | ||
): Promise<Expose<memberships>> { | ||
return this.membershipsService.getGroupMembership(groupId, Number(id)); | ||
} | ||
|
||
@Patch(':id') | ||
@Scopes('group-{groupId}:read-membership-{id}') | ||
async update( | ||
@Body() data: UpdateMembershipDto, | ||
@Param('groupId', ParseIntPipe) groupId: number, | ||
@Param('id', ParseIntPipe) id: number, | ||
): Promise<Expose<memberships>> { | ||
return this.membershipsService.updateGroupMembership( | ||
groupId, | ||
Number(id), | ||
data, | ||
); | ||
} | ||
|
||
@Delete(':id') | ||
@Scopes('group-{groupId}:delete-membership-{id}') | ||
async remove( | ||
@Param('groupId', ParseIntPipe) groupId: number, | ||
@Param('id', ParseIntPipe) id: number, | ||
): Promise<Expose<memberships>> { | ||
return this.membershipsService.deleteGroupMembership(groupId, Number(id)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { IsIn, IsOptional, IsString } from 'class-validator'; | ||
|
||
export class UpdateMembershipDto { | ||
@IsString() | ||
@IsIn(['OWNER', 'ADMIN', 'MEMBER']) | ||
@IsOptional() | ||
role?: 'OWNER' | 'ADMIN' | 'MEMBER'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { PrismaModule } from '../prisma/prisma.module'; | ||
import { GroupMembershipController } from './memberships-group.controller'; | ||
import { UserMembershipController } from './memberships-user.controller'; | ||
import { MembershipsService } from './memberships.service'; | ||
|
||
@Module({ | ||
imports: [PrismaModule], | ||
controllers: [UserMembershipController], | ||
controllers: [UserMembershipController, GroupMembershipController], | ||
providers: [MembershipsService], | ||
}) | ||
export class MembershipsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters