diff --git a/node_common/data/methods/create-orphan.js b/node_common/data/methods/create-orphan.js new file mode 100644 index 00000000..7df69c47 --- /dev/null +++ b/node_common/data/methods/create-orphan.js @@ -0,0 +1,24 @@ +import { runQuery } from "~/node_common/data/utilities"; + +export default async ({ data }) => { + return await runQuery({ + label: "CREATE_ORPHAN", + queryFn: async (DB) => { + const query = await DB.insert({ + created_at: new Date(), + data, + }) + .into("orphans") + .returning("*"); + + const index = query ? query.pop() : null; + return JSON.parse(JSON.stringify(index)); + }, + errorFn: async (e) => { + return { + error: true, + decorator: "CREATE_ORPHAN", + }; + }, + }); +};