@@ -10,7 +10,7 @@ const client = new faunadb.Client({
10
10
secret : dbToken
11
11
} )
12
12
13
- export function addPost ( postData ) {
13
+ export function addPost ( postData , journalID ) {
14
14
15
15
const me = q . Select ( "ref" , q . Get (
16
16
q . Ref ( "classes/users/self" ) ) ) ;
@@ -19,8 +19,9 @@ export function addPost(postData) {
19
19
{
20
20
data : {
21
21
...postData ,
22
+ journal : q . Ref ( q . Collection ( 'journals' ) , journalID ) ,
22
23
owner : q . Select ( "ref" , q . Get ( q . Ref ( "classes/users/self" ) ) )
23
- } ,
24
+ } ,
24
25
permissions : {
25
26
read : me ,
26
27
write : me
@@ -30,20 +31,25 @@ export function addPost(postData) {
30
31
. catch ( error => error )
31
32
}
32
33
33
- export function getPosts ( ) {
34
-
35
- return client . query (
36
- q . Map (
37
- q . Paginate (
38
- q . Match ( // todo use lists_by_owner
39
- q . Ref ( "indexes/all_posts" ) ) ) , ( ref ) => q . Get ( ref ) ) )
40
- . then ( ( r ) => r . data ) ;
41
- }
42
-
43
- export function test ( ) {
44
- console . log (
45
- "test fdb " ,
46
- q . Select ( "ref" , q . Get ( q . Ref ( "classes/users/self" ) ) )
47
- )
34
+ export function getPosts ( journalID ) {
35
+
36
+ // Get the Current Journal reference object
37
+ // TODO: Wonder if we could just store the current journal ID object into a vuex,
38
+ // this could save an additonal request to get the journal ID
39
+
40
+ return client . query ( q . Get ( q . Ref ( `collections/journals/${ journalID } ` ) ) )
41
+ . then ( ( journal ) => {
42
+ console . log ( "Got Journal" , journal )
43
+
44
+ return client . query ( q . Map (
45
+ q . Paginate ( q . Match ( q . Index ( "posts_by_journal" ) , journal . ref ) ) ,
46
+ ( ref ) => q . Get ( ref ) // fauna lambda function , what does "Get()" do?
47
+ ) )
48
+ . then ( resp => {
49
+ console . log ( "got posts" , resp ) ;
50
+ return resp
51
+ } )
52
+ } )
53
+ . catch ( err => console . error ( "couldnt get posts" , err ) ) ;
48
54
}
49
55
0 commit comments