mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-25 09:15:19 +03:00
feat(node_common/data): add views methods
This commit is contained in:
parent
a66ddceeb4
commit
5c50b7652a
32
node_common/data/methods/create-view.js
Normal file
32
node_common/data/methods/create-view.js
Normal file
@ -0,0 +1,32 @@
|
||||
import { runQuery } from "~/node_common/data/utilities";
|
||||
|
||||
export default async ({ ownerId, name, filterBySource, filterBySlateId, metadata = {} }) => {
|
||||
return await runQuery({
|
||||
label: "CREATE_VIEW",
|
||||
queryFn: async (DB) => {
|
||||
let query = await DB.insert({
|
||||
ownerId,
|
||||
name,
|
||||
filterBySource,
|
||||
filterBySlateId,
|
||||
metadata: JSON.stringify(metadata),
|
||||
})
|
||||
.into("views")
|
||||
.returning("*");
|
||||
|
||||
if (!query) {
|
||||
return null;
|
||||
}
|
||||
|
||||
query = query.pop();
|
||||
|
||||
return JSON.parse(JSON.stringify(query));
|
||||
},
|
||||
errorFn: async () => {
|
||||
return {
|
||||
error: true,
|
||||
decorator: "CREATE_VIEW",
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
@ -16,6 +16,8 @@ export default async ({ id }) => {
|
||||
|
||||
const activity = await DB("activity").where({ slateId: id }).del();
|
||||
|
||||
const views = await DB("views").where({ filterBySlateId: id }).del();
|
||||
|
||||
const data = await DB("slates").where({ id }).del().returning("*");
|
||||
|
||||
let slate = data ? data.pop() : data;
|
||||
|
@ -39,6 +39,8 @@ export default async ({ id }) => {
|
||||
|
||||
const usage = await DB.from("usage").where({ userId: id }).del();
|
||||
|
||||
const views = await DB.from("views").where({ ownerId: id }).del();
|
||||
|
||||
const data = await DB.from("users").where({ id }).del().returning("*");
|
||||
|
||||
let user = data ? data.pop() : data;
|
||||
|
18
node_common/data/methods/delete-view-by-id.js
Normal file
18
node_common/data/methods/delete-view-by-id.js
Normal file
@ -0,0 +1,18 @@
|
||||
import { runQuery } from "~/node_common/data/utilities";
|
||||
|
||||
export default async ({ id }) => {
|
||||
return await runQuery({
|
||||
label: "DELETE_VIEW",
|
||||
queryFn: async (DB) => {
|
||||
const data = await DB.from("views").where({ id }).del().returning("*");
|
||||
|
||||
return data;
|
||||
},
|
||||
errorFn: async (e) => {
|
||||
return {
|
||||
error: true,
|
||||
decorator: "DELETE_VIEW",
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
22
node_common/data/methods/get-view-by-id.js
Normal file
22
node_common/data/methods/get-view-by-id.js
Normal file
@ -0,0 +1,22 @@
|
||||
import { runQuery } from "~/node_common/data/utilities";
|
||||
|
||||
export default async ({ id }) => {
|
||||
return await runQuery({
|
||||
label: "GET_VIEW_BY_ID",
|
||||
queryFn: async (DB) => {
|
||||
const query = await DB.select("*").from("views").where({ id }).first();
|
||||
|
||||
if (!query || query.error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return JSON.parse(JSON.stringify(query));
|
||||
},
|
||||
errorFn: async (e) => {
|
||||
return {
|
||||
error: true,
|
||||
decorator: "GET_VIEW_BY_ID",
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
25
node_common/data/methods/get-views-by-user-id.js
Normal file
25
node_common/data/methods/get-views-by-user-id.js
Normal file
@ -0,0 +1,25 @@
|
||||
import { runQuery } from "~/node_common/data/utilities";
|
||||
|
||||
export default async ({ ownerId }) => {
|
||||
return await runQuery({
|
||||
label: "GET_VIEWS_BY_USER_ID",
|
||||
queryFn: async (DB) => {
|
||||
const query = await DB.select("*")
|
||||
.from("views")
|
||||
.where({ ownerId })
|
||||
.orderBy("createdAt", "asc");
|
||||
|
||||
if (!query || query.error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return JSON.parse(JSON.stringify(query));
|
||||
},
|
||||
errorFn: async (e) => {
|
||||
return {
|
||||
error: true,
|
||||
decorator: "GET_VIEWS_BY_USER_ID",
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue
Block a user