Source

api/opportunity/OpportunityTypeCollection.ts

  1. import _ from 'lodash';
  2. import BaseTypeCollection from '../base/BaseTypeCollection';
  3. import { TypeDefine, TypeUpdate } from '../../typings/radgrad';
  4. /**
  5. * OpportunityTypes help organize Opportunities into logically related groupings such as "Internships", "Clubs", etc.
  6. * @extends api/base.BaseTypeCollection
  7. * @memberOf api/opportunity
  8. */
  9. class OpportunityTypeCollection extends BaseTypeCollection {
  10. /**
  11. * Creates the OpportunityType collection.
  12. */
  13. constructor() {
  14. super('OpportunityType');
  15. }
  16. /**
  17. * Defines a new OpportunityType with its name, slug, and description.
  18. * @example
  19. * OpportunityTypes.define({ name: 'Research', slug: 'research', description: 'A research project.' });
  20. * @param { Object } description Object with keys name, slug, and description.
  21. * Slug must be globally unique and previously undefined.
  22. * @throws { Meteor.Error } If the slug already exists.
  23. * @returns The newly created docID.
  24. */
  25. public define({ name, slug, description, retired = false }: TypeDefine) {
  26. return super.define({ name, slug, description, retired });
  27. }
  28. /**
  29. * Update an OpportunityType.
  30. * @param docID the docID to be updated.
  31. * @param name the new name (optional).
  32. * @param description the new description (optional).
  33. * @throws { Meteor.Error } If docID is not defined.
  34. */
  35. public update(docID, { name, description, retired }: TypeUpdate) {
  36. this.assertDefined(docID);
  37. const updateData: TypeUpdate = {};
  38. if (!_.isNil(name)) {
  39. updateData.name = name;
  40. }
  41. if (!_.isNil(description)) {
  42. updateData.description = description;
  43. }
  44. if (_.isBoolean(retired)) {
  45. updateData.retired = retired;
  46. }
  47. this.collection.update(docID, { $set: updateData });
  48. }
  49. }
  50. /**
  51. * Provides the singleton instance of this class to all other entities.
  52. * @type {api/opportunity.OpportunityTypeCollection}
  53. * @memberOf api/opportunity
  54. */
  55. export const OpportunityTypes = new OpportunityTypeCollection();