Guest User

Untitled

a guest
Mar 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. const mongoose = require("mongoose");
  2. const Schema = mongoose.Schema;
  3.  
  4. mongoose.Promise = global.Promise;
  5.  
  6. const GAPFApplicationSchema = new Schema({
  7. facultyId: { type: Number, index: true },
  8. created: Number, // use UNIX time stamps for all dates
  9. lastModified: Number,
  10. status: { type: String, enum: ["SUBMITTED", "BUDGET_ALLOCATED"] },
  11. attachedDocuments: [
  12. {
  13. name: String,
  14. link: String,
  15. attachedDate: Number
  16. }
  17. ]
  18. });
  19.  
  20. GAPFApplicationSchema.static("findByFacultyId", function(facultyId, callback) {
  21. return this.findOne()
  22. .where("facultyId")
  23. .equals(facultyId);
  24. });
  25.  
  26. GAPFApplicationSchema.static("submit", function(gapf, callback) {
  27. return this.findOneAndUpdate(
  28. { facultyId: gapf.facultyId },
  29. gapf,
  30. { upsert: true }, // create it if doesn't exist
  31. callback
  32. );
  33. });
  34.  
  35. const GAPFApplication = mongoose.model(
  36. "GAPFApplication",
  37. GAPFApplicationSchema
  38. );
  39.  
  40. export { GAPFApplication };
Add Comment
Please, Sign In to add comment