2017-10-18 20:05:51 +09:00
|
|
|
import moment from 'moment';
|
2018-02-24 18:15:42 +09:00
|
|
|
import { getCollection } from 'meteor/vulcan:core';
|
2017-05-31 10:25:13 +09:00
|
|
|
|
|
|
|
const schema = {
|
|
|
|
|
|
|
|
// default properties
|
|
|
|
|
|
|
|
_id: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
viewableBy: ['guests'],
|
|
|
|
},
|
|
|
|
createdAt: {
|
|
|
|
type: Date,
|
|
|
|
optional: true,
|
2018-02-24 18:15:42 +09:00
|
|
|
viewableBy: ['admins'],
|
2017-05-31 10:25:13 +09:00
|
|
|
onInsert: (document, currentUser) => {
|
|
|
|
return new Date();
|
2018-02-03 13:17:04 -06:00
|
|
|
},
|
2017-05-31 10:25:13 +09:00
|
|
|
},
|
|
|
|
userId: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2018-02-24 18:15:42 +09:00
|
|
|
viewableBy: ['admins'],
|
|
|
|
resolveAs: {
|
|
|
|
fieldName: 'user',
|
|
|
|
type: 'User',
|
|
|
|
resolver: async (post, args, { currentUser, Users }) => {
|
|
|
|
const user = await Users.loader.load(post.userId);
|
|
|
|
return Users.restrictViewableFields(currentUser, Users, user);
|
|
|
|
},
|
|
|
|
addOriginalField: true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
type: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
viewableBy: ['admins'],
|
2017-05-31 10:25:13 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
// custom properties
|
|
|
|
|
2017-10-18 20:05:51 +09:00
|
|
|
associatedCollection: {
|
|
|
|
type: String,
|
2018-02-24 18:15:42 +09:00
|
|
|
viewableBy: ['admins'],
|
2017-10-18 20:05:51 +09:00
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
associatedId: {
|
|
|
|
type: String,
|
2018-02-24 18:15:42 +09:00
|
|
|
viewableBy: ['admins'],
|
2017-10-18 20:05:51 +09:00
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
|
2017-05-31 10:25:13 +09:00
|
|
|
tokenId: {
|
|
|
|
type: String,
|
|
|
|
optional: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
productKey: {
|
|
|
|
type: String,
|
2018-02-24 18:15:42 +09:00
|
|
|
viewableBy: ['admins'],
|
2017-05-31 10:25:13 +09:00
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
|
2018-02-24 18:15:42 +09:00
|
|
|
source: {
|
2017-05-31 10:25:13 +09:00
|
|
|
type: String,
|
2018-02-24 18:15:42 +09:00
|
|
|
viewableBy: ['admins'],
|
2017-05-31 10:25:13 +09:00
|
|
|
optional: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
test: {
|
|
|
|
type: Boolean,
|
2018-02-24 18:15:42 +09:00
|
|
|
viewableBy: ['admins'],
|
2017-05-31 10:25:13 +09:00
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
data: {
|
|
|
|
type: Object,
|
2018-02-24 18:15:42 +09:00
|
|
|
viewableBy: ['admins'],
|
2017-05-31 10:25:13 +09:00
|
|
|
blackbox: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
properties: {
|
|
|
|
type: Object,
|
2018-02-24 18:15:42 +09:00
|
|
|
viewableBy: ['admins'],
|
2017-05-31 10:25:13 +09:00
|
|
|
blackbox: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
ip: {
|
|
|
|
type: String,
|
2018-02-24 18:15:42 +09:00
|
|
|
viewableBy: ['admins'],
|
2017-05-31 10:25:13 +09:00
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
|
2017-10-18 20:05:51 +09:00
|
|
|
// GraphQL only
|
|
|
|
|
|
|
|
createdAtFormatted: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2018-02-24 18:15:42 +09:00
|
|
|
viewableBy: ['admins'],
|
2017-10-18 20:05:51 +09:00
|
|
|
resolveAs: {
|
|
|
|
type: 'String',
|
|
|
|
resolver: (charge, args, context) => {
|
|
|
|
return moment(charge.createdAt).format('dddd, MMMM Do YYYY');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-09 11:30:15 +09:00
|
|
|
createdAtFormattedShort: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2018-02-24 18:15:42 +09:00
|
|
|
viewableBy: ['admins'],
|
2018-02-09 11:30:15 +09:00
|
|
|
resolveAs: {
|
|
|
|
type: 'String',
|
|
|
|
resolver: (charge, args, context) => {
|
2018-02-14 22:21:56 +09:00
|
|
|
return moment(charge.createdAt).format('YYYY/MM/DD, hh:mm');
|
2018-02-09 11:30:15 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-18 20:05:51 +09:00
|
|
|
stripeChargeUrl: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
2018-02-24 18:15:42 +09:00
|
|
|
viewableBy: ['admins'],
|
2017-10-18 20:05:51 +09:00
|
|
|
resolveAs: {
|
|
|
|
type: 'String',
|
|
|
|
resolver: (charge, args, context) => {
|
|
|
|
return `https://dashboard.stripe.com/payments/${charge.data.id}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-24 18:15:42 +09:00
|
|
|
// doesn't work yet
|
|
|
|
|
|
|
|
// associatedDocument: {
|
|
|
|
// type: Object,
|
|
|
|
// viewableBy: ['admins'],
|
|
|
|
// optional: true,
|
|
|
|
// resolveAs: {
|
|
|
|
// type: 'Chargeable',
|
|
|
|
// resolver: (charge, args, context) => {
|
|
|
|
// const collection = getCollection(charge.associatedCollection);
|
|
|
|
// return collection.loader.load(charge.associatedId);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
|
2017-05-31 10:25:13 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
export default schema;
|