Data.js 793 B

12345678910111213141516171819202122232425262728
  1. 'use strict'
  2. import DataModel from '../models/Data'
  3. import { dbLogger } from '../../../config'
  4. import { formatLog } from '../../functions'
  5. export default class Data {
  6. static async add(dataObj) {
  7. const doc = await DataModel.create({ data: dataObj })
  8. dbLogger.info(formatLog(`New document was added. id=${doc.id}`))
  9. return doc
  10. }
  11. static async del(dataId) {
  12. const doc = await DataModel.findByIdAndDelete(dataId)
  13. dbLogger.info(formatLog(`A document was deleted. id=${doc.id}`))
  14. }
  15. static async update(dataId, newDataObj) {
  16. const doc = await DataModel.findByIdAndUpdate(dataId, newDataObj, { new: true })
  17. dbLogger.info(formatLog(`A document was updated. id=${doc.id}`))
  18. return doc
  19. }
  20. static find(dataId) {
  21. return DataModel.findById(dataId)
  22. }
  23. }