{"version":3,"file":"knows-pPcvxINX.js","sources":["../../../../../src/services/knows.ts"],"sourcesContent":["\"use server\";\n\nimport { timestampRecord, currentUserId } from \"./server\";\nimport { meiliServerKnows } from \"~/lib/server\";\nimport { db } from \"~/database\";\nimport { withAuthor } from \"~/repos/know\";\nimport { authorSim } from \"~/repos/account\";\nimport { KnowUpdate, NewKnow } from \"~/types/models\";\nimport * as repo from \"~/repos/know\";\n\nexport const create = async (val: NewKnow) => {\n const authorId = await currentUserId();\n if (!authorId) throw \"user not logged in\";\n\n const data = await db\n .insertInto(\"knows\")\n .values({ ...val, authorId })\n .returningAll()\n .returning((eb) => [withAuthor(eb)])\n .executeTakeFirstOrThrow();\n const doc = timestampRecord(data);\n\n await meiliServerKnows.addDocuments([doc]);\n return data;\n};\n\nexport const update = async (id: string, val: KnowUpdate) => {\n const data = await repo.update(id, val);\n if (!data) throw \"know not found\";\n\n const authorId = data.authorId;\n if (!authorId) throw \"user not logged in\";\n const author = await authorSim(authorId);\n\n const know = {\n ...timestampRecord(data),\n author,\n };\n\n await meiliServerKnows.updateDocuments([know]);\n return data;\n};\n\n// const implies = await knex(\"implies\")\n// .where(\"knowId\", id)\n// .joinRaw(\n// \"left join knows propositions on propositions.id = any(implies.proposition_ids)\"\n// )\n// // https://github.com/knex/knex/issues/882#issuecomment-1351747332\n// .select([\n// \"implies.*\",\n// knex.raw(\"array_agg(to_json(propositions.*)) as propositions\"),\n// ])\n// .orderBy(\"implies.createdAt\", \"desc\")\n// .groupBy([\"implies.id\"]);\nexport const query = async (id: string) => {\n return await repo.find(id);\n};\n"],"names":["create","createServerReference","update","query"],"mappings":"+pBACAA,MAAAA,EAAAC,EAAA,IAAA,CAAA,EAAA,SAAA,QAAA,EACaC,EAASD,EAAsB,IAAM,CAAC,EAAG,SAAI,QAAA,EAC7CE,EAAQF,EAAsB,IAAK,CAAA,EAAA,SAAA,OAAA"}