{"version":3,"file":"user-permissions.mjs","names":[],"sources":["../../../src/libs/formatters/user-permissions.ts"],"sourcesContent":["import type { UserPermission } from \"../../types/response.js\";\nimport type { Permission } from \"../../types.js\";\n\ninterface UserPermissionRolesPropsT {\n\tid: number;\n\tname?: string | null;\n\ttranslations?: {\n\t\tname: string | null;\n\t\tlocale_code: string | null;\n\t}[];\n\tpermissions?: {\n\t\tpermission: string;\n\t}[];\n}\n\nconst formatMultiple = (props: {\n\troles: UserPermissionRolesPropsT[];\n\tdefaultLocale: string;\n}): UserPermission => {\n\tif (!props.roles) {\n\t\treturn {\n\t\t\troles: [],\n\t\t\tpermissions: [],\n\t\t};\n\t}\n\n\tconst permissionsSet: Set<Permission> = new Set();\n\n\tfor (const role of props.roles) {\n\t\tif (!role.permissions) continue;\n\t\tfor (const permission of role.permissions) {\n\t\t\tpermissionsSet.add(permission.permission as Permission);\n\t\t}\n\t}\n\n\treturn {\n\t\troles: props.roles.map(({ id, name, translations }) => ({\n\t\t\tid,\n\t\t\tname:\n\t\t\t\tname ??\n\t\t\t\ttranslations?.find(\n\t\t\t\t\t(translation) => translation.locale_code === props.defaultLocale,\n\t\t\t\t)?.name ??\n\t\t\t\ttranslations?.find((translation) => translation.name !== null)?.name ??\n\t\t\t\t\"\",\n\t\t})),\n\t\tpermissions: Array.from(permissionsSet),\n\t};\n};\n\nexport default {\n\tformatMultiple,\n};\n"],"mappings":"AAkDA,IAAA,EAAe,CACd,eApCuB,GAGF,CACrB,GAAI,CAAC,EAAM,MACV,MAAO,CACN,MAAO,CAAC,EACR,YAAa,CAAC,CACf,EAGD,IAAM,EAAkC,IAAI,IAE5C,IAAK,IAAM,KAAQ,EAAM,MACnB,KAAK,YACV,IAAK,IAAM,KAAc,EAAK,YAC7B,EAAe,IAAI,EAAW,UAAwB,EAIxD,MAAO,CACN,MAAO,EAAM,MAAM,KAAK,CAAE,KAAI,OAAM,mBAAoB,CACvD,KACA,KACC,GACA,GAAc,KACZ,GAAgB,EAAY,cAAgB,EAAM,aACpD,CAAC,EAAE,MACH,GAAc,KAAM,GAAgB,EAAY,OAAS,IAAI,CAAC,EAAE,MAChE,EACF,EAAE,EACF,YAAa,MAAM,KAAK,CAAc,CACvC,CACD,CAIA"}