Vulcan/packages/vulcan-payments/lib/modules/charges/schema.js

152 lines
2.8 KiB
JavaScript
Raw Normal View History

import moment from 'moment';
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,
viewableBy: ['admins'],
2017-05-31 10:25:13 +09:00
onInsert: (document, currentUser) => {
return new Date();
},
2017-05-31 10:25:13 +09:00
},
userId: {
type: String,
optional: true,
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
associatedCollection: {
type: String,
viewableBy: ['admins'],
optional: true,
},
associatedId: {
type: String,
viewableBy: ['admins'],
optional: true,
},
2017-05-31 10:25:13 +09:00
tokenId: {
type: String,
optional: false,
},
productKey: {
type: String,
viewableBy: ['admins'],
2017-05-31 10:25:13 +09:00
optional: true,
},
source: {
2017-05-31 10:25:13 +09:00
type: String,
viewableBy: ['admins'],
2017-05-31 10:25:13 +09:00
optional: false,
},
test: {
type: Boolean,
viewableBy: ['admins'],
2017-05-31 10:25:13 +09:00
optional: true,
},
data: {
type: Object,
viewableBy: ['admins'],
2017-05-31 10:25:13 +09:00
blackbox: true,
},
properties: {
type: Object,
viewableBy: ['admins'],
2017-05-31 10:25:13 +09:00
blackbox: true,
},
ip: {
type: String,
viewableBy: ['admins'],
2017-05-31 10:25:13 +09:00
optional: true,
},
// GraphQL only
createdAtFormatted: {
type: String,
optional: true,
viewableBy: ['admins'],
resolveAs: {
type: 'String',
resolver: (charge, args, context) => {
return moment(charge.createdAt).format('dddd, MMMM Do YYYY');
}
}
},
createdAtFormattedShort: {
type: String,
optional: true,
viewableBy: ['admins'],
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');
}
}
},
stripeChargeUrl: {
type: String,
optional: true,
viewableBy: ['admins'],
resolveAs: {
type: 'String',
resolver: (charge, args, context) => {
return `https://dashboard.stripe.com/payments/${charge.data.id}`;
}
}
},
// 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;