Skip to content

Problem implementing API #167

@eriknyk

Description

@eriknyk

If I have 2 models a.yaml and b,yaml

and if I execute:

fakeit.generate('glob/to/models/**/*.yaml')
  .then((data) => {
    console.log(data)
  })

data is an array like:

[ '[\n  {\n    "name": "Fahey, Botsford and Schaden",\n    "code": "4c49c6c0-8307-4eea-8e67-99b04930e1d2"\n  }\n]',
  '[\n  {\n    "name": "Oma",\n    "last_name": "Lebsack",\n    "username": "Saige.OConnell14",\n    "password": "ydKAoYYf8hfWLZJ",\n    "email": "Faye.McDermott@gmail.com",\n    "phone": "(925) 798-7312"\n  }\n]' ]

The question here is, how I can determine which array position is what to be used?

I mean my a.yaml file has defined

name: Users
type: object

and b.yaml

name: Companies
type: object

I need a way to get it something like this:

fakeit.generate('glob/to/models/**/*.yaml')
  .then((data) => {
    data.foreEach(item => {
        const modelName = item.name; // -> this should to have Users|Companies
        const records = JSON.parse(item.data); // -> this should contains the serialized data
            
        records.foreEach(record => {
             db.collection(modelName).insertOne(record) // on mongo db
        })
    })
  })

Note.- Syntax is only a example like: pseudo-code

Actually there is no way to archive this, because it returns an array of strings and there is no way to know what serialized result is for what source name,

Regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions