Skip to content

Commit 406b11d

Browse files
committed
feat(permissions): add deletion API
1 parent c027992 commit 406b11d

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/permissions/permissions.controller.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Body, Controller, Get, Param, Patch, Req } from '@nestjs/common';
1+
import {
2+
Body,
3+
Controller,
4+
Delete,
5+
Get,
6+
Param,
7+
Patch,
8+
Req,
9+
} from '@nestjs/common';
210
import { PermissionsService } from './permissions.service';
311
import { PermissionDto } from './dto/permission.dto';
412

@@ -62,6 +70,20 @@ export class PermissionsController {
6270
);
6371
}
6472

73+
@Delete('groups/:groupId')
74+
async deleteGroupPermission(
75+
@Req() req,
76+
@Param('namespaceId') namespaceId: string,
77+
@Param('resourceId') resourceId: string,
78+
@Param('groupId') groupId: string,
79+
) {
80+
await this.permissionsService.deleteGroupPermission(
81+
namespaceId,
82+
resourceId,
83+
groupId,
84+
);
85+
}
86+
6587
@Get('users/:userId')
6688
async getUserPermission(
6789
@Req() req,
@@ -91,4 +113,18 @@ export class PermissionsController {
91113
permissionDto,
92114
);
93115
}
116+
117+
@Delete('users/:userId')
118+
async deleteUserPermission(
119+
@Req() req,
120+
@Param('namespaceId') namespaceId: string,
121+
@Param('resourceId') resourceId: string,
122+
@Param('userId') userId: string,
123+
) {
124+
await this.permissionsService.deleteUserPermission(
125+
namespaceId,
126+
resourceId,
127+
userId,
128+
);
129+
}
94130
}

src/permissions/permissions.service.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class PermissionsService {
7878
await this.dataSource.transaction(async (manager) => {
7979
const result = await manager.update(
8080
GroupPermission,
81-
{ namespaceId, resourceId, groupId },
81+
{ namespaceId, resourceId, groupId, deletedAt: IsNull() },
8282
{ level },
8383
);
8484
if (result.affected === 0) {
@@ -94,6 +94,14 @@ export class PermissionsService {
9494
});
9595
}
9696

97+
async deleteGroupPermission(
98+
namespaceId: string,
99+
resourceId: string,
100+
groupId: string,
101+
) {
102+
await this.groupPermiRepo.delete({ namespaceId, resourceId, groupId });
103+
}
104+
97105
async getUserPermission(
98106
namespaceId: string,
99107
resourceId: string,
@@ -131,4 +139,12 @@ export class PermissionsService {
131139
}
132140
});
133141
}
142+
143+
async deleteUserPermission(
144+
namespaceId: string,
145+
resourceId: string,
146+
userId: string,
147+
) {
148+
await this.userPermiRepo.delete({ namespaceId, resourceId, userId });
149+
}
134150
}

0 commit comments

Comments
 (0)