lmcq / firebase-firestorm

Firebase Firestorm is an ORM for Firestore which can be used with Typescript.
MIT License
252 stars 19 forks source link

TypeError: type is not a function #7

Closed michaelspeed closed 4 years ago

michaelspeed commented 4 years ago

i have these entity -

import {Entity, field, rootCollection} from "firebase-firestorm/lib";

@rootCollection({
    name: 'Discounts'
})
export default class Discounts extends Entity {

    @field({name: 'name'})
    name!: string;

    @field({name: 'price'})
    price!: number;

    @field({name: 'type'})
    type!: string
}
@rootCollection({
    name: 'members'
})
export default class Member extends Entity {

    @field({name: 'fname'})
    fname!: string;

    @field({name: 'lname'})
    lname!: string;

    @field({name: 'email'})
    email!: string;

    @field({name: 'phone'})
    phone!: string;

    @field({name: 'dob'})
    dob!: Date;

    @field({name: 'address'})
    address!: string;

    @documentRef({name: 'plan', entity: MemberShipPlans})
    plan!: IDocumentRef<MemberShipPlans>;

    @field({name: 'end'})
    end!: Date;
}
@rootCollection({
    name: 'Memberships'
})
export default class MemberShipPlans extends Entity {

    @field({name: 'name'})
    name!: string;

    @field({name: 'price'})
    price!: number;

    @field({name: 'tenure'})
    tenrure!: number;

    @documentRef({name: 'discount', entity: Discounts})
    discount!: IDocumentRef<Discounts>[]

}

i am querying a collections like this

Collection(Discounts).query().get().then(member => {
            console.log(member)
        })

and this comes up!

Screenshot at Nov 08 22-58-40

any ideas?

lmcq commented 4 years ago

Hi,

This is because the 'dob' and 'end' fields are Date's. Unfortunately, Date's are not currently supported if you're using the @field decorator. As they are supported in with the standard firestore sdk, they should also be supported in firestorm, so I'll find a fix.

Right now, you can use the @timestamp decorator, which will uses firestore's Timestamp class.

michaelspeed commented 4 years ago

thanks worked

davidassigbi commented 4 years ago

Hi i'm having this issue too but your solution didn't work for me... Here is my entity:

import { rootCollection, field, timestamp, Entity, ITimestamp } from 'firebase-firestorm/lib';

@rootCollection({
    name: 'users'
})
export default class User extends Entity {
    @timestamp({
        name: 'created_at',
        updateOnCreate: true
    })
    public createdAt!: ITimestamp;

    @timestamp({
        name: 'modified_at',
        updateOnUpdate: true
    })
    public modifiedAt!: ITimestamp;

    @field({ name: 'nom' })
    name!: string;

    @field({ name: 'prenom' })
    firstname!: string;

    @field({ name: 'email' })
    email!: string;

    @field({ name: 'username' })
    username!: string;
}

PB: I'm using firestorm 2.0.5

TetrisIQ commented 2 years ago

A bit late but had a similar Issue, a fix was to check the Compiler Options

{
  "compilerOptions": {
    "target": "ES5",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
  }
}