Source

api/interest/InterestTypeCollection.ts

  1. import _ from 'lodash';
  2. import BaseTypeCollection from '../base/BaseTypeCollection';
  3. import { TypeDefine, TypeUpdate } from '../../typings/radgrad';
  4. /**
  5. * InterestTypes help organize Interests into logically related groupings such as "CS-Disciplines", "Locations", etc.
  6. * @extends api/base.BaseTypeCollection
  7. * @memberOf api/interest
  8. */
  9. class InterestTypeCollection extends BaseTypeCollection {
  10. /**
  11. * Creates the InterestType collection.
  12. */
  13. constructor() {
  14. super('InterestType');
  15. }
  16. /**
  17. * Defines a new InterestType with its name, slug, and description.
  18. * @example
  19. * InterestTypes.define({ name: 'Locations', slug: 'locations', description: 'Regions of interest.' });
  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 InterestType.
  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. return true;
  49. }
  50. }
  51. /**
  52. * Provides the singleton instance of this class to all other entities.
  53. * @type {api/interest.InterestTypeCollection}
  54. * @memberOf api/interest
  55. */
  56. export const InterestTypes = new InterestTypeCollection();