@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 3.56 kB
Source Map (JSON)
{"version":3,"file":"delete-profile-picture.mjs","names":["mediaServices.deleteSinglePermanently"],"sources":["../../../src/services/account/delete-profile-picture.ts"],"sourcesContent":["import { copy } from \"../../libs/i18n/index.js\";\nimport { UsersRepository } from \"../../libs/repositories/index.js\";\nimport type { ServiceFn } from \"../../utils/services/types.js\";\nimport { mediaServices } from \"../index.js\";\n\nconst deleteProfilePicture: ServiceFn<\n\t[\n\t\t{\n\t\t\ttargetUserId: number;\n\t\t\tactorUserId: number;\n\t\t\tallowSelf?: boolean;\n\t\t},\n\t],\n\tundefined\n> = async (context, data) => {\n\tconst Users = new UsersRepository(context.db.client, context.config.db);\n\n\tif (data.allowSelf !== true && data.actorUserId === data.targetUserId) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tmessage: copy(\"server:core.users.self.update.denied\"),\n\t\t\t\tstatus: 400,\n\t\t\t},\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\tconst userRes = await Users.selectSingle({\n\t\tselect: [\"profile_picture_media_id\"],\n\t\twhere: [\n\t\t\t{\n\t\t\t\tkey: \"id\",\n\t\t\t\toperator: \"=\",\n\t\t\t\tvalue: data.targetUserId,\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\", \"false\"),\n\t\t\t},\n\t\t],\n\t\tvalidation: {\n\t\t\tenabled: true,\n\t\t\tdefaultError: {\n\t\t\t\tmessage:\n\t\t\t\t\tdata.allowSelf === true\n\t\t\t\t\t\t? copy(\"server:core.account.not.found.message\")\n\t\t\t\t\t\t: 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\tif (userRes.data.profile_picture_media_id === null) {\n\t\treturn {\n\t\t\terror: undefined,\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\tconst updateUserRes = await Users.updateSingle({\n\t\tdata: {\n\t\t\tprofile_picture_media_id: null,\n\t\t\tupdated_at: new Date().toISOString(),\n\t\t},\n\t\twhere: [\n\t\t\t{\n\t\t\t\tkey: \"id\",\n\t\t\t\toperator: \"=\",\n\t\t\t\tvalue: data.targetUserId,\n\t\t\t},\n\t\t],\n\t\treturning: [\"id\"],\n\t\tvalidation: {\n\t\t\tenabled: true,\n\t\t},\n\t});\n\tif (updateUserRes.error) return updateUserRes;\n\n\tconst deleteMediaRes = await mediaServices.deleteSinglePermanently(context, {\n\t\tid: userRes.data.profile_picture_media_id,\n\t\tuserId: data.actorUserId,\n\t});\n\tif (deleteMediaRes.error) return deleteMediaRes;\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: undefined,\n\t};\n};\n\nexport default deleteProfilePicture;\n"],"mappings":"uJAKA,MAAM,EASF,MAAO,EAAS,IAAS,CAC5B,IAAM,EAAQ,IAAI,EAAgB,EAAQ,GAAG,OAAQ,EAAQ,OAAO,EAAE,EAEtE,GAAI,EAAK,YAAc,IAAQ,EAAK,cAAgB,EAAK,aACxD,MAAO,CACN,MAAO,CACN,KAAM,QACN,QAAS,EAAK,sCAAsC,EACpD,OAAQ,GACT,EACA,KAAM,IAAA,EACP,EAGD,IAAM,EAAU,MAAM,EAAM,aAAa,CACxC,OAAQ,CAAC,0BAA0B,EACnC,MAAO,CACN,CACC,IAAK,KACL,SAAU,IACV,MAAO,EAAK,YACb,EACA,CACC,IAAK,aACL,SAAU,IACV,MAAO,EAAQ,OAAO,GAAG,WAAW,UAAW,OAAO,CACvD,CACD,EACA,WAAY,CACX,QAAS,GACT,aAAc,CACb,QACC,EAAK,YAAc,GAChB,EAAK,uCAAuC,EAC5C,EAAK,oCAAoC,EAC7C,OAAQ,GACT,CACD,CACD,CAAC,EACD,GAAI,EAAQ,MAAO,OAAO,EAE1B,GAAI,EAAQ,K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