From 36ebf5a8231612c97ac84935b6c004e15f01c94d Mon Sep 17 00:00:00 2001 From: jimmylee Date: Mon, 16 Nov 2020 23:59:11 -0800 Subject: [PATCH] create-orphan --- node_common/data/methods/create-orphan.js | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 node_common/data/methods/create-orphan.js 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", + }; + }, + }); +};