UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 2.38 kB
{"version":3,"file":"roles.mjs","names":["formatter"],"sources":["../../../src/libs/formatters/roles.ts"],"sourcesContent":["import type { Role } from \"../../types/response.js\";\nimport type { BooleanInt } from \"../db/types.js\";\nimport type { Permission } from \"../permission/types.js\";\nimport formatter from \"./index.js\";\n\ninterface RolePropsT {\n\tid: number;\n\tkey: string | null;\n\tlocked: BooleanInt;\n\ttenant_key: string | null;\n\ttranslations?: Array<{\n\t\tname: string | null;\n\t\tdescription: string | null;\n\t\tlocale_code: string;\n\t}>;\n\tupdated_at: Date | string | null;\n\tcreated_at: Date | string | null;\n\tpermissions?: {\n\t\tid: number;\n\t\tpermission: string;\n\t\trole_id: number;\n\t}[];\n}\n\nconst formatMultiple = (props: { roles: RolePropsT[] }) => {\n\treturn props.roles.map((r) =>\n\t\tformatSingle({\n\t\t\trole: r,\n\t\t}),\n\t);\n};\n\nconst formatSingle = (props: { role: RolePropsT }): Role => {\n\treturn {\n\t\tid: props.role.id,\n\t\tkey: props.role.key,\n\t\ttenantKey: props.role.tenant_key,\n\t\tname:\n\t\t\tprops.role.translations?.map((translation) => ({\n\t\t\t\tvalue: translation.name,\n\t\t\t\tlocaleCode: translation.locale_code,\n\t\t\t})) ?? [],\n\t\tdescription:\n\t\t\tprops.role.translations?.map((translation) => ({\n\t\t\t\tvalue: translation.description,\n\t\t\t\tlocaleCode: translation.locale_code,\n\t\t\t})) ?? [],\n\t\tlocked: formatter.formatBoolean(props.role.locked),\n\t\tpermissions: props.role.permissions?.map((p) => {\n\t\t\treturn {\n\t\t\t\tid: p.id,\n\t\t\t\tpermission: p.permission as Permission,\n\t\t\t};\n\t\t}),\n\t\tcreatedAt: formatter.formatDate(props.role.created_at),\n\t\tupdatedAt: formatter.formatDate(props.role.updated_at),\n\t};\n};\n\nexport default {\n\tformatMultiple,\n\tformatSingle,\n};\n"],"mappings":"2BAwBA,MAAM,EAAkB,GAChB,EAAM,MAAM,IAAK,GACvB,EAAa,CACZ,KAAM,CACP,CAAC,CACF,EAGK,EAAgB,IACd,CACN,GAAI,EAAM,KAAK,GACf,IAAK,EAAM,KAAK,IAChB,UAAW,EAAM,KAAK,WACtB,KACC,EAAM,KAAK,cAAc,IAAK,IAAiB,CAC9C,MAAO,EAAY,KACnB,WAAY,EAAY,WACzB,EAAE,GAAK,CAAC,EACT,YACC,EAAM,KAAK,cAAc,IAAK,IAAiB,CAC9C,MAAO,EAAY,YACnB,WAAY,EAAY,WACzB,EAAE,GAAK,CAAC,EACT,OAAQA,EAAU,cAAc,EAAM,KAAK,MAAM,EACjD,YAAa,EAAM,KAAK,aAAa,IAAK,IAClC,CACN,GAAI,EAAE,GACN,WAAY,EAAE,UACf,EACA,EACD,UAAWA,EAAU,WAAW,EAAM,KAAK,UAAU,EACrD,UAAWA,EAAU,WAAW,EAAM,KAAK,UAAU,CACtD,GAGD,IAAA,EAAe,CACd,iBACA,cACD"}