|
|
@@ -322,6 +322,17 @@ export abstract class GenericCrudService<T extends ObjectLiteral> {
|
|
|
* 更新实体
|
|
|
*/
|
|
|
async update(id: number, data: Partial<T>, userId?: string | number): Promise<T | null> {
|
|
|
+ // 权限验证
|
|
|
+ if (this.dataPermissionOptions?.enabled && userId) {
|
|
|
+ const entity = await this.getById(id);
|
|
|
+ if (!entity) return null;
|
|
|
+
|
|
|
+ const hasPermission = await this.checkPermission(entity, userId);
|
|
|
+ if (!hasPermission) {
|
|
|
+ throw new Error('无权更新该资源');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
const updateData = { ...data };
|
|
|
this.setUserFields(updateData, userId, false);
|
|
|
|