@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 2.57 kB
Source Map (JSON)
{"version":3,"file":"get-single.mjs","names":["localesFormatter"],"sources":["../../../src/services/locales/get-single.ts"],"sourcesContent":["import { localesFormatter } from \"../../libs/formatters/index.js\";\nimport { copy } from \"../../libs/i18n/index.js\";\nimport { LocalesRepository } from \"../../libs/repositories/index.js\";\nimport type { Locale } from \"../../types/response.js\";\nimport type { ServiceFn } from \"../../utils/services/types.js\";\n\nconst getSingle: ServiceFn<\n\t[\n\t\t{\n\t\t\tcode: string;\n\t\t},\n\t],\n\tLocale\n> = async (context, data) => {\n\tconst Locales = new LocalesRepository(context.db.client, context.config.db);\n\n\tconst configLocale = context.config.localization.locales.find(\n\t\t(locale) => locale.code === data.code,\n\t);\n\n\tif (!configLocale) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tmessage: copy(\"server:core.locale.not.found.message\"),\n\t\t\t\tstatus: 404,\n\t\t\t},\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\tconst localeRes = await Locales.selectSingle({\n\t\tselect: [\"code\", \"created_at\", \"updated_at\", \"is_deleted\", \"is_deleted_at\"],\n\t\twhere: [\n\t\t\t{\n\t\t\t\tkey: \"code\",\n\t\t\t\toperator: \"=\",\n\t\t\t\tvalue: data.code,\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"is_deleted\",\n\t\t\t\toperator: \"!=\",\n\t\t\t\tvalue: context.config.db.getDefault(\"boolean\", \"true\"),\n\t\t\t},\n\t\t],\n\t\tvalidation: {\n\t\t\tenabled: true,\n\t\t\tdefaultError: {\n\t\t\t\tmessage: copy(\"server:core.locale.not.found.message\"),\n\t\t\t\tstatus: 404,\n\t\t\t},\n\t\t},\n\t});\n\tif (localeRes.error) return localeRes;\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: localesFormatter.formatSingle({\n\t\t\tlocale: localeRes.data,\n\t\t\tconfigLocale: configLocale,\n\t\t\tdefaultLocale: context.config.localization.defaultLocale,\n\t\t}),\n\t};\n};\n\nexport default getSingle;\n"],"mappings":"oJAMA,MAAM,EAOF,MAAO,EAAS,IAAS,CAC5B,IAAM,EAAU,IAAI,EAAkB,EAAQ,GAAG,OAAQ,EAAQ,OAAO,EAAE,EAEpE,EAAe,EAAQ,OAAO,aAAa,QAAQ,KACvD,GAAW,EAAO,OAAS,EAAK,IAClC,EAEA,GAAI,CAAC,EACJ,MAAO,CACN,MAAO,CACN,KAAM,QACN,QAAS,EAAK,sCAAsC,EACpD,OAAQ,GACT,EACA,KAAM,IAAA,EACP,EAGD,IAAM,EAAY,MAAM,EAAQ,aAAa,CAC5C,OAAQ,CAAC,OAAQ,aAAc,aAAc,aAAc,eAAe,EAC1E,MAAO,CACN,CACC,IAAK,OACL,SAAU,IACV,MAAO,EAAK,IACb,EACA,CACC,IAAK,aACL,SAAU,KACV,MAAO,EAAQ,OAAO,GAAG,WAAW,UAAW,MAAM,CACtD,CACD,EACA,WAAY,CACX,QAAS,GACT,aAAc,CACb,QAAS,EAAK,sCAAsC,EACpD,OAAQ,GACT,CACD,CACD,CAAC,EAGD,OAFI,EAAU,MAAc,EAErB,CACN,MAAO,IAAA,GACP,KAAMA,EAAiB,aAAa,CACnC,OAAQ,EAAU,KACJ,eACd,cAAe,EAAQ,OAAO,aAAa,aAC5C,CAAC,CACF,CACD"}