Vulcan/packages/example-simple/lib/modules/movies/schema.js

76 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-07-26 07:35:38 +09:00
/*
modules/movies/schema.js - #tutorial-step-10 -
This is a JS object that defines every property of a collection document...
2017-07-26 07:35:38 +09:00
A SimpleSchema-compatible JSON schema
*/
const schema = {
// default properties
_id: {
type: String,
optional: true,
viewableBy: ["guests"]
2017-07-26 07:35:38 +09:00
},
createdAt: {
type: Date,
optional: true,
viewableBy: ["guests"],
2017-07-26 07:35:38 +09:00
onInsert: (document, currentUser) => {
return new Date();
}
},
userId: {
type: String,
optional: true,
viewableBy: ["guests"],
2017-07-26 07:35:38 +09:00
resolveAs: {
fieldName: "user",
type: "User",
2017-07-26 07:35:38 +09:00
resolver: (movie, args, context) => {
return context.Users.findOne(
{ _id: movie.userId },
{ fields: context.Users.getViewableFields(context.currentUser, context.Users) }
);
2017-07-26 07:35:38 +09:00
},
addOriginalField: true
}
},
2017-07-26 07:35:38 +09:00
// custom properties
name: {
label: "Name",
2017-07-26 07:35:38 +09:00
type: String,
optional: true,
// ...these next three are interesting—they take a user group that says which group can do what action.
// ...guests are anonymous users...
viewableBy: ["guests"],
/// ...members can only edit documents that they own. This is part of the default mutations. Back to modules/movies/collection.js...
insertableBy: ["members"],
editableBy: ["members"]
2017-07-26 07:35:38 +09:00
},
year: {
label: "Year",
2017-07-26 07:35:38 +09:00
type: String,
optional: true,
viewableBy: ["guests"],
insertableBy: ["members"],
editableBy: ["members"]
2017-07-26 07:35:38 +09:00
},
review: {
label: "Review",
2017-07-26 07:35:38 +09:00
type: String,
optional: true,
control: "textarea",
viewableBy: ["guests"],
insertableBy: ["members"],
editableBy: ["members"]
}
2017-07-26 07:35:38 +09:00
};
export default schema;