You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /** @module _modules/_baseRecord */
  2. /** @module _modules/allModules */
  3. /**
  4. * --- BASERECORD ---
  5. * Data common to every single data TYPE
  6. * Universal fields required for storing anything
  7. */
  8. class _baseRecord {
  9. /**
  10. * Standard record to extend with more detail
  11. */
  12. constructor() {
  13. this.createdAt = new Date().toJSON()
  14. this._id = Date.now().toString()
  15. this.lastUpdatedAt = null
  16. /** Set in subtype (ticket, user, etc) */
  17. this.type = null
  18. this._update()
  19. }
  20. /** Internally record update time */
  21. _update() {
  22. this.lastUpdatedAt = new Date().toJSON()
  23. }
  24. }
  25. /**
  26. * --- MODULES ---
  27. * Reusable bits to add to data TYPES
  28. * Make these as generic and reusable as possible!
  29. *
  30. * TODO: Destructure all these arguements
  31. */
  32. const allModules = {
  33. /**
  34. * Use parent() for anything that has a parent
  35. */
  36. parent: ({ id = '' }) => {
  37. const module = {
  38. parentId: id,
  39. }
  40. return module
  41. },
  42. /**
  43. * Use hourly() for anything that needs to track money * time
  44. */
  45. hourly: ({ hours, rate }) => {
  46. let module = {
  47. hours: hours,
  48. rate: rate,
  49. total: hours * rate,
  50. }
  51. return module
  52. },
  53. /**
  54. * Use id() for anything that needs to store contact information
  55. * (People, companies, etc)
  56. */
  57. contact: ({ name, email }) => {
  58. const module = {
  59. name: name,
  60. email: email,
  61. }
  62. // This is used for checking, maybe validation in the future(?)
  63. if (name) {
  64. module.name = name
  65. }
  66. if (email) {
  67. module.email = email
  68. }
  69. return module
  70. },
  71. /**
  72. * Use transaction() for anything that needs to track money
  73. * (Donations, fees, etc)
  74. */
  75. transaction: ({ amount, date }) => {
  76. let module = {
  77. amount: amount,
  78. date: date,
  79. }
  80. return module
  81. },
  82. /**
  83. * Use subjNote() for anything that needs just a title and short note
  84. * (Blog post, Quick notes, etc)
  85. */
  86. subjNote: ({ subject, note, status }) => {
  87. let module = {
  88. subject: subject,
  89. note: note,
  90. status: status,
  91. }
  92. if (!status) {
  93. module.status = 'draft'
  94. } else {
  95. module.status = status
  96. }
  97. return module
  98. },
  99. /**
  100. * Use location() for anything that needs to store location information
  101. * (People, companies, etc)
  102. */
  103. location: ({
  104. street = '',
  105. apt = '',
  106. city = '',
  107. state = '',
  108. zip = 11111,
  109. }) => {
  110. const module = {
  111. address: street,
  112. apt: apt,
  113. city: city,
  114. state: state,
  115. zip: zip,
  116. }
  117. return module
  118. },
  119. }
  120. export { _baseRecord, allModules }