From df1c5c4cde2c35026f63f84a07c01b9a2c75235a Mon Sep 17 00:00:00 2001 From: develite98 Date: Fri, 5 Jan 2024 10:34:21 +0700 Subject: [PATCH] feat(4ps): fix bug parse permission --- libs/mix-lib/src/model/core/database.model.ts | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/libs/mix-lib/src/model/core/database.model.ts b/libs/mix-lib/src/model/core/database.model.ts index 2abd9299..1b8cfeef 100644 --- a/libs/mix-lib/src/model/core/database.model.ts +++ b/libs/mix-lib/src/model/core/database.model.ts @@ -37,17 +37,23 @@ export class MixDatabase { this.mixDatabaseContextId = value.mixDatabaseContextId ?? DbContextFixId.MasterDb; - this.updatePermissions = value.updatePermissions - ? JSON.parse(value.updatePermissions.toString()) - : []; - this.readPermissions = value.readPermissions - ? JSON.parse(value.readPermissions.toString()) - : []; - this.deletePermissions = value.deletePermissions - ? JSON.parse(value.deletePermissions.toString()) - : []; - this.createPermissions = value.createPermissions - ? JSON.parse(value.createPermissions.toString()) + this.updatePermissions = MixDatabase.parsePermission( + value.updatePermissions + ); + this.readPermissions = MixDatabase.parsePermission(value.readPermissions); + this.deletePermissions = MixDatabase.parsePermission( + value.deletePermissions + ); + this.createPermissions = MixDatabase.parsePermission( + value.createPermissions + ); + } + + public static parsePermission(value: string[] | object | undefined) { + return value instanceof Array + ? value + : value + ? JSON.parse((value as any).toString()) : []; } }