1amageek / pring.ts

Cloud Firestore model framework for TypeScript - Google
https://firebase.google.com/docs/firestore/
MIT License
108 stars 7 forks source link

Support `FirebaseFirestore.DocumentReference` #19

Open starhoshi opened 6 years ago

starhoshi commented 6 years ago

An Error occurred when I tried to save DocumentReference on Cloud Functions.

Error

Error: Cannot encode type ([object Object]) to a Firestore Value

Error: Cannot encode type ([object Object]) to a Firestore Value
    at Function.encodeValue (/user_code/node_modules/pring/node_modules/@google-cloud/firestore/src/document.js:773:11)
    at Function.encodeFields (/user_code/node_modules/pring/node_modules/@google-cloud/firestore/src/document.js:644:36)
    at Function.fromObject (/user_code/node_modules/pring/node_modules/@google-cloud/firestore/src/document.js:202:55)
    at WriteBatch.set (/user_code/node_modules/pring/node_modules/@google-cloud/firestore/src/write-batch.js:272:39)
    at PringTest.Base.pack (/user_code/node_modules/pring/src/pring.js:225:27)
    at PringTest.<anonymous> (/user_code/node_modules/pring/src/pring.js:268:42)
    at step (/user_code/node_modules/pring/src/pring.js:32:23)
    at Object.next (/user_code/node_modules/pring/src/pring.js:13:53)
    at /user_code/node_modules/pring/src/pring.js:7:71
    at __awaiter (/user_code/node_modules/pring/src/pring.js:3:12)

Code

class PringTest extends Pring.Base {
  @property testRef: FirebaseFirestore.DocumentReference
}

export const createTestOrder = functions.firestore.document(`/version/1/testorder/{testOrderID}`).onCreate(async event => {
  const pringTest = new PringTest()
  pringTest.testRef = admin.firestore().doc('/version/1/sku/test')
  await pringTest.save() // error
})