Updated to nearly fully functional. Pre-release 1. Still needs some UI changes in the slideshow and admin pages (move the save button & fix the save detection for the internship list). Customer had one more page change request which I need to re-define and handle.
This commit is contained in:
74
imports/api/Internship.js
Normal file
74
imports/api/Internship.js
Normal file
@@ -0,0 +1,74 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
|
||||
let Internship = new Mongo.Collection('Internship');
|
||||
|
||||
Internship.attachSchema(new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
label: "Name",
|
||||
optional: false,
|
||||
trim: true,
|
||||
index: 1,
|
||||
unique: true
|
||||
},
|
||||
content: {
|
||||
type: String,
|
||||
label: "Content",
|
||||
optional: false,
|
||||
trim: false
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
label: "Created On",
|
||||
optional: true
|
||||
},
|
||||
updatedAt: {
|
||||
type: Date,
|
||||
label: "Updated On",
|
||||
optional: true
|
||||
}
|
||||
}));
|
||||
|
||||
if(Meteor.isServer) Meteor.publish('Internship', function() {
|
||||
return Internship.find({});
|
||||
});
|
||||
|
||||
if(Meteor.isServer) {
|
||||
Meteor.methods({
|
||||
addInternship: function(name, content) {
|
||||
check(name, String);
|
||||
check(content, String);
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
const createdAt = new Date();
|
||||
const updatedAt = createdAt;
|
||||
|
||||
//Returns the id of the object created.
|
||||
return Internship.insert({name, content, createdAt, updatedAt});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
removeInternship: function(_id) {
|
||||
check(_id, String);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Internship.remove(_id);
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
updateInternship: function(_id, content) {
|
||||
check(_id, String);
|
||||
check(content, String);
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
const updatedAt = new Date();
|
||||
|
||||
return Internship.update(_id, {$set: {content, updatedAt}});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default Internship;
|
||||
Reference in New Issue
Block a user