2021-03-07 23:53:54 +03:00
|
|
|
import * as Serializers from "~/node_common/serializers";
|
|
|
|
|
2020-07-25 03:16:35 +03:00
|
|
|
import { runQuery } from "~/node_common/data/utilities";
|
|
|
|
|
2021-03-07 23:53:54 +03:00
|
|
|
//NOTE(martina): if updating privacy, use the separate update-slate-privacy function which will remove it from activity as well
|
|
|
|
|
|
|
|
//NOTE(martina): you can pass in an update object whose data component is incomplete (e.g. data: { name: "New name" }) without accidentally
|
|
|
|
//wiping the rest of data b/c this updater method overlays it over the current value for data
|
|
|
|
|
2021-11-16 01:11:22 +03:00
|
|
|
export default async ({ objects, ...slate }) => {
|
2020-07-25 03:16:35 +03:00
|
|
|
return await runQuery({
|
|
|
|
label: "UPDATE_SLATE_BY_ID",
|
|
|
|
queryFn: async (DB) => {
|
2021-09-03 22:08:02 +03:00
|
|
|
const response = await DB.from("slates").where("id", slate.id).update(slate).returning("*");
|
2020-07-25 03:16:35 +03:00
|
|
|
|
|
|
|
const index = response ? response.pop() : null;
|
2021-03-07 23:53:54 +03:00
|
|
|
return JSON.parse(JSON.stringify(index));
|
2020-07-25 03:16:35 +03:00
|
|
|
},
|
|
|
|
errorFn: async (e) => {
|
|
|
|
return {
|
2020-09-13 01:08:36 +03:00
|
|
|
error: true,
|
|
|
|
decorator: "UPDATE_SLATE_BY_ID",
|
2020-07-25 03:16:35 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|