Astronomy & Meteor 1.3 & React

Hi,

I’m currently trying to insert a record using astronomy into a collection. Any thoughts on what i should be importing. Here is my current import list on Methods.js

import {Meteor} from 'meteor/meteor';
import {Mongo} from 'meteor/mongo';
import {coupons, coupon} from '/lib/collection.jsx'

The method

'addCoupon': function(name, redeems, couponType, startDate) {
  var coupon = new coupon();
  coupon.set({
  name: name,
  code: name,
  redeemsAllowed: redeems,
  couponType: couponType,
  startDate: startDate,
  endDate: startDate
  });
  coupon.save(); // Document insertion.
}

and collection.jsx

import {Meteor} from 'meteor/meteor';
import {Accounts} from 'meteor/accounts-base';
import {Mongo} from 'meteor/mongo';
import {Astro} from 'meteor/jagi:astronomy';
import {Validators} from 'meteor/jagi:astronomy-validators';
import {relations} from 'meteor/jagi:astronomy-relations';
import {timestamp} from 'meteor/jagi:astronomy-timestamp-behavior';
export const coupons = new Mongo.Collection('coupons');

export const coupon = Astro.Class({
  name: 'Coupons',
  collection: coupons,
  fields: {
    'name': {
      type: 'string'
    },
    'code': {
      type: 'string'
    },
    'redeemsAllowed': {
      type: 'number'
    },
    'redeemsLeft': {
      type: 'number',
      optional: true,
      transient: true
    },
    'redeemers': {
      type: 'array',
      optional: true,
      nested: 'Redeemers',
      default: function() {
        return [];
      }
    },
    'couponType': {
      type: 'string'
      // CAN BE TYPE USER, COMPANY, GLOBAL
    },
    'restrictions': {
      type: 'array',
      optional: true
    },
    'startDate': {
      type: 'date'
    },
    'endDate': {
      type: 'date'
    }
  },
  'events': {
    beforeFind: function() {
      this.set('redeemsLeft', this.redeemsAllowed - this.redeemers.length);
    }
  }
})

Thank you in advance for any help that can be provided.

Solved the issue around this.

Might as well post your answer. Otherwise the endless sea of forum threads where the last post is “Nevermind fixed it” will claim you. :ship:

1 Like

fair enough

See here: https://github.com/ffxsam/ffx-meteor-react-boilerplate/blob/example/lib/methods.js

1 Like

One note about your code:

export const coupon = Astro.Class({
  name: 'Coupons',
  collection: coupons,

name is actually the name of the Astronomy class. In this case:

export const coupon = Astro.Class({
  name: 'coupon',
  collection: coupons,
1 Like

Thank You for fix note.