| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- /** @module _modules/_baseRecord */
- /** @module _modules/allModules */
-
- /**
- * --- BASERECORD ---
- * Data common to every single data TYPE
- * Universal fields required for storing anything
- */
- class _baseRecord {
- /**
- * Standard record to extend with more detail
- */
- constructor() {
- this.createdAt = new Date().toJSON()
- this._id = Date.now().toString()
- this.lastUpdatedAt = null
-
- /** Set in subtype (ticket, user, etc) */
- this.type = null
-
- this._update()
- }
- /** Internally record update time */
- _update() {
- this.lastUpdatedAt = new Date().toJSON()
- }
- }
-
- /**
- * --- MODULES ---
- * Reusable bits to add to data TYPES
- * Make these as generic and reusable as possible!
- *
- * TODO: Destructure all these arguements
- */
-
- const allModules = {
- /**
- * Use parent() for anything that has a parent
- */
- parent: ({ id = '' }) => {
- const module = {
- parentId: id,
- }
- return module
- },
-
- /**
- * Use hourly() for anything that needs to track money * time
- */
- hourly: ({ hours, rate }) => {
- let module = {
- hours: hours,
- rate: rate,
- total: hours * rate,
- }
- return module
- },
-
- /**
- * Use id() for anything that needs to store contact information
- * (People, companies, etc)
- */
- contact: ({ name, email }) => {
- const module = {
- name: name,
- email: email,
- }
-
- // This is used for checking, maybe validation in the future(?)
- if (name) {
- module.name = name
- }
- if (email) {
- module.email = email
- }
- return module
- },
-
- /**
- * Use transaction() for anything that needs to track money
- * (Donations, fees, etc)
- */
- transaction: ({ amount, date }) => {
- let module = {
- amount: amount,
- date: date,
- }
- return module
- },
-
- /**
- * Use subjNote() for anything that needs just a title and short note
- * (Blog post, Quick notes, etc)
- */
- subjNote: ({ subject, note, status }) => {
- let module = {
- subject: subject,
- note: note,
- status: status,
- }
-
- if (!status) {
- module.status = 'draft'
- } else {
- module.status = status
- }
- return module
- },
-
- /**
- * Use location() for anything that needs to store location information
- * (People, companies, etc)
- */
- location: ({
- street = '',
- apt = '',
- city = '',
- state = '',
- zip = 11111,
- }) => {
- const module = {
- address: street,
- apt: apt,
- city: city,
- state: state,
- zip: zip,
- }
-
- return module
- },
- }
-
- export { _baseRecord, allModules }
|