|
|
@@ -363,7 +363,19 @@ export abstract class GenericCrudService<T extends ObjectLiteral> {
|
|
|
/**
|
|
|
* 删除实体
|
|
|
*/
|
|
|
- async delete(id: number): Promise<boolean> {
|
|
|
+ async delete(id: number, userId?: string | number): Promise<boolean> {
|
|
|
+ // 权限验证
|
|
|
+ if (this.dataPermissionOptions?.enabled && userId) {
|
|
|
+ const entity = await this.getById(id);
|
|
|
+ if (!entity) return false;
|
|
|
+
|
|
|
+ const hasPermission = await this.checkPermission(entity, userId);
|
|
|
+ if (!hasPermission) {
|
|
|
+ throw new Error('无权删除该资源');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行删除
|
|
|
const result = await this.repository.delete(id);
|
|
|
return result.affected === 1;
|
|
|
}
|