mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-12 22:26:08 -04:00
optimize readability of find calls
Signed-off-by: Yannick Bungers <git@innay.de>
This commit is contained in:
parent
70d7ca5475
commit
f096d706c8
1 changed files with 19 additions and 27 deletions
|
@ -226,18 +226,15 @@ export class PermissionsService {
|
||||||
canEdit: boolean,
|
canEdit: boolean,
|
||||||
): Promise<Note> {
|
): Promise<Note> {
|
||||||
const permissions = await note.userPermissions;
|
const permissions = await note.userPermissions;
|
||||||
const permission = permissions.find(
|
let permissionIndex = 0;
|
||||||
(value: NoteUserPermission, index: number) => {
|
const permission = permissions.find((value, index) => {
|
||||||
if (value.user.id == permissionUser.id) {
|
permissionIndex = index;
|
||||||
if (value.canEdit != canEdit) {
|
return value.user.id == permissionUser.id;
|
||||||
value.canEdit = canEdit;
|
});
|
||||||
permissions[index] = value;
|
if (permission != undefined) {
|
||||||
}
|
permission.canEdit = canEdit;
|
||||||
return true;
|
permissions[permissionIndex] = permission;
|
||||||
}
|
} else {
|
||||||
},
|
|
||||||
);
|
|
||||||
if (permission == undefined) {
|
|
||||||
const noteUserPermission = NoteUserPermission.create(
|
const noteUserPermission = NoteUserPermission.create(
|
||||||
permissionUser,
|
permissionUser,
|
||||||
note,
|
note,
|
||||||
|
@ -258,9 +255,7 @@ export class PermissionsService {
|
||||||
async removeUserPermission(note: Note, permissionUser: User): Promise<Note> {
|
async removeUserPermission(note: Note, permissionUser: User): Promise<Note> {
|
||||||
const permissions = await note.userPermissions;
|
const permissions = await note.userPermissions;
|
||||||
const permissionsFiltered = permissions.filter(
|
const permissionsFiltered = permissions.filter(
|
||||||
(value: NoteUserPermission) => {
|
(value) => value.user.id != permissionUser.id,
|
||||||
return value.user.id != permissionUser.id;
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
note.userPermissions = Promise.resolve(permissionsFiltered);
|
note.userPermissions = Promise.resolve(permissionsFiltered);
|
||||||
return await this.noteRepository.save(note);
|
return await this.noteRepository.save(note);
|
||||||
|
@ -280,18 +275,15 @@ export class PermissionsService {
|
||||||
canEdit: boolean,
|
canEdit: boolean,
|
||||||
): Promise<Note> {
|
): Promise<Note> {
|
||||||
const permissions = await note.groupPermissions;
|
const permissions = await note.groupPermissions;
|
||||||
const permission = permissions.find(
|
let permissionIndex = 0;
|
||||||
(value: NoteGroupPermission, index: number) => {
|
const permission = permissions.find((value, index) => {
|
||||||
if (value.group.id == permissionGroup.id) {
|
permissionIndex = index;
|
||||||
if (value.canEdit != canEdit) {
|
return value.group.id == permissionGroup.id;
|
||||||
value.canEdit = canEdit;
|
});
|
||||||
permissions[index] = value;
|
if (permission != undefined) {
|
||||||
}
|
permission.canEdit = canEdit;
|
||||||
return true;
|
permissions[permissionIndex] = permission;
|
||||||
}
|
} else {
|
||||||
},
|
|
||||||
);
|
|
||||||
if (permission == undefined) {
|
|
||||||
const noteGroupPermission = NoteGroupPermission.create(
|
const noteGroupPermission = NoteGroupPermission.create(
|
||||||
permissionGroup,
|
permissionGroup,
|
||||||
note,
|
note,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue