@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 2.36 kB
Source Map (JSON)
{"version":3,"file":"get-single.mjs","names":[],"sources":["../../../src/services/user-tokens/get-single.ts"],"sourcesContent":["import type { UserTokenType } from \"../../libs/db/types.js\";\nimport { copy } from \"../../libs/i18n/index.js\";\nimport { UserTokensRepository } from \"../../libs/repositories/index.js\";\nimport hashUserToken from \"../../utils/helpers/hash-user-token.js\";\nimport type { ServiceFn } from \"../../utils/services/types.js\";\n\nconst getSingle: ServiceFn<\n\t[\n\t\t{\n\t\t\ttokenType: UserTokenType;\n\t\t\ttoken: string;\n\t\t},\n\t],\n\t{\n\t\tid: number;\n\t\tuser_id: number | null;\n\t}\n> = async (context, data) => {\n\tconst UserTokens = new UserTokensRepository(\n\t\tcontext.db.client,\n\t\tcontext.config.db,\n\t);\n\tconst hashedToken = hashUserToken(data.token);\n\n\tconst userTokenRes = await UserTokens.selectSingle({\n\t\tselect: [\"id\", \"user_id\"],\n\t\twhere: [\n\t\t\t{\n\t\t\t\tkey: \"token\",\n\t\t\t\toperator: \"=\",\n\t\t\t\tvalue: hashedToken,\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"token_type\",\n\t\t\t\toperator: \"=\",\n\t\t\t\tvalue: data.tokenType,\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"expiry_date\",\n\t\t\t\toperator: \">\",\n\t\t\t\tvalue: new Date().toISOString(),\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"revoked_at\",\n\t\t\t\toperator: \"is\",\n\t\t\t\tvalue: null,\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"consumed_at\",\n\t\t\t\toperator: \"is\",\n\t\t\t\tvalue: null,\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.tokens.not.found.message\"),\n\t\t\t\tstatus: 404,\n\t\t\t},\n\t\t},\n\t});\n\tif (userTokenRes.error) return userTokenRes;\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: userTokenRes.data,\n\t};\n};\n\nexport default getSingle;\n"],"mappings":"8JAMA,MAAM,EAWF,MAAO,EAAS,IAAS,CAC5B,IAAM,EAAa,IAAI,EACtB,EAAQ,GAAG,OACX,EAAQ,OAAO,EAChB,EACM,EAAc,EAAc,EAAK,KAAK,EAEtC,EAAe,MAAM,EAAW,aAAa,CAClD,OAAQ,CAAC,KAAM,SAAS,EACxB,MAAO,CACN,CACC,IAAK,QACL,SAAU,IACV,MAAO,CACR,EACA,CACC,IAAK,aACL,SAAU,IACV,MAAO,EAAK,SACb,EACA,CACC,IAAK,cACL,SAAU,IACV,MAAO,IAAI,KAAK,CAAA,CAAE,YAAY,CAC/B,EACA,CACC,IAAK,aACL,SAAU,KACV,MAAO,IACR,EACA,CACC,IAAK,cACL,SAAU,KACV,MAAO,IACR,CACD,EACA,WAAY,CACX,QAAS,GACT,aAAc,CACb,QAAS,EAAK,sCAAsC,EACpD,OAAQ,GACT,CACD,CACD,CAAC,EAGD,OAFI,EAAa,MAAc,EAExB,CACN,MAAO,IAAA,GACP,KAAM,EAAa,IACpB,CACD"}