{"version":3,"file":"get-single.mjs","names":["usersFormatter"],"sources":["../../../src/services/users/get-single.ts"],"sourcesContent":["import type { QueryBuilderWhere } from \"../../libs/db/query-builder/index.js\";\nimport { usersFormatter } from \"../../libs/formatters/index.js\";\nimport { copy } from \"../../libs/i18n/index.js\";\nimport { UsersRepository } from \"../../libs/repositories/index.js\";\nimport type { LucidAuth } from \"../../types/hono.js\";\nimport type { User } from \"../../types/response.js\";\nimport { getBaseUrl } from \"../../utils/helpers/index.js\";\nimport type { ServiceFn } from \"../../utils/services/types.js\";\n\nconst getSingle: ServiceFn<\n\t[\n\t\t{\n\t\t\tuserId: number;\n\t\t\t/** When true, it will only return users that are active and not soft-deleted  */\n\t\t\tactiveUser?: boolean;\n\t\t\tauthUser: LucidAuth;\n\t\t},\n\t],\n\tUser\n> = async (context, data) => {\n\tconst Users = new UsersRepository(context.db.client, context.config.db);\n\n\tconst userQueryWhere: QueryBuilderWhere<\"lucid_users\"> = [\n\t\t{\n\t\t\tkey: \"id\",\n\t\t\toperator: \"=\",\n\t\t\tvalue: data.userId,\n\t\t},\n\t];\n\tif (data.activeUser) {\n\t\tuserQueryWhere.push({\n\t\t\tkey: \"is_deleted\",\n\t\t\toperator: \"=\",\n\t\t\tvalue: context.config.db.getDefault(\"boolean\", \"false\"),\n\t\t});\n\t}\n\n\tconst userRes = await Users.selectSinglePreset({\n\t\ttenantKey: context.request.tenantKey,\n\t\twhere: userQueryWhere,\n\t\tvalidation: {\n\t\t\tenabled: true,\n\t\t\tdefaultError: {\n\t\t\t\tmessage: copy(\"server:core.user.not.found.message\"),\n\t\t\t\tstatus: 404,\n\t\t\t},\n\t\t},\n\t});\n\tif (userRes.error) return userRes;\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: usersFormatter.formatSingle({\n\t\t\tuser: userRes.data,\n\t\t\tauthUser: data.authUser,\n\t\t\thost: getBaseUrl(context),\n\t\t\tlocales: context.config.localization.locales.map((locale) => locale.code),\n\t\t\tdefaultLocale: context.config.localization.defaultLocale,\n\t\t\ttenants: context.config.tenants,\n\t\t}),\n\t};\n};\n\nexport default getSingle;\n"],"mappings":"oMASA,MAAM,EAUF,MAAO,EAAS,IAAS,CAC5B,IAAM,EAAQ,IAAI,EAAgB,EAAQ,GAAG,OAAQ,EAAQ,OAAO,EAAE,EAEhE,EAAmD,CACxD,CACC,IAAK,KACL,SAAU,IACV,MAAO,EAAK,MACb,CACD,EACI,EAAK,YACR,EAAe,KAAK,CACnB,IAAK,aACL,SAAU,IACV,MAAO,EAAQ,OAAO,GAAG,WAAW,UAAW,OAAO,CACvD,CAAC,EAGF,IAAM,EAAU,MAAM,EAAM,mBAAmB,CAC9C,UAAW,EAAQ,QAAQ,UAC3B,MAAO,EACP,WAAY,CACX,QAAS,GACT,aAAc,CACb,QAAS,EAAK,oCAAoC,EAClD,OAAQ,GACT,CACD,CACD,CAAC,EAGD,OAFI,EAAQ,MAAc,EAEnB,CACN,MAAO,IAAA,GACP,KAAMA,EAAe,aAAa,CACjC,KAAM,EAAQ,KACd,SAAU,EAAK,SACf,KAAM,EAAW,CAAO,EACxB,QAAS,EAAQ,OAAO,aAAa,QAAQ,IAAK,GAAW,EAAO,IAAI,EACxE,cAAe,EAAQ,OAAO,aAAa,cAC3C,QAAS,EAAQ,OAAO,OACzB,CAAC,CACF,CACD"}