index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const faker = require('faker')
  2. let productId = 1
  3. class FakeProdcut {
  4. constructor () {
  5. this.id = productId++
  6. let fc = faker.commerce
  7. this.name = fc.productName()
  8. this.color = fc.color()
  9. this.department = fc.department()
  10. this.price = fc.price()
  11. this.adjective = fc.productAdjective()
  12. this.material = fc.productMaterial()
  13. this.product = fc.product()
  14. }
  15. serialize () {
  16. return {
  17. id: this.id,
  18. name: this.name,
  19. color: this.color,
  20. department: this.department,
  21. price: this.price,
  22. adjective: this.adjective,
  23. material: this.material,
  24. product: this.product
  25. }
  26. }
  27. }
  28. module.exports = function () {
  29. var data = { products: [] }
  30. // Create 1000 Product
  31. data.products = generateFakeObject(FakeProdcut, 100)
  32. return data
  33. }
  34. function generateFakeObject (TARGETCLASS = '', count = 10) {
  35. if (typeof TARGETCLASS !== 'function') {
  36. console.error('클래스가 아님')
  37. return []
  38. }
  39. let result = []
  40. for (var i = 0; i < count; i++) {
  41. const fp = new TARGETCLASS()
  42. result.push(fp.serialize())
  43. }
  44. return result
  45. }