@@ -10,7 +10,7 @@ const client = new faunadb.Client({
1010 secret : dbToken
1111} )
1212
13- export function addPost ( postData ) {
13+ export function addPost ( postData , journalID ) {
1414
1515 const me = q . Select ( "ref" , q . Get (
1616 q . Ref ( "classes/users/self" ) ) ) ;
@@ -19,8 +19,9 @@ export function addPost(postData) {
1919 {
2020 data : {
2121 ...postData ,
22+ journal : q . Ref ( q . Collection ( 'journals' ) , journalID ) ,
2223 owner : q . Select ( "ref" , q . Get ( q . Ref ( "classes/users/self" ) ) )
23- } ,
24+ } ,
2425 permissions : {
2526 read : me ,
2627 write : me
@@ -30,20 +31,25 @@ export function addPost(postData) {
3031 . catch ( error => error )
3132}
3233
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 ) ) ;
4854}
4955
0 commit comments